Skip to content

Commit 48aa84c

Browse files
Sh4d1Quentin Brosse
authored and
Quentin Brosse
committed
feat(k8s): add autohealing to pools (scaleway#266)
1 parent d8e6766 commit 48aa84c

4 files changed

+31
-0
lines changed

scaleway/resource_k8s_cluster_beta.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ func resourceScalewayK8SClusterBeta() *schema.Resource {
9393
Default: false,
9494
Description: "Enable the autoscaling on the default pool",
9595
},
96+
"autohealing": {
97+
Type: schema.TypeBool,
98+
Optional: true,
99+
Default: false,
100+
Description: "Enable the autohealing on the default pool",
101+
},
96102
"size": {
97103
Type: schema.TypeInt,
98104
Required: true,
@@ -284,6 +290,7 @@ func resourceScalewayK8SClusterBetaCreate(d *schema.ResourceData, m interface{})
284290
defaultPoolReq := &k8s.CreateClusterRequestDefaultPoolConfig{
285291
NodeType: d.Get("default_pool.0.node_type").(string),
286292
Autoscaling: d.Get("default_pool.0.autoscaling").(bool),
293+
Autohealing: d.Get("default_pool.0.autohealing").(bool),
287294
Size: uint32(d.Get("default_pool.0.size").(int)),
288295
}
289296

@@ -363,6 +370,7 @@ func resourceScalewayK8SClusterBetaDefaultPoolRead(d *schema.ResourceData, m int
363370
defaultPool["pool_id"] = pool.ID
364371
defaultPool["node_type"] = pool.NodeType
365372
defaultPool["autoscaling"] = pool.Autoscaling
373+
defaultPool["autohealing"] = pool.Autohealing
366374
defaultPool["size"] = pool.Size
367375
defaultPool["min_size"] = pool.MinSize
368376
defaultPool["max_size"] = pool.MaxSize
@@ -480,6 +488,10 @@ func resourceScalewayK8SClusterBetaDefaultPoolUpdate(d *schema.ResourceData, m i
480488
updateRequest.Autoscaling = scw.BoolPtr(autoscaling.(bool))
481489
}
482490

491+
if autohealing, ok := d.GetOk("default_pool.0.autohealing"); ok {
492+
updateRequest.Autohealing = scw.BoolPtr(autohealing.(bool))
493+
}
494+
483495
if minSize, ok := d.GetOk("default_pool.0.min_size"); ok {
484496
updateRequest.MinSize = scw.Uint32Ptr(uint32(minSize.(int)))
485497
}
@@ -503,6 +515,7 @@ func resourceScalewayK8SClusterBetaDefaultPoolUpdate(d *schema.ResourceData, m i
503515
Name: "default",
504516
NodeType: d.Get("default_pool.0.node_type").(string),
505517
Autoscaling: d.Get("default_pool.0.autoscaling").(bool),
518+
Autohealing: d.Get("default_pool.0.autohealing").(bool),
506519
Size: uint32(d.Get("default_pool.0.size").(int)),
507520
}
508521
if placementGroupID, ok := d.GetOk("default_pool.0.placement_group_id"); ok {

scaleway/resource_k8s_cluster_beta_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func TestAccScalewayK8SClusterBetaDefaultPool(t *testing.T) {
124124
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.pool", "default_pool.0.min_size", "1"),
125125
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.pool", "default_pool.0.max_size", "2"),
126126
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.pool", "default_pool.0.autoscaling", "true"),
127+
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.pool", "default_pool.0.autohealing", "true"),
127128
resource.TestCheckResourceAttr("scaleway_k8s_cluster_beta.pool", "default_pool.0.container_runtime", "docker"),
128129
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.pool", "kubeconfig.0.config_file"),
129130
resource.TestCheckResourceAttrSet("scaleway_k8s_cluster_beta.pool", "kubeconfig.0.host"),
@@ -242,6 +243,7 @@ resource "scaleway_k8s_cluster_beta" "pool" {
242243
min_size = 1
243244
max_size = 2
244245
autoscaling = true
246+
autohealing = true
245247
container_runtime = "docker"
246248
}
247249
tags = [ "terraform-test", "scaleway_k8s_cluster_beta", "default-pool" ]

scaleway/resource_k8s_pool_beta.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ func resourceScalewayK8SPoolBeta() *schema.Resource {
4040
Default: false,
4141
Description: "Enable the autoscaling on the pool",
4242
},
43+
"autohealing": {
44+
Type: schema.TypeBool,
45+
Optional: true,
46+
Default: false,
47+
Description: "Enable the autohealing on the pool",
48+
},
4349
"size": {
4450
Type: schema.TypeInt,
4551
Required: true,
@@ -112,6 +118,7 @@ func resourceScalewayK8SPoolBetaCreate(d *schema.ResourceData, m interface{}) er
112118
Name: name.(string),
113119
NodeType: d.Get("node_type").(string),
114120
Autoscaling: d.Get("autoscaling").(bool),
121+
Autohealing: d.Get("autohealing").(bool),
115122
Size: uint32(d.Get("size").(int)),
116123
}
117124

@@ -168,6 +175,7 @@ func resourceScalewayK8SPoolBetaRead(d *schema.ResourceData, m interface{}) erro
168175
d.Set("name", pool.Name)
169176
d.Set("node_type", pool.NodeType)
170177
d.Set("autoscaling", pool.Autoscaling)
178+
d.Set("autohealing", pool.Autohealing)
171179
d.Set("size", pool.Size)
172180
d.Set("version", pool.Version)
173181
d.Set("min_size", pool.MinSize)
@@ -197,6 +205,10 @@ func resourceScalewayK8SPoolBetaUpdate(d *schema.ResourceData, m interface{}) er
197205
updateRequest.Autoscaling = scw.BoolPtr(d.Get("autoscaling").(bool))
198206
}
199207

208+
if d.HasChange("autohealing") {
209+
updateRequest.Autohealing = scw.BoolPtr(d.Get("autohealing").(bool))
210+
}
211+
200212
if d.HasChange("min_size") {
201213
updateRequest.MinSize = scw.Uint32Ptr(uint32(d.Get("min_size").(int)))
202214
}

scaleway/resource_k8s_pool_beta_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func TestAccScalewayK8SClusterPoolMinimal(t *testing.T) {
2828
testAccCheckScalewayK8SPoolBetaExists("scaleway_k8s_pool_beta.minimal"),
2929
resource.TestCheckResourceAttr("scaleway_k8s_pool_beta.minimal", "node_type", "gp1_xs"),
3030
resource.TestCheckResourceAttr("scaleway_k8s_pool_beta.minimal", "size", "1"),
31+
resource.TestCheckResourceAttr("scaleway_k8s_pool_beta.minimal", "autohealing", "true"),
32+
resource.TestCheckResourceAttr("scaleway_k8s_pool_beta.minimal", "autoscaling", "true"),
3133
resource.TestCheckResourceAttr("scaleway_k8s_pool_beta.minimal", "version", "1.16.0"),
3234
resource.TestCheckResourceAttrSet("scaleway_k8s_pool_beta.minimal", "id"),
3335
),
@@ -104,6 +106,8 @@ resource "scaleway_k8s_pool_beta" "minimal" {
104106
name = "minimal"
105107
cluster_id = "${scaleway_k8s_cluster_beta.minimal.id}"
106108
node_type = "gp1_xs"
109+
autohealing = true
110+
autoscaling = true
107111
size = 1
108112
}`)
109113
}

0 commit comments

Comments
 (0)