Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(k8s): add unneeded time for autoscaler #461

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,614 changes: 9,614 additions & 0 deletions a

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk v1.0.0
github.com/mitchellh/go-homedir v1.1.0
github.com/nicolai86/scaleway-sdk v0.0.0-20181024210327-b20018e944c4
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200407075309-351601ab0ad3
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200421151545-c4338a1f64c9
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.5.0.20200219165633-cc8064e6b5f1/
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6 h1:C1/pvkxkGN/H03mDxLzItaceYJDBk1HdClgR15suAzI=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200407075309-351601ab0ad3 h1:0RWvOIoHoAQCctiGlGSYrjamJaD2zIxInpEbcF9ygq8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200407075309-351601ab0ad3/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200421151545-c4338a1f64c9 h1:VExNGApruijWPXvqW/ns6wlNwxAFm/8F7KnknJn5pwc=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200421151545-c4338a1f64c9/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
Expand Down
Binary file added main
Binary file not shown.
1 change: 1 addition & 0 deletions scaleway/helpers_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func clusterAutoscalerConfigFlatten(cluster *k8s.Cluster) []map[string]interface
autoscalerConfig := map[string]interface{}{}
autoscalerConfig["disable_scale_down"] = cluster.AutoscalerConfig.ScaleDownDisabled
autoscalerConfig["scale_down_delay_after_add"] = cluster.AutoscalerConfig.ScaleDownDelayAfterAdd
autoscalerConfig["scale_down_unneeded_time"] = cluster.AutoscalerConfig.ScaleDownUnneededTime
autoscalerConfig["estimator"] = cluster.AutoscalerConfig.Estimator
autoscalerConfig["expander"] = cluster.AutoscalerConfig.Expander
autoscalerConfig["ignore_daemonsets_utilization"] = cluster.AutoscalerConfig.IgnoreDaemonsetsUtilization
Expand Down
47 changes: 46 additions & 1 deletion scaleway/resource_k8s_cluster_beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ func resourceScalewayK8SClusterBetaCreate(d *schema.ResourceData, m interface{})
autoscalerReq.ScaleDownDelayAfterAdd = scw.StringPtr(scaleDownDelayAfterAdd.(string))
}

if scaleDownUneededTime, ok := d.GetOk("autoscaler_config.0.scale_down_unneeded_time"); ok {
autoscalerReq.ScaleDownUnneededTime = scw.StringPtr(scaleDownUneededTime.(string))
jerome-quere marked this conversation as resolved.
Show resolved Hide resolved
}

if estimator, ok := d.GetOk("autoscaler_config.0.estimator"); ok {
autoscalerReq.Estimator = k8s.AutoscalerEstimator(estimator.(string))
}
Expand Down Expand Up @@ -855,6 +859,42 @@ func resourceScalewayK8SClusterBetaUpdate(d *schema.ResourceData, m interface{})
updateRequest.AutoUpgrade.MaintenanceWindow.Day = k8s.MaintenanceWindowDayOfTheWeek(d.Get("auto_upgrade.0.maintenance_window_day").(string))
}

autoscalerReq := &k8s.UpdateClusterRequestAutoscalerConfig{}

if d.HasChange("autoscaler_config.0.disable_scale_down") {
autoscalerReq.ScaleDownDisabled = scw.BoolPtr((d.Get("autoscaler_config.0.disable_scale_down").(bool)))
}

if d.HasChange("autoscaler_config.0.scale_down_delay_after_add") {
autoscalerReq.ScaleDownDelayAfterAdd = scw.StringPtr(d.Get("autoscaler_config.0.scale_down_delay_after_add").(string))
}

if d.HasChange("autoscaler_config.0.scale_down_unneeded_time") {
autoscalerReq.ScaleDownUnneededTime = scw.StringPtr(d.Get("autoscaler_config.0.scale_down_unneeded_time").(string))
}

if d.HasChange("autoscaler_config.0.estimator") {
autoscalerReq.Estimator = k8s.AutoscalerEstimator(d.Get("autoscaler_config.0.estimator").(string))
}

if d.HasChange("autoscaler_config.0.expander") {
autoscalerReq.Expander = k8s.AutoscalerExpander(d.Get("autoscaler_config.0.expander").(string))
}

if d.HasChange("autoscaler_config.0.ignore_daemonsets_utilization") {
autoscalerReq.IgnoreDaemonsetsUtilization = scw.BoolPtr(d.Get("autoscaler_config.0.ignore_daemonsets_utilization").(bool))
}

