Skip to content

Commit 3422710

Browse files
expose DOKS custom cluster-autoscaler expanders (#1705)
1 parent cd9080b commit 3422710

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

args.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ const (
128128
ArgClusterAutoscalerScaleDownUtilizationThreshold = "scale-down-utilization-threshold"
129129
// ArgClusterAutoscalerScaleDownUnneededTime is the cluster autoscaler scale down unneeded time
130130
ArgClusterAutoscalerScaleDownUnneededTime = "scale-down-unneeded-time"
131+
// ArgClusterAutoscalerExpanders customizes the expanders used by the cluster autoscaler to scale up the cluster.
132+
ArgClusterAutoscalerExpanders = "expanders"
131133
// ArgEnableRoutingAgent enables the routing-agent cluster plugin.
132134
ArgEnableRoutingAgent = "enable-routing-agent"
133135
// ArgSurgeUpgrade is a cluster's surge-upgrade argument.

commands/displayers/kubernetes.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (clusters *KubernetesClusters) Cols() []string {
5050
"NodePools",
5151
"Autoscaler.UtilizationThreshold",
5252
"Autoscaler.UnneededTime",
53+
"Autoscaler.Expanders",
5354
"RoutingAgent",
5455
}
5556
}
@@ -84,6 +85,7 @@ func (clusters *KubernetesClusters) ColMap() map[string]string {
8485
"NodePools": "Node Pools",
8586
"Autoscaler.UtilizationThreshold": "Autoscaler Scale Down Utilization",
8687
"Autoscaler.UnneededTime": "Autoscaler Scale Down Unneeded Time",
88+
"Autoscaler.Expanders": "Autoscaler Custom Expanders",
8789
"RoutingAgent": "Routing Agent",
8890
}
8991
}
@@ -119,6 +121,7 @@ func (clusters *KubernetesClusters) KV() []map[string]any {
119121
"NodePools": strings.Join(nodePools, " "),
120122
"Autoscaler.UtilizationThreshold": "",
121123
"Autoscaler.UnneededTime": "",
124+
"Autoscaler.Expanders": "",
122125
"RoutingAgent": cluster.RoutingAgent != nil && *cluster.RoutingAgent.Enabled,
123126
}
124127

@@ -129,6 +132,9 @@ func (clusters *KubernetesClusters) KV() []map[string]any {
129132
if cluster.ClusterAutoscalerConfiguration.ScaleDownUnneededTime != nil {
130133
o["Autoscaler.UnneededTime"] = *cfg.ScaleDownUnneededTime
131134
}
135+
if cluster.ClusterAutoscalerConfiguration.Expanders != nil {
136+
o["Autoscaler.Expanders"] = strings.Join(cfg.Expanders, ", ")
137+
}
132138
}
133139

134140
out = append(out, o)

