7
7
"strings"
8
8
"time"
9
9
10
+ "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit"
11
+
10
12
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
11
13
12
14
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -445,25 +447,47 @@ func resourceTencentCloudKubernetesScaleWorkerCreateOnStart(ctx context.Context)
445
447
waitRequest := tke .NewDescribeClusterInstancesRequest ()
446
448
waitRequest .ClusterId = & clusterId
447
449
waitRequest .InstanceIds = helper .Strings (instanceIds )
448
- waitRequest .Offset = helper .Int64 (0 )
449
- waitRequest .Limit = helper .Int64 (100 )
450
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 ())
451
+ var (
452
+ offset int64 = 0
453
+ limit int64 = 100
454
+ tmpInstanceSet []* tke.Instance
455
+ )
456
+
457
+ // get all instances
458
+ for {
459
+ waitRequest .Limit = & limit
460
+ waitRequest .Offset = & offset
461
+ ratelimit .Check (waitRequest .GetAction ())
462
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseTkeClient ().DescribeClusterInstances (waitRequest )
463
+ if e != nil {
464
+ return tccommon .RetryError (e )
465
+ } else {
466
+ log .Printf ("[DEBUG] api[%s] success, request body [%s], response body [%s]\n " , waitRequest .GetAction (), waitRequest .ToJsonString (), result .ToJsonString ())
467
+ }
468
+
469
+ if result == nil || len (result .Response .InstanceSet ) == 0 {
470
+ break
471
+ }
472
+
473
+ tmpInstanceSet = append (tmpInstanceSet , result .Response .InstanceSet ... )
474
+
475
+ if len (result .Response .InstanceSet ) < int (limit ) {
476
+ break
477
+ }
478
+
479
+ offset += limit
456
480
}
457
481
458
482
// check instances status
459
- tmpInstanceSet := result .Response .InstanceSet
460
- if tmpInstanceSet == nil {
483
+ if len (tmpInstanceSet ) == 0 {
461
484
return resource .NonRetryableError (fmt .Errorf ("there is no instances in set" ))
462
485
} else {
463
486
var (
464
487
stop int
465
488
flag bool
466
489
)
490
+
467
491
for _ , v := range instanceIds {
468
492
for _ , instance := range tmpInstanceSet {
469
493
if v == * instance .InstanceId {
@@ -472,7 +496,7 @@ func resourceTencentCloudKubernetesScaleWorkerCreateOnStart(ctx context.Context)
472
496
flag = true
473
497
} else if * instance .InstanceState == "failed" {
474
498
stop += 1
475
- log .Printf ("instance:%s status is failed." , v )
499
+ log .Printf ("instance: %s status is failed." , v )
476
500
} else {
477
501
continue
478
502
}
@@ -485,8 +509,7 @@ func resourceTencentCloudKubernetesScaleWorkerCreateOnStart(ctx context.Context)
485
509
} else if stop == len (instanceIds ) && ! flag {
486
510
return resource .NonRetryableError (fmt .Errorf ("The instances being created have all failed." ))
487
511
} else {
488
- e = fmt .Errorf ("cluster instances is still initializing." )
489
- return resource .RetryableError (e )
512
+ return resource .RetryableError (fmt .Errorf ("cluster instances is still initializing." ))
490
513
}
491
514
}
492
515
})
0 commit comments