diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b26203dd..fb7d10a770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## 0.1.0 (upcoming) +## 0.17.0-0.1.0 (upcoming) -* Add clusterAPI capabilities for EKS \ No newline at end of file +* Add clusterAPI capabilities for EKS diff --git a/pkg/cluster/internal/create/actions/cluster/cluster.go b/pkg/cluster/internal/create/actions/cluster/cluster.go index 23025e2247..e5c80ad852 100644 --- a/pkg/cluster/internal/create/actions/cluster/cluster.go +++ b/pkg/cluster/internal/create/actions/cluster/cluster.go @@ -20,6 +20,7 @@ import ( "bytes" "embed" "os" + "strings" "text/template" "github.com/go-playground/validator/v10" @@ -111,8 +112,8 @@ type WorkerNodes []struct { SSHKey string `yaml:"ssh_key"` Spot bool `yaml:"spot" validate:"omitempty,boolean"` Labels map[string]string `yaml:"labels"` - NodeGroupMaxSize int `yaml:"max_size" validate:"required,numeric,gtefield=Quantity,gt=0"` - NodeGroupMinSize int `yaml:"min_size" validate:"required,numeric,ltefield=Quantity,gt=0"` + NodeGroupMaxSize int `yaml:"max_size" validate:"omitempty,numeric,required_with=NodeGroupMinSize,gtefield=Quantity,gt=0"` + NodeGroupMinSize int `yaml:"min_size" validate:"omitempty,numeric,required_with=NodeGroupMaxSize,ltefield=Quantity,gt=0"` RootVolume struct { Size int `yaml:"size" validate:"numeric"` Type string `yaml:"type"` @@ -216,34 +217,45 @@ func GetClusterDescriptor(descriptorPath string) (*DescriptorFile, error) { return &descriptorFile, nil } +func resto(n int, i int) int { + var r int + r = (n % 3) / (i + 1) + if r > 1 { + r = 1 + } + return r +} + func GetClusterManifest(flavor string, params TemplateParams) (string, error) { funcMap := template.FuncMap{ - "loop": func(az string, qa int, maxsize int, minsize int) <-chan Node { + "loop": func(az string, zd string, qa int, maxsize int, minsize int) <-chan Node { ch := make(chan Node) go func() { - var azs []string var q int var mx int var mn int if az != "" { - azs = []string{az} - q = qa - mx = maxsize - mn = minsize + ch <- Node{AZ: az, QA: qa, MaxSize: maxsize, MinSize: minsize} } else { - azs = []string{"a", "b", "c"} - q = qa / 3 - mx = maxsize / 3 - mn = minsize / 3 - } - for _, a := range azs { - ch <- Node{AZ: a, QA: q, MaxSize: mx, MinSize: mn} + for i, a := range []string{"a", "b", "c"} { + if zd == "unbalanced" { + q = qa/3 + resto(qa, i) + mx = maxsize/3 + resto(maxsize, i) + mn = minsize/3 + resto(minsize, i) + ch <- Node{AZ: a, QA: q, MaxSize: mx, MinSize: mn} + } else { + ch <- Node{AZ: a, QA: qa / 3, MaxSize: maxsize / 3, MinSize: minsize / 3} + } + } } close(ch) }() return ch }, + "hostname": func(s string) string { + return strings.Split(s, "/")[0] + }, } var tpl bytes.Buffer diff --git a/pkg/cluster/internal/create/actions/cluster/templates/aws.eks.tmpl b/pkg/cluster/internal/create/actions/cluster/templates/aws.eks.tmpl index 7be2ac8f34..688bbfdccd 100644 --- a/pkg/cluster/internal/create/actions/cluster/templates/aws.eks.tmpl +++ b/pkg/cluster/internal/create/actions/cluster/templates/aws.eks.tmpl @@ -65,12 +65,12 @@ spec: - name: ANNOTATE_POD_IP value: \"true\" {{- range $node := .Descriptor.WorkerNodes }} -{{- range $index, $n := loop .AZ .Quantity .NodeGroupMaxSize .NodeGroupMinSize }} +{{- range $index, $n := loop .AZ .ZoneDistribution .Quantity .NodeGroupMaxSize .NodeGroupMinSize }} --- apiVersion: cluster.x-k8s.io/v1beta1 kind: MachineDeployment metadata: -{{- if and $node.NodeGroupMaxSize $node.NodeGroupMinSize }} +{{- if and (gt $node.NodeGroupMaxSize 0) (gt $node.NodeGroupMinSize 0) }} annotations: cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: '{{ $n.MaxSize }}' cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: '{{ $n.MinSize }}' diff --git a/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl b/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl index da6c8aabac..dff13b5fa5 100644 --- a/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl +++ b/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl @@ -88,7 +88,8 @@ spec: [plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors] [plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"docker.io\"] endpoint = [\"https://registry-1.docker.io\"] - [plugins.\"io.containerd.grpc.v1.cri\".registry.configs.\"{{ .ExternalRegistry.Url }}\".auth] + {{- $url := hostname .ExternalRegistry.Url }} + [plugins.\"io.containerd.grpc.v1.cri\".registry.configs.\"{{ $url }}\".auth] password = \"{{ .ExternalRegistry.Pass }}\" username = \"{{ .ExternalRegistry.User }}\" path: /etc/containerd/config.toml @@ -121,18 +122,16 @@ spec: rootDeviceType: {{ .Descriptor.ControlPlane.RootVolume.Type }} {{- end }} {{- range $node := .Descriptor.WorkerNodes }} -{{- range $index, $n := loop .AZ .Quantity .NodeGroupMaxSize .NodeGroupMinSize }} +{{- range $index, $n := loop .AZ .ZoneDistribution .Quantity .NodeGroupMaxSize .NodeGroupMinSize }} --- apiVersion: cluster.x-k8s.io/v1beta1 kind: MachineDeployment metadata: +{{- if and (gt $node.NodeGroupMaxSize 0) (gt $node.NodeGroupMinSize 0) }} annotations: - {{- if $node.NodeGroupMaxSize }} cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: '{{ $n.MaxSize }}' - {{- end }} - {{- if $node.NodeGroupMinSize }} cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: '{{ $n.MinSize }}' - {{- end }} +{{- end }} name: "{{ $node.Name }}-md-{{ $index }}" namespace: "cluster-{{ $.Descriptor.ClusterID }}" spec: @@ -196,7 +195,8 @@ spec: [plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors] [plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"docker.io\"] endpoint = [\"https://registry-1.docker.io\"] - [plugins.\"io.containerd.grpc.v1.cri\".registry.configs.\"{{ $.ExternalRegistry.Url }}\".auth] + {{- $url := hostname $.ExternalRegistry.Url }} + [plugins.\"io.containerd.grpc.v1.cri\".registry.configs.\"{{ $url }}\".auth] password = \"{{ $.ExternalRegistry.Pass }}\" username = \"{{ $.ExternalRegistry.User }}\" path: /etc/containerd/config.toml