From ed0bc240ec1b1fd1a50f036fb1697244f93217bc Mon Sep 17 00:00:00 2001 From: Francisco Augusto Date: Wed, 8 Mar 2023 11:44:59 +0100 Subject: [PATCH 1/4] Fix autoscaler conditions --- pkg/cluster/internal/create/actions/cluster/cluster.go | 4 ++-- .../internal/create/actions/cluster/templates/aws.eks.tmpl | 2 +- .../internal/create/actions/cluster/templates/gcp.tmpl | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/cluster/internal/create/actions/cluster/cluster.go b/pkg/cluster/internal/create/actions/cluster/cluster.go index e4fcbd97ed..94b4b9c822 100644 --- a/pkg/cluster/internal/create/actions/cluster/cluster.go +++ b/pkg/cluster/internal/create/actions/cluster/cluster.go @@ -110,8 +110,8 @@ type WorkerNodes []struct { AZ string `yaml:"az"` SSHKey string `yaml:"ssh_key"` Spot bool `yaml:"spot" validate:"omitempty,boolean"` - 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"` 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 ea7022e60a..15bd398395 100644 --- a/pkg/cluster/internal/create/actions/cluster/templates/aws.eks.tmpl +++ b/pkg/cluster/internal/create/actions/cluster/templates/aws.eks.tmpl @@ -70,7 +70,7 @@ spec: 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 1cc1e3c6a0..70cfc031a8 100644 --- a/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl +++ b/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl @@ -126,13 +126,11 @@ spec: 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: From 893a14ef587cf6e3d2f344f18558498184f7e49b Mon Sep 17 00:00:00 2001 From: Francisco Augusto Date: Wed, 8 Mar 2023 12:16:25 +0100 Subject: [PATCH 2/4] Fix gcp registry url --- pkg/cluster/internal/create/actions/cluster/cluster.go | 4 ++++ .../internal/create/actions/cluster/templates/gcp.tmpl | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/cluster/internal/create/actions/cluster/cluster.go b/pkg/cluster/internal/create/actions/cluster/cluster.go index e4fcbd97ed..e2eaff595b 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" @@ -243,6 +244,9 @@ func GetClusterManifest(flavor string, params TemplateParams) (string, error) { }() 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/gcp.tmpl b/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl index 1cc1e3c6a0..c302f3bddf 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 @@ -196,7 +197,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 From c6ccc50368c5090213b4713336c8c170b8f39db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Alberto=20Novoa=20Rojas?= <112587171+iamjanr@users.noreply.github.com> Date: Wed, 8 Mar 2023 16:11:23 +0100 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 2c5c9e4b672228ab4e86551948719f4197140dbc Mon Sep 17 00:00:00 2001 From: Francisco Augusto Date: Mon, 13 Mar 2023 11:52:03 +0100 Subject: [PATCH 4/4] Add support for unbalanced zone_distribution --- .../create/actions/cluster/cluster.go | 34 ++++++++++++------- .../actions/cluster/templates/aws.eks.tmpl | 2 +- .../create/actions/cluster/templates/gcp.tmpl | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pkg/cluster/internal/create/actions/cluster/cluster.go b/pkg/cluster/internal/create/actions/cluster/cluster.go index cefe711a35..a4936b6fea 100644 --- a/pkg/cluster/internal/create/actions/cluster/cluster.go +++ b/pkg/cluster/internal/create/actions/cluster/cluster.go @@ -216,29 +216,37 @@ 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) }() 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 15bd398395..5014dfb56f 100644 --- a/pkg/cluster/internal/create/actions/cluster/templates/aws.eks.tmpl +++ b/pkg/cluster/internal/create/actions/cluster/templates/aws.eks.tmpl @@ -65,7 +65,7 @@ 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 diff --git a/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl b/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl index 84afe97681..29480e1e54 100644 --- a/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl +++ b/pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl @@ -122,7 +122,7 @@ 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