From ed0bc240ec1b1fd1a50f036fb1697244f93217bc Mon Sep 17 00:00:00 2001 From: Francisco Augusto Date: Wed, 8 Mar 2023 11:44:59 +0100 Subject: [PATCH] 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: