Skip to content

Commit

Permalink
Add support for custom cas image
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Sep 2, 2020
1 parent 8bda944 commit e00a2d4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
3 changes: 3 additions & 0 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/kops/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/kops/v1alpha2/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions pkg/model/components/clusterautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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")
}
Expand All @@ -48,5 +70,6 @@ func (b *ClusterAutoscalerOptionsBuilder) BuildOptions(o interface{}) error {
if cas.SkipNodesWithSystemPods == nil {
cas.SkipNodesWithSystemPods = fi.Bool(true)
}

return nil
}
2 changes: 1 addition & 1 deletion upup/models/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 0 additions & 21 deletions upup/pkg/fi/cloudup/template_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit e00a2d4

Please sign in to comment.