commands/kubernetes.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ After creating a cluster, a configuration context is added to kubectl and made a
295295
"The threshold value for the cluster autoscaler's scale-down-utilization-threshold. It is the maximum value between the sum of CPU requests and sum of memory requests of all pods running on the node divided by node's corresponding allocatable resource, below which a node can be considered for scale down. To set the scale-down-utilization-threshold to 50%, pass the floating point value 0.5.")
296296
AddStringFlag(cmdKubeClusterCreate, doctl.ArgClusterAutoscalerScaleDownUnneededTime, "", "",
297297
"The unneed time for the cluster autoscaler's scale-down-unneeded-time. It defines how long a node should be unneeded before it is eligible for scale down. To set the scale-down-unneeded-time to a minute and 30 seconds for example, pass the string '1m30s'.")
298+
AddStringSliceFlag(cmdKubeClusterCreate, doctl.ArgClusterAutoscalerExpanders, "", nil,
299+
"Customizes expanders used by cluster-autoscaler. The autoscaler will apply each expander from the provided comma-separated list to narrow down the selection of node types created to scale up, until either a single node type is left, or the list of expanders is exhausted. Available expanders: random, least-waste, priority. If this flag is empty, autoscaler will use its default expanders.")
298300
AddBoolFlag(cmdKubeClusterCreate, doctl.ArgEnableRoutingAgent, "", false,
299301
"Creates the cluster with routing-agent enabled. Defaults to false. To enable routing-agent, supply --enable-routing-agent=true.")
300302
AddStringSliceFlag(cmdKubeClusterCreate, doctl.ArgTag, "", nil,
@@ -351,6 +353,8 @@ Updates the configuration values for a Kubernetes cluster. The cluster must be r
351353
"The threshold value for the cluster autoscaler's scale-down-utilization-threshold. It is the maximum value between the sum of CPU requests and sum of memory requests of all pods running on the node divided by node's corresponding allocatable resource, below which a node can be considered for scale down. To set the scale-down-utilization-threshold to 50%, pass the floating point value 0.5.")
352354
AddStringFlag(cmdKubeClusterUpdate, doctl.ArgClusterAutoscalerScaleDownUnneededTime, "", "",
353355
"The unneed time for the cluster autoscaler's scale-down-unneeded-time. It defines how long a node should be unneeded before it is eligible for scale down. To set the scale-down-unneeded-time to a minute and 30 seconds for example, pass the string '1m30s'.")
356+
AddStringSliceFlag(cmdKubeClusterUpdate, doctl.ArgClusterAutoscalerExpanders, "", nil,
357+
"Customizes expanders used by cluster-autoscaler. The autoscaler will apply each expander from the provided comma-separated list to narrow down the selection of node types created to scale up, until either a single node type is left, or the list of expanders is exhausted. Available expanders: random, least-waste, priority. If this value is empty, autoscaler will use its default expanders. To unset expander customization, pass an empty string.")
354358
AddStringSliceFlag(cmdKubeClusterUpdate, doctl.ArgControlPlaneFirewallAllowedAddresses, "", nil,
355359
"A comma-separated list of allowed addresses that can access the control plane.")
356360
AddBoolFlag(cmdKubeClusterUpdate, doctl.ArgClusterUpdateKubeconfig, "",
@@ -1733,7 +1737,15 @@ func buildClusterCreateRequestFromArgs(c *CmdConfig, r *godo.KubernetesClusterCr
17331737
clusterAutoscalerConfiguration.ScaleDownUnneededTime = &unneededTime
17341738
}
17351739

1736-
if thresholdStr != "" || unneededTime != "" {
1740+
expanders, expandersAreSet, err := c.Doit.GetStringSliceIsFlagSet(c.NS, doctl.ArgClusterAutoscalerExpanders)
1741+
if err != nil {
1742+
return err
1743+
}
1744+
if expandersAreSet {
1745+
clusterAutoscalerConfiguration.Expanders = expanders
1746+
}
1747+
1748+
if thresholdStr != "" || unneededTime != "" || expandersAreSet {
17371749
r.ClusterAutoscalerConfiguration = clusterAutoscalerConfiguration
17381750
}
17391751

@@ -1882,7 +1894,15 @@ func buildClusterUpdateRequestFromArgs(c *CmdConfig, r *godo.KubernetesClusterUp
18821894
clusterAutoscalerConfiguration.ScaleDownUnneededTime = &unneededTime
18831895
}
18841896

1885-
if thresholdStr != "" || unneededTime != "" {
1897+
expanders, expandersAreSet, err := c.Doit.GetStringSliceIsFlagSet(c.NS, doctl.ArgClusterAutoscalerExpanders)
1898+
if err != nil {
1899+
return err
1900+
}
1901+
if expandersAreSet {
1902+
clusterAutoscalerConfiguration.Expanders = expanders
1903+
}
1904+
1905+
if thresholdStr != "" || unneededTime != "" || expandersAreSet {
18861906
r.ClusterAutoscalerConfiguration = clusterAutoscalerConfiguration
18871907
}
18881908

integration/kubernetes_clusters_get_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ var (
106106
},
107107
"cluster_autoscaler_configuration": {
108108
"scale_down_utilization_threshold": 0.5,
109-
"scale_down_unneeded_time": "1m30s"
109+
"scale_down_unneeded_time": "1m30s",
110+
"expanders": ["priority", "random"]
110111
},
111112
"created_at": "2018-11-15T16:00:11Z",
112113
"updated_at": "2018-11-15T16:00:11Z"
@@ -115,7 +116,8 @@ var (
115116
}
116117
`
117118

118-
k8sGetOutput = `ID Name Region Version Auto Upgrade HA Control Plane Status Endpoint IPv4 Cluster Subnet Service Subnet Tags Created At Updated At Node Pools Autoscaler Scale Down Utilization Autoscaler Scale Down Unneeded Time Routing Agent
119-
some-cluster-id some-cluster-id nyc3 some-kube-version true false running production 2018-11-15 16:00:11 +0000 UTC 2018-11-15 16:00:11 +0000 UTC frontend-pool 50% 1m30s false
119+
k8sGetOutput = `
120+
ID Name Region Version Auto Upgrade HA Control Plane Status Endpoint IPv4 Cluster Subnet Service Subnet Tags Created At Updated At Node Pools Autoscaler Scale Down Utilization Autoscaler Scale Down Unneeded Time Autoscaler Custom Expanders Routing Agent
121+
some-cluster-id some-cluster-id nyc3 some-kube-version true false running production 2018-11-15 16:00:11 +0000 UTC 2018-11-15 16:00:11 +0000 UTC frontend-pool 50% 1m30s priority, random false
120122
`
121123
)

integration/projects_resources_get_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ ID Name Size Region Filesyste
343343
}
344344
`
345345
projectsResourcesGetKubernetesOutput = `
346-
ID Name Region Version Auto Upgrade HA Control Plane Status Endpoint IPv4 Cluster Subnet Service Subnet Tags Created At Updated At Node Pools Autoscaler Scale Down Utilization Autoscaler Scale Down Unneeded Time Routing Agent
347-
1111 false false provisioning k8s 2021-01-29 16:02:02 +0000 UTC 0001-01-01 00:00:00 +0000 UTC pool-test false
346+
ID Name Region Version Auto Upgrade HA Control Plane Status Endpoint IPv4 Cluster Subnet Service Subnet Tags Created At Updated At Node Pools Autoscaler Scale Down Utilization Autoscaler Scale Down Unneeded Time Autoscaler Custom Expanders Routing Agent
347+
1111 false false provisioning k8s 2021-01-29 16:02:02 +0000 UTC 0001-01-01 00:00:00 +0000 UTC pool-test false
348348
`
349349

350350
projectsResourcesListKubernetesOutput = `

0 commit comments

Comments
 (0)