Skip to content

Commit

Permalink
feat(tke): [116205708]kubenetes clusters datasource add kube_config_f…
Browse files Browse the repository at this point in the history
…ile_prefix field (#2530)

* kubenetes clusters datasource add kube_config_file_prefix field

* add changelog 2530.txt
  • Loading branch information
bruceybian authored Feb 19, 2024
1 parent 331b7f2 commit f07c1b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/2530.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
datasource/tencentcloud_kubernetes_clusters: add `kube_config_file_prefix` field
```
27 changes: 25 additions & 2 deletions tencentcloud/services/tke/data_source_tc_kubernetes_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tke

import (
"context"
"fmt"
"log"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
Expand Down Expand Up @@ -227,6 +228,11 @@ func DataSourceTencentCloudKubernetesClusters() *schema.Resource {
Optional: true,
Description: "Used to save results.",
},
"kube_config_file_prefix": {
Type: schema.TypeString,
Optional: true,
Description: "The path prefix of kube config. You can store KubeConfig in a specified directory by specifying this field, such as ~/.kube/k8s, then public network access will use ~/.kube/k8s-clusterID-kubeconfig naming, and intranet access will use ~/.kube /k8s-clusterID-kubeconfig-intranet naming. If this field is not set, the KubeConfig will not be exported.",
},

"list": {
Type: schema.TypeList,
Expand All @@ -251,8 +257,9 @@ func dataSourceTencentCloudKubernetesClustersRead(d *schema.ResourceData, meta i
}

var (
id string
name string
id string
name string
kubeConfigFilePrefix string
)

if v, ok := d.GetOk("cluster_id"); ok {
Expand Down Expand Up @@ -290,6 +297,10 @@ func dataSourceTencentCloudKubernetesClustersRead(d *schema.ResourceData, meta i
}
}

if v, ok := d.GetOk("kube_config_file_prefix"); ok {
kubeConfigFilePrefix = v.(string)
}

LOOP:
for _, info := range infos {
if len(tags) > 0 {
Expand Down Expand Up @@ -410,6 +421,18 @@ LOOP:

infoMap["kube_config"] = config
infoMap["kube_config_intranet"] = intranetConfig

if kubeConfigFilePrefix != "" {
kubeConfigFile := kubeConfigFilePrefix + fmt.Sprintf("-%s-kubeconfig", info.ClusterId)
if err = tccommon.WriteToFile(kubeConfigFile, config); err != nil {
return err
}
kubeConfigIntranetFile := kubeConfigFilePrefix + fmt.Sprintf("-%s-kubeconfig-intranet", info.ClusterId)
if err = tccommon.WriteToFile(kubeConfigIntranetFile, intranetConfig); err != nil {
return err
}
}

list = append(list, infoMap)
}

Expand Down
1 change: 1 addition & 0 deletions website/docs/d/kubernetes_clusters.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following arguments are supported:

* `cluster_id` - (Optional, String) ID of the cluster. Conflict with cluster_name, can not be set at the same time.
* `cluster_name` - (Optional, String) Name of the cluster. Conflict with cluster_id, can not be set at the same time.
* `kube_config_file_prefix` - (Optional, String) The path prefix of kube config. You can store KubeConfig in a specified directory by specifying this field, such as ~/.kube/k8s, then public network access will use ~/.kube/k8s-clusterID-kubeconfig naming, and intranet access will use ~/.kube /k8s-clusterID-kubeconfig-intranet naming. If this field is not set, the KubeConfig will not be exported.
* `result_output_file` - (Optional, String) Used to save results.
* `tags` - (Optional, Map) Tags of the cluster.

Expand Down

0 comments on commit f07c1b7

Please sign in to comment.