Skip to content

Commit 6f81d63

Browse files
authored
fixed the problem of synchronously modifying the maximum value and th… (#2354)
* fixed the problem of synchronously modifying the maximum value and the expected value * add changelog 2354.txt
1 parent f0a7989 commit 6f81d63

File tree

3 files changed

+96
-9
lines changed

3 files changed

+96
-9
lines changed

.changelog/2354.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_kubernetes_node_pool: Add verification when modifying the maximum value and expected value synchronously.
3+
```

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,12 +1550,24 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
15501550

15511551
d.Partial(true)
15521552

1553+
nodePool, _, err := service.DescribeNodePool(ctx, clusterId, nodePoolId)
1554+
if err != nil {
1555+
return err
1556+
}
1557+
oldDesiredCapacity := *nodePool.DesiredNodesNum
1558+
oldMinSize := *nodePool.MinNodesNum
1559+
oldMaxSize := *nodePool.MaxNodesNum
1560+
1561+
desiredCapacity := int64(d.Get("desired_capacity").(int))
1562+
minSize := int64(d.Get("min_size").(int))
1563+
maxSize := int64(d.Get("max_size").(int))
1564+
if desiredCapacity != oldDesiredCapacity && (minSize != oldMinSize || maxSize != oldMaxSize) {
1565+
log.Printf("[CRITAL]%s modification of min_size[%v] or max_size[%v] at the same time as desired_capacity[%v] failed\n", logId, minSize, maxSize, desiredCapacity)
1566+
return fmt.Errorf("`min_size` or `max_size` cannot be modified at the same time as `desired_capacity`, please modify `min_size` or `max_size` first, and then modify `desired_capacity`")
1567+
}
1568+
15531569
// LaunchConfig
15541570
if d.HasChange("auto_scaling_config") {
1555-
nodePool, _, err := service.DescribeNodePool(ctx, clusterId, nodePoolId)
1556-
if err != nil {
1557-
return err
1558-
}
15591571
launchConfigId := *nodePool.LaunchConfigurationId
15601572
// change as config here
15611573
request, composeError := composeAsLaunchConfigModifyRequest(d, launchConfigId)
@@ -1583,7 +1595,6 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
15831595
// min 3 max 6 desired 5
15841596
// modify min/max first will cause error, this case must upgrade desired first
15851597
if d.HasChange("desired_capacity") || !desiredCapacityOutRange(d) {
1586-
desiredCapacity := int64(d.Get("desired_capacity").(int))
15871598
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
15881599
errRet := service.ModifyClusterNodePoolDesiredCapacity(ctx, clusterId, nodePoolId, desiredCapacity)
15891600
if errRet != nil {
@@ -1610,8 +1621,6 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
16101621
"node_os",
16111622
"tags",
16121623
) {
1613-
maxSize := int64(d.Get("max_size").(int))
1614-
minSize := int64(d.Get("min_size").(int))
16151624
enableAutoScale := d.Get("enable_auto_scale").(bool)
16161625
deletionProtection := d.Get("deletion_protection").(bool)
16171626
name := d.Get("name").(string)

tencentcloud/resource_tc_kubernetes_node_pool_test.go

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ func TestAccTencentCloudKubernetesNodePoolResource_basic(t *testing.T) {
110110
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.enhanced_security_service", "false"),
111111
),
112112
},
113+
{
114+
Config: testAccTkeNodePoolClusterUpdateSize,
115+
Check: resource.ComposeTestCheckFunc(
116+
testAccCheckTkeNodePoolExists,
117+
resource.TestCheckResourceAttrSet(testTkeClusterNodePoolResourceKey, "cluster_id"),
118+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "max_size", "5"),
119+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "min_size", "0"),
120+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "desired_capacity", "1"),
121+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "name", "mynodepool"),
122+
),
123+
},
113124
{
114125
Config: testAccTkeNodePoolClusterUpdate,
115126
Check: resource.ComposeTestCheckFunc(
@@ -128,7 +139,7 @@ func TestAccTencentCloudKubernetesNodePoolResource_basic(t *testing.T) {
128139
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.spot_max_price", "1000"),
129140
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.cam_role_name", "TCB_QcsRole"),
130141
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "max_size", "5"),
131-
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "min_size", "2"),
142+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "min_size", "0"),
132143
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "labels.test3", "test3"),
133144
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "desired_capacity", "2"),
134145
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "name", "mynodepoolupdate"),
@@ -348,12 +359,76 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
348359
}
349360
`
350361

362+
const testAccTkeNodePoolClusterUpdateSize string = testAccTkeNodePoolClusterBasic + `
363+
resource "tencentcloud_kubernetes_node_pool" "np_test" {
364+
name = "mynodepool"
365+
cluster_id = local.cluster_id
366+
max_size = 5
367+
min_size = 0
368+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
369+
subnet_ids = [data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id]
370+
retry_policy = "INCREMENTAL_INTERVALS"
371+
desired_capacity = 1
372+
enable_auto_scale = true
373+
scaling_group_name = "asg_np_test"
374+
default_cooldown = 400
375+
termination_policies = ["OLDEST_INSTANCE"]
376+
scaling_group_project_id = var.default_project
377+
deletion_protection = true
378+
delete_keep_instance = false
379+
node_os="tlinux2.2(tkernel3)x86_64"
380+
381+
auto_scaling_config {
382+
instance_type = var.ins_type
383+
system_disk_type = "CLOUD_PREMIUM"
384+
system_disk_size = "50"
385+
orderly_security_group_ids = [data.tencentcloud_security_groups.sg.security_groups[0].security_group_id, data.tencentcloud_security_groups.sg_keep.security_groups[0].security_group_id]
386+
cam_role_name = "TCB_QcsRole"
387+
data_disk {
388+
disk_type = "CLOUD_PREMIUM"
389+
disk_size = 50
390+
}
391+
392+
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
393+
internet_max_bandwidth_out = 10
394+
public_ip_assigned = true
395+
password = "test123#"
396+
enhanced_security_service = false
397+
enhanced_monitor_service = false
398+
host_name = "12.123.0.0"
399+
host_name_style = "ORIGINAL"
400+
}
401+
unschedulable = 0
402+
labels = {
403+
"test1" = "test1",
404+
"test2" = "test2",
405+
}
406+
407+
taints {
408+
key = "test_taint"
409+
value = "taint_value"
410+
effect = "PreferNoSchedule"
411+
}
412+
413+
tags = {
414+
keep-test-np1 = "test1"
415+
keep-test-np2 = "test2"
416+
}
417+
418+
node_config {
419+
extra_args = [
420+
"root-dir=/var/lib/kubelet"
421+
]
422+
}
423+
}
424+
`
425+
351426
const testAccTkeNodePoolClusterUpdate string = testAccTkeNodePoolClusterBasic + `
352427
resource "tencentcloud_kubernetes_node_pool" "np_test" {
353428
name = "mynodepoolupdate"
354429
cluster_id = local.cluster_id
355430
max_size = 5
356-
min_size = 2
431+
min_size = 0
357432
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
358433
subnet_ids = [data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id]
359434
retry_policy = "INCREMENTAL_INTERVALS"

0 commit comments

Comments
 (0)