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 5586bb64f2..1d8a28f4d2 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 @@ -318,10 +318,8 @@ spec: - --aws-use-static-instance-list={{ .AWSUseStaticInstanceList }} {{ end }} - --expander={{ .Expander }} - {{ range $name, $spec := GetNodeInstanceGroups }} - {{ if WithDefaultBool $spec.Autoscale true }} - - --nodes={{ $spec.MinSize }}:{{ $spec.MaxSize }}:{{ $name }}{{- if not (eq GetCloudProvider "gce") }}.{{ ClusterName }}{{ end -}} - {{ end }} + {{ range $nodeGroup := GetClusterAutoscalerNodeGroups }} + - --nodes={{ $nodeGroup.MinSize }}:{{ $nodeGroup.MaxSize }}:{{ $nodeGroup.Other }} {{ end }} - --scale-down-utilization-threshold={{ .ScaleDownUtilizationThreshold }} - --skip-nodes-with-local-storage={{ .SkipNodesWithLocalStorage }} @@ -335,9 +333,11 @@ spec: - --logtostderr=true - --stderrthreshold=info - --v=4 + {{ if (eq GetCloudProvider "aws") }} env: - name: AWS_REGION value: "{{ Region }}" + {{ end }} livenessProbe: failureThreshold: 3 httpGet: diff --git a/upup/pkg/fi/cloudup/template_functions.go b/upup/pkg/fi/cloudup/template_functions.go index 01142b8cae..70b328b2ae 100644 --- a/upup/pkg/fi/cloudup/template_functions.go +++ b/upup/pkg/fi/cloudup/template_functions.go @@ -113,6 +113,7 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS dest["GetCloudProvider"] = cluster.Spec.GetCloudProvider dest["GetInstanceGroup"] = tf.GetInstanceGroup dest["GetNodeInstanceGroups"] = tf.GetNodeInstanceGroups + dest["GetClusterAutoscalerNodeGroups"] = tf.GetClusterAutoscalerNodeGroups dest["HasHighlyAvailableControlPlane"] = tf.HasHighlyAvailableControlPlane dest["ControlPlaneControllerReplicas"] = tf.ControlPlaneControllerReplicas dest["APIServerNodeRole"] = tf.APIServerNodeRole @@ -824,6 +825,37 @@ func (tf *TemplateFunctions) GetNodeInstanceGroups() map[string]kops.InstanceGro return nodegroups } +type ClusterAutoscalerNodeGroup struct { + AutoScale *bool + MinSize int32 + MaxSize int32 + Other string +} + +// GetClusterAutoscalerGroups returns a map containing ClusterAutoscaler info for each instance group of type Node. +func (tf *TemplateFunctions) GetClusterAutoscalerNodeGroups() map[string]ClusterAutoscalerNodeGroup { + cluster := tf.Cluster + groups := make(map[string]ClusterAutoscalerNodeGroup) + for _, ig := range tf.KopsModelContext.InstanceGroups { + if ig.Spec.Role == kops.InstanceGroupRoleNode && (ig.Spec.Autoscale == nil || fi.ValueOf(ig.Spec.Autoscale)) { + group := ClusterAutoscalerNodeGroup{ + AutoScale: ig.Spec.Autoscale, + MinSize: fi.ValueOf(ig.Spec.MinSize), + MaxSize: fi.ValueOf(ig.Spec.MaxSize), + } + if cluster.Spec.GetCloudProvider() == kops.CloudProviderGCE { + cloud := tf.cloud.(gce.GCECloud) + format := "https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instanceGroups/%s" + group.Other = fmt.Sprintf(format, cloud.Project(), ig.Spec.Zones[0], gce.NameForInstanceGroupManager(cluster, ig, ig.Spec.Zones[0])) + } else { + group.Other = ig.Name + "." + cluster.Name + } + groups[ig.Name] = group + } + } + return groups +} + func (tf *TemplateFunctions) architectureOfAMI(amiID string) string { image, _ := tf.cloud.(awsup.AWSCloud).ResolveImage(amiID) switch *image.Architecture {