diff --git a/k8s/crds/kops.k8s.io_clusters.yaml b/k8s/crds/kops.k8s.io_clusters.yaml index 8c0211036f025..f0be51f42c89a 100644 --- a/k8s/crds/kops.k8s.io_clusters.yaml +++ b/k8s/crds/kops.k8s.io_clusters.yaml @@ -347,6 +347,9 @@ spec: expander: description: 'Expander determines the strategy for which instance group gets expanded. Supported values: least-waste, most-pods, random. Default: least-waste' type: string + image: + description: 'Image is the docker container used. Default: the latest supported image for the specified kubernetes version.' + type: string scaleDownUtilizationThreshold: description: 'ScaleDownUtilizationThreshold determines the utilization threshold for node scale-down. Default: 0.5' type: string diff --git a/pkg/apis/kops/componentconfig.go b/pkg/apis/kops/componentconfig.go index 4e4792ee45cc1..2f00d5cbda082 100644 --- a/pkg/apis/kops/componentconfig.go +++ b/pkg/apis/kops/componentconfig.go @@ -780,6 +780,9 @@ type ClusterAutoscalerConfig struct { // SkipNodesWithLocalStorage makes cluster autoscaler skip scale-down of nodes with local storage. // Default: true SkipNodesWithLocalStorage *bool `json:"skipNodesWithLocalStorage,omitempty"` + // Image is the docker container used. + // Default: the latest supported image for the specified kubernetes version. + Image *string `json:"image,omitempty"` } // HasAdmissionController checks if a specific admission controller is enabled diff --git a/pkg/apis/kops/v1alpha2/componentconfig.go b/pkg/apis/kops/v1alpha2/componentconfig.go index b30421ff1473b..fd803fc3ecbb1 100644 --- a/pkg/apis/kops/v1alpha2/componentconfig.go +++ b/pkg/apis/kops/v1alpha2/componentconfig.go @@ -781,6 +781,9 @@ type ClusterAutoscalerConfig struct { // SkipNodesWithLocalStorage makes cluster autoscaler skip scale-down of nodes with local storage. // Default: true SkipNodesWithLocalStorage *bool `json:"skipNodesWithLocalStorage,omitempty"` + // Image is the docker container used. + // Default: the latest supported image for the specified kubernetes version. + Image *string `json:"image,omitempty"` } // HasAdmissionController checks if a specific admission controller is enabled diff --git a/pkg/model/components/clusterautoscaler.go b/pkg/model/components/clusterautoscaler.go index 12cebbcdcbae9..aac4b7d2e30ef 100644 --- a/pkg/model/components/clusterautoscaler.go +++ b/pkg/model/components/clusterautoscaler.go @@ -18,6 +18,7 @@ package components import ( "k8s.io/kops/pkg/apis/kops" + "k8s.io/kops/pkg/apis/kops/util" "k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi/loader" ) @@ -36,6 +37,27 @@ func (b *ClusterAutoscalerOptionsBuilder) BuildOptions(o interface{}) error { return nil } + if cas.Image == nil { + tag := "latest" + parsed, err := util.ParseKubernetesVersion(clusterSpec.KubernetesVersion) + if err == nil { + switch parsed.Minor { + case 19: + tag = "v1.19.0" + case 18: + tag = "v1.18.2" + case 17: + tag = "v1.17.3" + case 16: + tag = "v1.16.6" + case 15: + tag = "v1.15.7" + } + } + + cas.Image = fi.String("k8s.gcr.io/autoscaling/cluster-autoscaler:" + tag) + } + if cas.Expander == nil { cas.Expander = fi.String("random") } @@ -48,5 +70,6 @@ func (b *ClusterAutoscalerOptionsBuilder) BuildOptions(o interface{}) error { if cas.SkipNodesWithSystemPods == nil { cas.SkipNodesWithSystemPods = fi.Bool(true) } + return nil } diff --git a/upup/models/bindata.go b/upup/models/bindata.go index 0f8dfe167ee4b..16c0bca7b3f96 100644 --- a/upup/models/bindata.go +++ b/upup/models/bindata.go @@ -999,7 +999,7 @@ spec: nodeSelector: node-role.kubernetes.io/master: "" containers: - - image: k8s.gcr.io/autoscaling/cluster-autoscaler:{{ ClusterAutoscalerTag }} + - image: {{ .ClusterAutoscaler.Image }} name: cluster-autoscaler resources: limits: diff --git a/upup/models/cloudup/resources/addons/cluster-autoscaler.addons.k8s.io/k8s-1.15.yaml.template b/upup/models/cloudup/resources/addons/cluster-autoscaler.addons.k8s.io/k8s-1.15.yaml.template index ec9ae588a7870..0cd4c5ce8281b 100644 --- a/upup/models/cloudup/resources/addons/cluster-autoscaler.addons.k8s.io/k8s-1.15.yaml.template +++ b/upup/models/cloudup/resources/addons/cluster-autoscaler.addons.k8s.io/k8s-1.15.yaml.template @@ -141,7 +141,7 @@ spec: nodeSelector: node-role.kubernetes.io/master: "" containers: - - image: k8s.gcr.io/autoscaling/cluster-autoscaler:{{ ClusterAutoscalerTag }} + - image: {{ .ClusterAutoscaler.Image }} name: cluster-autoscaler resources: limits: diff --git a/upup/pkg/fi/cloudup/template_functions.go b/upup/pkg/fi/cloudup/template_functions.go index 4039c944f3028..2826318c82290 100644 --- a/upup/pkg/fi/cloudup/template_functions.go +++ b/upup/pkg/fi/cloudup/template_functions.go @@ -127,7 +127,6 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS // will return openstack external ccm image location for current kubernetes version dest["OpenStackCCMTag"] = tf.OpenStackCCMTag - dest["ClusterAutoscalerTag"] = tf.ClusterAutoscalerTag dest["ProxyEnv"] = tf.ProxyEnv dest["KopsSystemEnv"] = tf.KopsSystemEnv @@ -539,23 +538,3 @@ func (tf *TemplateFunctions) GetNodeInstanceGroups() map[string]kops.InstanceGro } return nodegroups } - -func (tf *TemplateFunctions) ClusterAutoscalerTag() (tag string) { - tag = "latest" - parsed, err := util.ParseKubernetesVersion(tf.Cluster.Spec.KubernetesVersion) - if err == nil { - switch parsed.Minor { - case 19: - tag = "v1.19.0" - case 18: - tag = "v1.18.2" - case 17: - tag = "v1.17.3" - case 16: - tag = "v1.16.6" - case 15: - tag = "v1.15.7" - } - } - return tag -}