if d.HasChange("autoscaler_config.0.balance_similar_node_groups") {
autoscalerReq.BalanceSimilarNodeGroups = scw.BoolPtr(d.Get("autoscaler_config.0.balance_similar_node_groups").(bool))
}

if d.HasChange("autoscaler_config.0.expendable_pods_priority_cutoff") {
autoscalerReq.ExpendablePodsPriorityCutoff = scw.Int32Ptr(int32(d.Get("autoscaler_config.0.expendable_pods_priority_cutoff").(int)))
}

updateRequest.AutoscalerConfig = autoscalerReq

////
// Apply Update
////
Expand Down Expand Up @@ -941,14 +981,19 @@ func autoscalerConfigSchema() *schema.Resource {
Default: "10m",
Description: "How long after scale up that scale down evaluation resumes",
},
"scale_down_unneeded_time": {
Type: schema.TypeString,
Optional: true,
Default: "10m",
Description: "How long a node should be unneeded before it is eligible for scale down",
},
"estimator": {
Type: schema.TypeString,
Optional: true,
Default: k8s.AutoscalerEstimatorBinpacking.String(),
Description: "Type of resource estimator to be used in scale up",
ValidateFunc: validation.StringInSlice([]string{
k8s.AutoscalerEstimatorBinpacking.String(),
k8s.AutoscalerEstimatorOldbinpacking.String(),
}, false),
},
"expander": {
Expand Down
46 changes: 46 additions & 0 deletions scaleway/resource_k8s_cluster_beta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,37 @@ func TestAccScalewayK8SClusterAutoscaling(t *testing.T) {
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.autoscaler", "wildcard_dns"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.disable_scale_down", "true"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.scale_down_delay_after_add", "20m"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.scale_down_unneeded_time", "20m"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.estimator", "binpacking"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.expander", "most_pods"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.ignore_daemonsets_utilization", "true"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.balance_similar_node_groups", "true"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.expendable_pods_priority_cutoff", "10"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "tags.0", "terraform-test"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "tags.1", "scaleway_k8s_cluster_beta"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "tags.2", "autoscaler-config"),
),
},
{
Config: testAccCheckScalewayK8SClusterBetaConfigAutoscalerChange("1.18.0"),
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayK8SClusterBetaExists("scaleway_k8s_cluster_beta.autoscaler"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "version", "1.18.0"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "cni", "calico"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "status", k8s.ClusterStatusPoolRequired.String()),
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.autoscaler", "kubeconfig.0.config_file"),
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.autoscaler", "kubeconfig.0.host"),
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.autoscaler", "kubeconfig.0.cluster_ca_certificate"),
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.autoscaler", "kubeconfig.0.token"),
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.autoscaler", "apiserver_url"),
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.autoscaler", "wildcard_dns"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.disable_scale_down", "false"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.scale_down_delay_after_add", "20m"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.scale_down_unneeded_time", "5m"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.estimator", "binpacking"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.expander", "most_pods"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.ignore_daemonsets_utilization", "false"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.balance_similar_node_groups", "false"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "autoscaler_config.0.expendable_pods_priority_cutoff", "0"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "tags.0", "terraform-test"),
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.autoscaler", "tags.1", "scaleway_k8s_cluster_beta"),
Expand Down Expand Up @@ -347,10 +374,29 @@ resource "scaleway_k8s_cluster_beta" "autoscaler" {
autoscaler_config {
disable_scale_down = true
scale_down_delay_after_add = "20m"
scale_down_unneeded_time = "20m"
estimator = "binpacking"
expander = "most_pods"
ignore_daemonsets_utilization = true
balance_similar_node_groups = true
expendable_pods_priority_cutoff = 10
}
tags = [ "terraform-test", "scaleway_k8s_cluster_beta", "autoscaler-config" ]
}`, version)
}

func testAccCheckScalewayK8SClusterBetaConfigAutoscalerChange(version string) string {
return fmt.Sprintf(`
resource "scaleway_k8s_cluster_beta" "autoscaler" {
cni = "calico"
version = "%s"
name = "autoscaler"
autoscaler_config {
disable_scale_down = false
scale_down_delay_after_add = "20m"
scale_down_unneeded_time = "5m"
estimator = "binpacking"
expander = "most_pods"
expendable_pods_priority_cutoff = 0
}
tags = [ "terraform-test", "scaleway_k8s_cluster_beta", "autoscaler-config" ]
Expand Down

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

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

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

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

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

Loading