Skip to content

Commit 6db3653

Browse files
fix: tke/nodepool - support multi_zone_subnet_policy modify (#1192)
* fix: tke/nodepool - support multi_zone_subnet_policy modify * Update mr.yml Co-authored-by: tongyiming <[email protected]>
1 parent 78b56bd commit 6db3653

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ func ResourceTencentCloudKubernetesNodePool() *schema.Resource {
423423
"multi_zone_subnet_policy": {
424424
Type: schema.TypeString,
425425
Optional: true,
426-
ForceNew: true,
427426
ValidateFunc: validateAllowedStringValue([]string{MultiZoneSubnetPolicyPriority,
428427
MultiZoneSubnetPolicyEquality}),
429428
Description: "Multi-availability zone/subnet policy. Valid values: PRIORITY and EQUALITY. Default value: PRIORITY.",
@@ -572,7 +571,7 @@ func ResourceTencentCloudKubernetesNodePool() *schema.Resource {
572571
}
573572
}
574573

575-
//this function composes every single parameter to a as scale parameter with json string format
574+
//this function composes every single parameter to an as scale parameter with json string format
576575
func composeParameterToAsScalingGroupParaSerial(d *schema.ResourceData) (string, error) {
577576
var (
578577
result string
@@ -1268,6 +1267,7 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12681267
if d.HasChange("scaling_group_name") ||
12691268
d.HasChange("zones") ||
12701269
d.HasChange("scaling_group_project_id") ||
1270+
d.HasChange("multi_zone_subnet_policy") ||
12711271
d.HasChange("default_cooldown") ||
12721272
d.HasChange("termination_policies") {
12731273

@@ -1277,28 +1277,42 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12771277
}
12781278

12791279
var (
1280-
scalingGroupId = *nodePool.AutoscalingGroupId
1281-
name = d.Get("scaling_group_name").(string)
1282-
projectId = d.Get("scaling_group_project_id").(int)
1283-
defaultCooldown = d.Get("default_cooldown").(int)
1284-
zones []*string
1285-
terminationPolicies []*string
1280+
request = as.NewModifyAutoScalingGroupRequest()
1281+
scalingGroupId = *nodePool.AutoscalingGroupId
1282+
name = d.Get("scaling_group_name").(string)
1283+
projectId = d.Get("scaling_group_project_id").(int)
1284+
defaultCooldown = d.Get("default_cooldown").(int)
1285+
multiZoneSubnetPolicy = d.Get("multi_zone_subnet_policy").(string)
12861286
)
12871287

1288+
request.AutoScalingGroupId = &scalingGroupId
1289+
1290+
if name != "" {
1291+
request.AutoScalingGroupName = &name
1292+
}
1293+
1294+
if multiZoneSubnetPolicy != "" {
1295+
request.MultiZoneSubnetPolicy = &multiZoneSubnetPolicy
1296+
}
1297+
1298+
if projectId != 0 {
1299+
request.ProjectId = helper.IntUint64(projectId)
1300+
}
1301+
1302+
if defaultCooldown != 0 {
1303+
request.DefaultCooldown = helper.IntUint64(defaultCooldown)
1304+
}
1305+
12881306
if v, ok := d.GetOk("zones"); ok {
1289-
for _, zone := range v.([]interface{}) {
1290-
zones = append(zones, helper.String(zone.(string)))
1291-
}
1307+
request.Zones = helper.InterfacesStringsPoint(v.([]interface{}))
12921308
}
12931309

12941310
if v, ok := d.GetOk("termination_policies"); ok {
1295-
for _, policy := range v.([]interface{}) {
1296-
terminationPolicies = append(terminationPolicies, helper.String(policy.(string)))
1297-
}
1311+
request.TerminationPolicies = helper.InterfacesStringsPoint(v.([]interface{}))
12981312
}
12991313

13001314
err = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
1301-
errRet := asService.ModifyScalingGroup(ctx, scalingGroupId, name, projectId, defaultCooldown, zones, terminationPolicies)
1315+
errRet := asService.ModifyAutoScalingGroup(ctx, request)
13021316
if errRet != nil {
13031317
return retryError(errRet)
13041318
}

tencentcloud/resource_tc_kubernetes_node_pool_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
294294
scaling_group_name = "basic_group_test"
295295
default_cooldown = 350
296296
termination_policies = ["NEWEST_INSTANCE"]
297+
multi_zone_subnet_policy = "EQUALITY"
297298
298299
auto_scaling_config {
299300
instance_type = local.final_type

tencentcloud/service_tencentcloud_as.go

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -440,40 +440,27 @@ func (me *AsService) DescribeScheduledActionById(ctx context.Context, scheduledA
440440
return
441441
}
442442

443-
func (me *AsService) ModifyScalingGroup(ctx context.Context, id string, name string, projectId int, cooldown int, zones []*string, terminationPolicies []*string) error {
443+
func (me *AsService) ModifyAutoScalingGroup(ctx context.Context, request *as.ModifyAutoScalingGroupRequest) (errRet error) {
444444
logId := getLogId(ctx)
445-
request := as.NewModifyAutoScalingGroupRequest()
446-
447-
request.AutoScalingGroupId = helper.String(id)
448-
449-
if name != "" {
450-
request.AutoScalingGroupName = helper.String(name)
451-
}
452-
453-
if projectId != 0 {
454-
request.ProjectId = helper.IntUint64(projectId)
455-
}
445+
defer func() {
446+
if errRet != nil {
447+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
448+
logId, request.GetAction(), request.ToJsonString(), errRet.Error())
449+
}
450+
}()
456451

457-
if cooldown != 0 {
458-
request.DefaultCooldown = helper.IntUint64(cooldown)
459-
}
452+
ratelimit.Check(request.GetAction())
453+
response, err := me.client.UseAsClient().ModifyAutoScalingGroup(request)
460454

461-
if len(zones) != 0 {
462-
request.Zones = zones
455+
if err != nil {
456+
errRet = err
457+
return
463458
}
464459

465-
if len(terminationPolicies) != 0 {
466-
request.TerminationPolicies = terminationPolicies
467-
}
460+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
461+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
468462

469-
ratelimit.Check(request.GetAction())
470-
_, err := me.client.UseAsClient().ModifyAutoScalingGroup(request)
471-
if err != nil {
472-
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
473-
logId, request.GetAction(), request.ToJsonString(), err.Error())
474-
return err
475-
}
476-
return nil
463+
return
477464
}
478465

479466
func (me *AsService) DeleteScheduledAction(ctx context.Context, scheduledActonId string) error {

website/docs/r/kubernetes_node_pool.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ The following arguments are supported:
163163
* `desired_capacity` - (Optional, Int) Desired capacity ot the node. If `enable_auto_scale` is set `true`, this will be a computed parameter.
164164
* `enable_auto_scale` - (Optional, Bool) Indicate whether to enable auto scaling or not.
165165
* `labels` - (Optional, Map) Labels of kubernetes node pool created nodes. The label key name does not exceed 63 characters, only supports English, numbers,'/','-', and does not allow beginning with ('/').
166-
* `multi_zone_subnet_policy` - (Optional, String, ForceNew) Multi-availability zone/subnet policy. Valid values: PRIORITY and EQUALITY. Default value: PRIORITY.
166+
* `multi_zone_subnet_policy` - (Optional, String) Multi-availability zone/subnet policy. Valid values: PRIORITY and EQUALITY. Default value: PRIORITY.
167167
* `node_config` - (Optional, List) Node config.
168168
* `node_os_type` - (Optional, String) The image version of the node. Valida values are `DOCKER_CUSTOMIZE` and `GENERAL`. Default is `GENERAL`. This parameter will only affect new nodes, not including the existing nodes.
169169
* `node_os` - (Optional, String) Operating system of the cluster, the available values include: `tlinux2.4x86_64`, `ubuntu18.04.1x86_64`, `ubuntu16.04.1 LTSx86_64`, `centos7.6.0_x64` and `centos7.2x86_64`. Default is 'tlinux2.4x86_64'. This parameter will only affect new nodes, not including the existing nodes.

0 commit comments

Comments
 (0)