Skip to content

Commit 2061f13

Browse files
committed
dad
1 parent 7510103 commit 2061f13

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tencentcloud/services/tke/resource_tc_kubernetes_scale_worker_extension.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,55 @@ func resourceTencentCloudKubernetesScaleWorkerCreateOnStart(ctx context.Context)
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 resource.NonRetryableError(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)