Skip to content

Commit 013d864

Browse files
authored
fix: tke - modify params of requesting kubeconfig. (#1183)
* fix: tke - modify params of requesting kubeconfig. * feat: tke - support intranet kubeconfig
1 parent bbd6386 commit 013d864

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

tencentcloud/data_source_tc_kubernetes_clusters.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ func tkeClusterInfo() map[string]*schema.Schema {
192192
"kube_config": {
193193
Type: schema.TypeString,
194194
Computed: true,
195-
Description: "kubernetes config.",
195+
Description: "Kubernetes config.",
196+
},
197+
"kube_config_intranet": {
198+
Type: schema.TypeString,
199+
Computed: true,
200+
Description: "Kubernetes config of private network.",
196201
},
197202
}
198203

@@ -379,16 +384,38 @@ LOOP:
379384
infoMap["pgw_endpoint"] = emptyStrFunc(securityRet.Response.PgwEndpoint)
380385
infoMap["security_policy"] = policies
381386

382-
config, err := service.DescribeClusterConfig(ctx, info.ClusterId)
387+
config, err := service.DescribeClusterConfig(ctx, info.ClusterId, true)
388+
if err != nil {
389+
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
390+
config, err = service.DescribeClusterConfig(ctx, d.Id(), true)
391+
if err != nil {
392+
return retryError(err)
393+
}
394+
return nil
395+
})
396+
}
397+
if err != nil {
398+
log.Printf("[CRITAL]%s tencentcloud_kubernetes_clusters DescribeClusterInstances fail, reason:%s\n ", logId, err.Error())
399+
return err
400+
}
401+
402+
intranetConfig, err := service.DescribeClusterConfig(ctx, info.ClusterId, false)
383403
if err != nil {
384-
config, err = service.DescribeClusterConfig(ctx, info.ClusterId)
404+
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
405+
config, err = service.DescribeClusterConfig(ctx, d.Id(), false)
406+
if err != nil {
407+
return retryError(err)
408+
}
409+
return nil
410+
})
385411
}
386412
if err != nil {
387413
log.Printf("[CRITAL]%s tencentcloud_kubernetes_clusters DescribeClusterInstances fail, reason:%s\n ", logId, err.Error())
388414
return err
389415
}
390416

391417
infoMap["kube_config"] = config
418+
infoMap["kube_config_intranet"] = intranetConfig
392419
list = append(list, infoMap)
393420
}
394421

tencentcloud/resource_tc_kubernetes_cluster.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,12 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
14311431
"kube_config": {
14321432
Type: schema.TypeString,
14331433
Computed: true,
1434-
Description: "kubernetes config.",
1434+
Description: "Kubernetes config.",
1435+
},
1436+
"kube_config_intranet": {
1437+
Type: schema.TypeString,
1438+
Computed: true,
1439+
Description: "Kubernetes config of private network.",
14351440
},
14361441
}
14371442

@@ -2369,10 +2374,10 @@ func resourceTencentCloudTkeClusterRead(d *schema.ResourceData, meta interface{}
23692374
_ = d.Set("auto_upgrade_cluster_level", info.AutoUpgradeClusterLevel)
23702375
}
23712376

2372-
config, err := service.DescribeClusterConfig(ctx, d.Id())
2377+
config, err := service.DescribeClusterConfig(ctx, d.Id(), true)
23732378
if err != nil {
23742379
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
2375-
config, err = service.DescribeClusterConfig(ctx, d.Id())
2380+
config, err = service.DescribeClusterConfig(ctx, d.Id(), true)
23762381
if err != nil {
23772382
return retryError(err)
23782383
}
@@ -2386,6 +2391,23 @@ func resourceTencentCloudTkeClusterRead(d *schema.ResourceData, meta interface{}
23862391

23872392
_ = d.Set("kube_config", config)
23882393

2394+
intranetConfig, err := service.DescribeClusterConfig(ctx, d.Id(), false)
2395+
if err != nil {
2396+
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
2397+
intranetConfig, err = service.DescribeClusterConfig(ctx, d.Id(), false)
2398+
if err != nil {
2399+
return retryError(err)
2400+
}
2401+
return nil
2402+
})
2403+
}
2404+
2405+
if err != nil {
2406+
return nil
2407+
}
2408+
2409+
_ = d.Set("kube_config_intranet", intranetConfig)
2410+
23892411
_, workers, err := service.DescribeClusterInstances(ctx, d.Id())
23902412
if err != nil {
23912413
err = resource.Retry(10*readRetryTimeout, func() *resource.RetryError {

tencentcloud/service_tencentcloud_tke.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,13 @@ func (me *TkeService) DescribeClusterLevelAttribute(ctx context.Context, id stri
370370
return
371371
}
372372

373-
func (me *TkeService) DescribeClusterConfig(ctx context.Context, id string) (config string, errRet error) {
373+
func (me *TkeService) DescribeClusterConfig(ctx context.Context, id string, isPublic bool) (config string, errRet error) {
374374

375375
logId := getLogId(ctx)
376376
request := tke.NewDescribeClusterKubeconfigRequest()
377+
if isPublic {
378+
request.IsExtranet = &isPublic
379+
}
377380

378381
defer func() {
379382
if errRet != nil {

website/docs/d/kubernetes_clusters.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ In addition to all arguments above, the following attributes are exported:
6262
* `eni_subnet_ids` - Subnet IDs for cluster with VPC-CNI network mode.
6363
* `ignore_cluster_cidr_conflict` - Indicates whether to ignore the cluster cidr conflict error.
6464
* `is_non_static_ip_mode` - Indicates whether non-static ip mode is enabled.
65-
* `kube_config` - kubernetes config.
65+
* `kube_config_intranet` - Kubernetes config of private network.
66+
* `kube_config` - Kubernetes config.
6667
* `kube_proxy_mode` - Cluster kube-proxy mode.
6768
* `network_type` - Cluster network type.
6869
* `node_name_type` - Node name type of cluster.

website/docs/r/kubernetes_cluster.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ In addition to all arguments above, the following attributes are exported:
623623
* `cluster_external_endpoint` - External network address to access.
624624
* `cluster_node_num` - Number of nodes in the cluster.
625625
* `domain` - Domain name for access.
626-
* `kube_config` - kubernetes config.
626+
* `kube_config_intranet` - Kubernetes config of private network.
627+
* `kube_config` - Kubernetes config.
627628
* `password` - Password of account.
628629
* `pgw_endpoint` - The Intranet address used for access.
629630
* `security_policy` - Access policy.

0 commit comments

Comments
 (0)