Skip to content

Commit 00a8525

Browse files
committed
fix: desired cap
1 parent 524eb26 commit 00a8525

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,17 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
215215
Elem: &schema.Resource{
216216
Schema: map[string]*schema.Schema{
217217
"disk_type": {
218-
Type: schema.TypeString,
219-
Optional: true,
220-
ForceNew: true,
218+
Type: schema.TypeString,
219+
Optional: true,
220+
//ForceNew: true,
221221
Default: SYSTEM_DISK_TYPE_CLOUD_PREMIUM,
222222
ValidateFunc: validateAllowedStringValue(SYSTEM_DISK_ALLOW_TYPE),
223223
Description: "Types of disk. Valid value: `CLOUD_PREMIUM` and `CLOUD_SSD`.",
224224
},
225225
"disk_size": {
226-
Type: schema.TypeInt,
227-
Optional: true,
228-
ForceNew: true,
226+
Type: schema.TypeInt,
227+
Optional: true,
228+
//ForceNew: true,
229229
Default: 0,
230230
Description: "Volume of disk in GB. Default is `0`.",
231231
},
@@ -897,6 +897,13 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
897897
return request
898898
}
899899

900+
func desiredCapacityOutRange(d *schema.ResourceData) bool {
901+
capacity := d.Get("desired_capacity").(int)
902+
minSize := d.Get("min_size").(int)
903+
maxSize := d.Get("max_size").(int)
904+
return capacity > maxSize || capacity < minSize
905+
}
906+
900907
func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) error {
901908
defer logElapsed("resource.tencentcloud_kubernetes_node_pool.read")()
902909

@@ -1265,6 +1272,27 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12651272
d.SetPartial("auto_scaling_config")
12661273
}
12671274

1275+
var capacityHasChanged = false
1276+
// assuming
1277+
// min 1 max 6 desired 2
1278+
// to
1279+
// min 3 max 6 desired 5
1280+
// modify min/max first will cause error, this case must upgrade desired first
1281+
if d.HasChange("desired_capacity") || !desiredCapacityOutRange(d) {
1282+
desiredCapacity := int64(d.Get("desired_capacity").(int))
1283+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
1284+
errRet := service.ModifyClusterNodePoolDesiredCapacity(ctx, clusterId, nodePoolId, desiredCapacity)
1285+
if errRet != nil {
1286+
return retryError(errRet)
1287+
}
1288+
return nil
1289+
})
1290+
if err != nil {
1291+
return err
1292+
}
1293+
capacityHasChanged = true
1294+
}
1295+
12681296
// ModifyClusterNodePool
12691297
if d.HasChange("min_size") || d.HasChange("max_size") || d.HasChange("name") || d.HasChange("labels") || d.HasChange("taints") || d.HasChange("enable_auto_scale") || d.HasChange("node_os_type") || d.HasChange("node_os") {
12701298
maxSize := int64(d.Get("max_size").(int))
@@ -1285,14 +1313,6 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12851313
if err != nil {
12861314
return err
12871315
}
1288-
d.SetPartial("min_size")
1289-
d.SetPartial("max_size")
1290-
d.SetPartial("name")
1291-
d.SetPartial("enable_auto_scale")
1292-
d.SetPartial("node_os")
1293-
d.SetPartial("node_os_type")
1294-
d.SetPartial("labels")
1295-
d.SetPartial("taints")
12961316
}
12971317

12981318
// ModifyScalingGroup
@@ -1361,7 +1381,7 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
13611381
d.SetPartial("termination_policies")
13621382
}
13631383

1364-
if d.HasChange("desired_capacity") {
1384+
if d.HasChange("desired_capacity") && !capacityHasChanged {
13651385
desiredCapacity := int64(d.Get("desired_capacity").(int))
13661386
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
13671387
errRet := service.ModifyClusterNodePoolDesiredCapacity(ctx, clusterId, nodePoolId, desiredCapacity)
@@ -1373,7 +1393,6 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
13731393
if err != nil {
13741394
return err
13751395
}
1376-
d.SetPartial("desired_capacity")
13771396
}
13781397

13791398
if d.HasChange("auto_scaling_config.0.backup_instance_types") {

tencentcloud/resource_tc_kubernetes_node_pool_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
330330
"test3" = "test3",
331331
"test2" = "test2",
332332
}
333+
334+
taints {
335+
key = "test_taint"
336+
value = "taint_value"
337+
effect = "PreferNoSchedule"
338+
}
333339
334340
node_config {
335341
extra_args = [

website/docs/r/kubernetes_node_pool.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ The `data_disk` object supports the following:
212212
The `data_disk` object supports the following:
213213

214214
* `delete_with_instance` - (Optional, Bool) Indicates whether the disk remove after instance terminated.
215-
* `disk_size` - (Optional, Int, ForceNew) Volume of disk in GB. Default is `0`.
216-
* `disk_type` - (Optional, String, ForceNew) Types of disk. Valid value: `CLOUD_PREMIUM` and `CLOUD_SSD`.
215+
* `disk_size` - (Optional, Int) Volume of disk in GB. Default is `0`.
216+
* `disk_type` - (Optional, String) Types of disk. Valid value: `CLOUD_PREMIUM` and `CLOUD_SSD`.
217217
* `encrypt` - (Optional, Bool) Specify whether to encrypt data disk, default: false.
218218
* `snapshot_id` - (Optional, String, ForceNew) Data disk snapshot ID.
219219
* `throughput_performance` - (Optional, Int) Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD` and `data_size` > 460GB.

0 commit comments

Comments
 (0)