Skip to content

Commit

Permalink
Merge pull request #10531 from favoretti/favoretti/aks_autoscaling
Browse files Browse the repository at this point in the history
azurerm_kubernetes_cluster: auto_scaler_profile additions
  • Loading branch information
tombuildsstuff authored Feb 15, 2021
2 parents eb08e92 + dc930c5 commit e5c6e26
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ func resourceKubernetesCluster() *schema.Resource {
Optional: true,
Computed: true,
},
"skip_nodes_with_local_storage": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"skip_nodes_with_system_pods": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -2035,6 +2045,16 @@ func flattenKubernetesClusterAutoScalerProfile(profile *containerservice.Managed
scanInterval = *profile.ScanInterval
}

skipNodesWithLocalStorage := true
if profile.SkipNodesWithLocalStorage != nil {
skipNodesWithLocalStorage = strings.EqualFold(*profile.SkipNodesWithLocalStorage, "true")
}

skipNodesWithSystemPods := true
if profile.SkipNodesWithSystemPods != nil {
skipNodesWithSystemPods = strings.EqualFold(*profile.SkipNodesWithSystemPods, "true")
}

return []interface{}{
map[string]interface{}{
"balance_similar_node_groups": balanceSimilarNodeGroups,
Expand All @@ -2047,6 +2067,8 @@ func flattenKubernetesClusterAutoScalerProfile(profile *containerservice.Managed
"scale_down_unready": scaleDownUnreadyTime,
"scale_down_utilization_threshold": scaleDownUtilizationThreshold,
"scan_interval": scanInterval,
"skip_nodes_with_local_storage": skipNodesWithLocalStorage,
"skip_nodes_with_system_pods": skipNodesWithSystemPods,
},
}
}
Expand All @@ -2068,6 +2090,8 @@ func expandKubernetesClusterAutoScalerProfile(input []interface{}) *containerser
scaleDownUnreadyTime := config["scale_down_unready"].(string)
scaleDownUtilizationThreshold := config["scale_down_utilization_threshold"].(string)
scanInterval := config["scan_interval"].(string)
skipNodesWithLocalStorage := config["skip_nodes_with_local_storage"].(bool)
skipNodesWithSystemPods := config["skip_nodes_with_system_pods"].(bool)

return &containerservice.ManagedClusterPropertiesAutoScalerProfile{
BalanceSimilarNodeGroups: utils.String(strconv.FormatBool(balanceSimilarNodeGroups)),
Expand All @@ -2080,5 +2104,7 @@ func expandKubernetesClusterAutoScalerProfile(input []interface{}) *containerser
ScaleDownUnreadyTime: utils.String(scaleDownUnreadyTime),
ScaleDownUtilizationThreshold: utils.String(scaleDownUtilizationThreshold),
ScanInterval: utils.String(scanInterval),
SkipNodesWithLocalStorage: utils.String(strconv.FormatBool(skipNodesWithLocalStorage)),
SkipNodesWithSystemPods: utils.String(strconv.FormatBool(skipNodesWithSystemPods)),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ func testAccKubernetesCluster_autoScalingProfile(t *testing.T) {
check.That(data.ResourceName).Key("auto_scaler_profile.0.scale_down_unready").HasValue("15m"),
check.That(data.ResourceName).Key("auto_scaler_profile.0.scale_down_utilization_threshold").HasValue("0.5"),
check.That(data.ResourceName).Key("auto_scaler_profile.0.scan_interval").HasValue("10s"),
check.That(data.ResourceName).Key("auto_scaler_profile.0.skip_nodes_with_local_storage").HasValue("false"),
check.That(data.ResourceName).Key("auto_scaler_profile.0.skip_nodes_with_system_pods").HasValue("false"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -554,6 +556,8 @@ resource "azurerm_kubernetes_cluster" "test" {
scale_down_unneeded = "15m"
scale_down_unready = "15m"
scale_down_utilization_threshold = "0.5"
skip_nodes_with_local_storage = false
skip_nodes_with_system_pods = false
}
identity {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ A `auto_scaler_profile` block supports the following:

* `scale_down_utilization_threshold` - Node utilization level, defined as sum of requested resources divided by capacity, below which a node can be considered for scale down. Defaults to `0.5`.

* `skip_nodes_with_local_storage` - If `true` cluster autoscaler will never delete nodes with pods with local storage, for example, EmptyDir or HostPath. Defaults to `true`.

* `skip_nodes_with_system_pods` - If `true` cluster autoscaler will never delete nodes with pods from kube-system (except for DaemonSet or mirror pods). Defaults to `true`.

---

A `azure_active_directory` block supports the following:
Expand Down

0 comments on commit e5c6e26

Please sign in to comment.