/
clusterautoscaler.go
94 lines (81 loc) · 2.68 KB
/
clusterautoscaler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
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"
)
// ClusterAutoscalerOptionsBuilder adds options for cluster autoscaler to the model
type ClusterAutoscalerOptionsBuilder struct {
*OptionsContext
}
var _ loader.OptionsBuilder = &ClusterAutoscalerOptionsBuilder{}
func (b *ClusterAutoscalerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
cas := clusterSpec.ClusterAutoscaler
if cas == nil || !fi.BoolValue(cas.Enabled) {
return nil
}
if cas.Image == nil {
image := "k8s.gcr.io/autoscaling/cluster-autoscaler:latest"
v, err := util.ParseKubernetesVersion(clusterSpec.KubernetesVersion)
if err == nil {
switch v.Minor {
case 22:
image = "k8s.gcr.io/autoscaling/cluster-autoscaler:v1.22.0"
case 21:
image = "k8s.gcr.io/autoscaling/cluster-autoscaler:v1.21.0"
case 20:
image = "k8s.gcr.io/autoscaling/cluster-autoscaler:v1.20.0"
case 19:
image = "k8s.gcr.io/autoscaling/cluster-autoscaler:v1.19.1"
case 18:
image = "k8s.gcr.io/autoscaling/cluster-autoscaler:v1.18.3"
case 17:
image = "k8s.gcr.io/autoscaling/cluster-autoscaler:v1.17.4"
case 16:
image = "k8s.gcr.io/autoscaling/cluster-autoscaler:v1.16.7"
case 15:
image = "k8s.gcr.io/autoscaling/cluster-autoscaler:v1.15.7"
}
}
cas.Image = fi.String(image)
}
if cas.Expander == nil {
cas.Expander = fi.String("random")
}
if cas.ScaleDownUtilizationThreshold == nil {
cas.ScaleDownUtilizationThreshold = fi.String("0.5")
}
if cas.SkipNodesWithLocalStorage == nil {
cas.SkipNodesWithLocalStorage = fi.Bool(true)
}
if cas.SkipNodesWithSystemPods == nil {
cas.SkipNodesWithSystemPods = fi.Bool(true)
}
if cas.BalanceSimilarNodeGroups == nil {
cas.BalanceSimilarNodeGroups = fi.Bool(false)
}
if cas.AWSUseStaticInstanceList == nil {
cas.AWSUseStaticInstanceList = fi.Bool(false)
}
if cas.NewPodScaleUpDelay == nil {
cas.NewPodScaleUpDelay = fi.String("0s")
}
if cas.ScaleDownDelayAfterAdd == nil {
cas.ScaleDownDelayAfterAdd = fi.String("10m0s")
}
return nil
}