Skip to content

Commit c1406d2

Browse files
authored
fix(tke): [118133957] support retry (#2723)
* dad * dad * dad
1 parent 54857fa commit c1406d2

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

.changelog/2723.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_kubernetes_scale_worker: support retry
3+
```

tencentcloud/services/tke/resource_tc_kubernetes_scale_worker_extension.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,60 @@ func resourceTencentCloudKubernetesScaleWorkerCreateOnStart(ctx context.Context)
435435
}
436436

437437
//修改id设置,不符合id规则
438-
id := clusterId + tccommon.FILED_SP + strings.Join(instanceIds, tccommon.FILED_SP)
438+
id := clusterId + tccommon.FILED_SP + strings.Join(instanceIds, tccommon.COMMA_SP)
439439
d.SetId(id)
440440

441441
//wait for LANIP
442442
time.Sleep(tccommon.ReadRetryTimeout)
443+
444+
// wait for all instances status running
445+
waitRequest := tke.NewDescribeClusterInstancesRequest()
446+
waitRequest.ClusterId = &clusterId
447+
waitRequest.InstanceIds = helper.Strings(instanceIds)
448+
waitRequest.Offset = helper.Int64(0)
449+
waitRequest.Limit = helper.Int64(100)
450+
err = resource.Retry(tccommon.ReadRetryTimeout*5, func() *resource.RetryError {
451+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTkeClient().DescribeClusterInstances(waitRequest)
452+
if e != nil {
453+
return tccommon.RetryError(e)
454+
} else {
455+
log.Printf("[DEBUG] api[%s] success, request body [%s], response body [%s]\n", waitRequest.GetAction(), waitRequest.ToJsonString(), result.ToJsonString())
456+
}
457+
458+
// check instances status
459+
tmpInstanceSet := result.Response.InstanceSet
460+
if tmpInstanceSet == nil || len(tmpInstanceSet) == 0 {
461+
return resource.NonRetryableError(fmt.Errorf("there is no instances in set"))
462+
} else {
463+
var stop int
464+
for _, v := range instanceIds {
465+
for _, instance := range tmpInstanceSet {
466+
if v == *instance.InstanceId {
467+
if *instance.InstanceState == "running" {
468+
stop += 1
469+
} else if *instance.InstanceState == "failed" {
470+
stop += 1
471+
log.Printf("instance:%s status is failed.", v)
472+
} else {
473+
continue
474+
}
475+
}
476+
}
477+
}
478+
479+
if stop == len(instanceIds) {
480+
return nil
481+
}
482+
}
483+
484+
e = fmt.Errorf("cluster instances is still initializing.")
485+
return tccommon.RetryError(e)
486+
})
487+
488+
if err != nil {
489+
log.Printf("[CRITAL] kubernetes scale worker instances status error, reason:%+v", err)
490+
}
491+
443492
return nil
444493
}
445494

0 commit comments

Comments
 (0)