Skip to content

Commit 66214b8

Browse files
authored
feat:update tke addon config for tcr (#1770)
* feat:update tke addon config for tcr * add changelog and update doc * rm cluster id from exapmle
1 parent 28f18dc commit 66214b8

File tree

4 files changed

+157
-40
lines changed

4 files changed

+157
-40
lines changed

.changelog/1770.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_addon_attachment: adjust the example for installing tcr addon
3+
```

tencentcloud/internal/helper/helper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ func ConvertInterfacesHeadToMap(v interface{}) (result map[string]interface{}, o
189189
return
190190
}
191191

192+
// CovertInterfaceMapToStrPtr returns [string:string] map from a [string:interface] map
193+
func CovertInterfaceMapToStrPtr(m map[string]interface{}) map[string]*string {
194+
result := make(map[string]*string)
195+
for k, v := range m {
196+
if s, ok := v.(string); ok {
197+
result[k] = &s
198+
}
199+
}
200+
return result
201+
}
202+
192203
func SetMapInterfaces(d *schema.ResourceData, key string, values ...map[string]interface{}) error {
193204
val := make([]interface{}, 0, len(values))
194205
for i := range values {

tencentcloud/resource_tc_kubernetes_addon_attachment.go

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Provide a resource to configure kubernetes cluster app addons.
55
66
Example Usage
77
8+
Install cbs addon by passing values
9+
810
```hcl
911
1012
resource "tencentcloud_kubernetes_addon_attachment" "addon_cbs" {
@@ -15,33 +17,82 @@ resource "tencentcloud_kubernetes_addon_attachment" "addon_cbs" {
1517
"rootdir=/var/lib/kubelet"
1618
]
1719
}
20+
```
21+
22+
Install tcr addon by passing values
1823
24+
```hcl
1925
resource "tencentcloud_kubernetes_addon_attachment" "addon_tcr" {
20-
cluster_id = "cls-xxxxxxxx"
21-
name = "tcr"
22-
# version = "1.0.0"
26+
cluster_id = "cls-xxxxxxxx" #specify your tke cluster id
27+
name = "tcr"
28+
version = "1.0.0"
2329
values = [
2430
# imagePullSecretsCrs is an array which can configure image pull
25-
"global.imagePullSecretsCrs[0].name=unique-sample-vpc",
26-
"global.imagePullSecretsCrs[0].namespaces=tcr-assistant-system",
27-
"global.imagePullSecretsCrs[0].serviceAccounts=*",
28-
"global.imagePullSecretsCrs[0].type=docker",
29-
"global.imagePullSecretsCrs[0].dockerUsername=100012345678",
30-
"global.imagePullSecretsCrs[0].dockerPassword=a.b.tcr-token",
31-
"global.imagePullSecretsCrs[0].dockerServer=xxxx.tencentcloudcr.com",
32-
"global.imagePullSecretsCrs[1].name=sample-public",
33-
"global.imagePullSecretsCrs[1].namespaces=*",
31+
"global.imagePullSecretsCrs[0].name=${local.tcr_id}-vpc", #specify a unique name, invalid format as: `${tcrId}-vpc`
32+
"global.imagePullSecretsCrs[0].namespaces=${local.ns_name}", #input the specified namespaces of the cluster, or input `*` for all.
33+
"global.imagePullSecretsCrs[0].serviceAccounts=*", #input the specified service account of the cluster, or input `*` for all.
34+
"global.imagePullSecretsCrs[0].type=docker", #only support docker now
35+
"global.imagePullSecretsCrs[0].dockerUsername=${local.user_name}", #input the access username, or you can create it from data source `tencentcloud_tcr_tokens`
36+
"global.imagePullSecretsCrs[0].dockerPassword=${local.token}", #input the access token, or you can create it from data source `tencentcloud_tcr_tokens`
37+
"global.imagePullSecretsCrs[0].dockerServer=${local.tcr_name}-vpc.tencentcloudcr.com", #invalid format as: `${tcr_name}-vpc.tencentcloudcr.com`
38+
"global.imagePullSecretsCrs[1].name=${local.tcr_id}-public", #specify a unique name, invalid format as: `${tcr_id}-public`
39+
"global.imagePullSecretsCrs[1].namespaces=${local.ns_name}",
3440
"global.imagePullSecretsCrs[1].serviceAccounts=*",
3541
"global.imagePullSecretsCrs[1].type=docker",
36-
"global.imagePullSecretsCrs[1].dockerUsername=100012345678",
37-
"global.imagePullSecretsCrs[1].dockerPassword=a.b.tcr-token",
38-
"global.imagePullSecretsCrs[1].dockerServer=sample",
39-
# Specify global hosts
40-
"global.hosts[0].domain=sample-vpc.tencentcloudcr.com",
41-
"global.hosts[0].ip=10.16.0.49",
42-
"global.hosts[0].disabled=false",
42+
"global.imagePullSecretsCrs[1].dockerUsername=${local.user_name}", #refer to previous description
43+
"global.imagePullSecretsCrs[1].dockerPassword=${local.token}", #refer to previous description
44+
"global.imagePullSecretsCrs[1].dockerServer=${local.tcr_name}-tencentcloudcr.com", #invalid format as: `${tcr_name}.tencentcloudcr.com`
45+
"global.cluster.region=gz",
46+
"global.cluster.longregion=ap-guangzhou",
47+
# Specify global hosts(optional), the numbers of hosts must be matched with the numbers of imagePullSecretsCrs
48+
"global.hosts[0].domain=${local.tcr_name}-vpc.tencentcloudcr.com", #Corresponds to the dockerServer in the imagePullSecretsCrs above
49+
"global.hosts[0].ip=${local.end_point}", #input InternalEndpoint of tcr instance, you can get it from data source `tencentcloud_tcr_instances`
50+
"global.hosts[0].disabled=false", #disabled this host config or not
51+
"global.hosts[1].domain=${local.tcr_name}-tencentcloudcr.com",
52+
"global.hosts[1].ip=${local.end_point}",
53+
"global.hosts[1].disabled=false",
4354
]
4455
}
56+
57+
locals {
58+
tcr_id = tencentcloud_tcr_instance.mytcr.id
59+
tcr_name = tencentcloud_tcr_instance.mytcr.name
60+
ns_name = tencentcloud_tcr_namespace.my_ns.name
61+
user_name = tencentcloud_tcr_token.my_token.user_name
62+
token = tencentcloud_tcr_token.my_token.token
63+
end_point = data.tencentcloud_tcr_instances.my_ins.instance_list.0.internal_end_point
64+
}
65+
66+
resource "tencentcloud_tcr_token" "my_token" {
67+
instance_id = local.tcr_id
68+
description = "tcr token"
69+
}
70+
71+
data "tencentcloud_tcr_instances" "my_ins" {
72+
instance_id = local.tcr_id
73+
}
74+
75+
resource "tencentcloud_tcr_instance" "mytcr" {
76+
name = "tf-test-tcr-addon"
77+
instance_type = "basic"
78+
delete_bucket = true
79+
80+
tags = {
81+
test = "test"
82+
}
83+
}
84+
85+
resource "tencentcloud_tcr_namespace" "my_ns" {
86+
instance_id = local.tcr_id
87+
name = "tf_test_tcr_ns_addon"
88+
is_public = true
89+
is_auto_scan = true
90+
is_prevent_vul = true
91+
severity = "medium"
92+
cve_whitelist_items {
93+
cve_id = "cve-xxxxx"
94+
}
95+
}
4596
```
4697
4798
Install new addon by passing spec json to req_body directly
@@ -235,7 +286,6 @@ func resourceTencentCloudTkeAddonAttachmentRead(d *schema.ResourceData, meta int
235286
err error
236287
response string
237288
addonResponseData = &AddonResponseData{}
238-
status = make(map[string]*string)
239289
)
240290

241291
_, has, err = service.PollingAddonsPhase(ctx, clusterId, addonName, addonResponseData)
@@ -255,6 +305,7 @@ func resourceTencentCloudTkeAddonAttachmentRead(d *schema.ResourceData, meta int
255305
_ = d.Set("response_body", response)
256306

257307
spec := addonResponseData.Spec
308+
statuses := addonResponseData.Status
258309

259310
if spec != nil {
260311
_ = d.Set("cluster_id", clusterId)
@@ -268,8 +319,9 @@ func resourceTencentCloudTkeAddonAttachmentRead(d *schema.ResourceData, meta int
268319
}
269320
}
270321

271-
if status != nil {
272-
err := d.Set("status", status)
322+
if statuses != nil || len(statuses) == 0 {
323+
strMap := helper.CovertInterfaceMapToStrPtr(statuses)
324+
err := d.Set("status", strMap)
273325
if err != nil {
274326
return err
275327
}

website/docs/r/kubernetes_addon_attachment.html.markdown

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Provide a resource to configure kubernetes cluster app addons.
1515

1616
## Example Usage
1717

18+
Install cbs addon by passing values
19+
1820
```hcl
1921
resource "tencentcloud_kubernetes_addon_attachment" "addon_cbs" {
2022
cluster_id = "cls-xxxxxxxx"
@@ -24,33 +26,82 @@ resource "tencentcloud_kubernetes_addon_attachment" "addon_cbs" {
2426
"rootdir=/var/lib/kubelet"
2527
]
2628
}
29+
```
30+
31+
Install tcr addon by passing values
2732

33+
```hcl
2834
resource "tencentcloud_kubernetes_addon_attachment" "addon_tcr" {
29-
cluster_id = "cls-xxxxxxxx"
35+
cluster_id = "cls-xxxxxxxx" #specify your tke cluster id
3036
name = "tcr"
31-
# version = "1.0.0"
37+
version = "1.0.0"
3238
values = [
3339
# imagePullSecretsCrs is an array which can configure image pull
34-
"global.imagePullSecretsCrs[0].name=unique-sample-vpc",
35-
"global.imagePullSecretsCrs[0].namespaces=tcr-assistant-system",
36-
"global.imagePullSecretsCrs[0].serviceAccounts=*",
37-
"global.imagePullSecretsCrs[0].type=docker",
38-
"global.imagePullSecretsCrs[0].dockerUsername=100012345678",
39-
"global.imagePullSecretsCrs[0].dockerPassword=a.b.tcr-token",
40-
"global.imagePullSecretsCrs[0].dockerServer=xxxx.tencentcloudcr.com",
41-
"global.imagePullSecretsCrs[1].name=sample-public",
42-
"global.imagePullSecretsCrs[1].namespaces=*",
40+
"global.imagePullSecretsCrs[0].name=${local.tcr_id}-vpc", #specify a unique name, invalid format as: `${tcrId}-vpc`
41+
"global.imagePullSecretsCrs[0].namespaces=${local.ns_name}", #input the specified namespaces of the cluster, or input `*` for all.
42+
"global.imagePullSecretsCrs[0].serviceAccounts=*", #input the specified service account of the cluster, or input `*` for all.
43+
"global.imagePullSecretsCrs[0].type=docker", #only support docker now
44+
"global.imagePullSecretsCrs[0].dockerUsername=${local.user_name}", #input the access username, or you can create it from data source `tencentcloud_tcr_tokens`
45+
"global.imagePullSecretsCrs[0].dockerPassword=${local.token}", #input the access token, or you can create it from data source `tencentcloud_tcr_tokens`
46+
"global.imagePullSecretsCrs[0].dockerServer=${local.tcr_name}-vpc.tencentcloudcr.com", #invalid format as: `${tcr_name}-vpc.tencentcloudcr.com`
47+
"global.imagePullSecretsCrs[1].name=${local.tcr_id}-public", #specify a unique name, invalid format as: `${tcr_id}-public`
48+
"global.imagePullSecretsCrs[1].namespaces=${local.ns_name}",
4349
"global.imagePullSecretsCrs[1].serviceAccounts=*",
4450
"global.imagePullSecretsCrs[1].type=docker",
45-
"global.imagePullSecretsCrs[1].dockerUsername=100012345678",
46-
"global.imagePullSecretsCrs[1].dockerPassword=a.b.tcr-token",
47-
"global.imagePullSecretsCrs[1].dockerServer=sample",
48-
# Specify global hosts
49-
"global.hosts[0].domain=sample-vpc.tencentcloudcr.com",
50-
"global.hosts[0].ip=10.16.0.49",
51-
"global.hosts[0].disabled=false",
51+
"global.imagePullSecretsCrs[1].dockerUsername=${local.user_name}", #refer to previous description
52+
"global.imagePullSecretsCrs[1].dockerPassword=${local.token}", #refer to previous description
53+
"global.imagePullSecretsCrs[1].dockerServer=${local.tcr_name}-tencentcloudcr.com", #invalid format as: `${tcr_name}.tencentcloudcr.com`
54+
"global.cluster.region=gz",
55+
"global.cluster.longregion=ap-guangzhou",
56+
# Specify global hosts(optional), the numbers of hosts must be matched with the numbers of imagePullSecretsCrs
57+
"global.hosts[0].domain=${local.tcr_name}-vpc.tencentcloudcr.com", #Corresponds to the dockerServer in the imagePullSecretsCrs above
58+
"global.hosts[0].ip=${local.end_point}", #input InternalEndpoint of tcr instance, you can get it from data source `tencentcloud_tcr_instances`
59+
"global.hosts[0].disabled=false", #disabled this host config or not
60+
"global.hosts[1].domain=${local.tcr_name}-tencentcloudcr.com",
61+
"global.hosts[1].ip=${local.end_point}",
62+
"global.hosts[1].disabled=false",
5263
]
5364
}
65+
66+
locals {
67+
tcr_id = tencentcloud_tcr_instance.mytcr.id
68+
tcr_name = tencentcloud_tcr_instance.mytcr.name
69+
ns_name = tencentcloud_tcr_namespace.my_ns.name
70+
user_name = tencentcloud_tcr_token.my_token.user_name
71+
token = tencentcloud_tcr_token.my_token.token
72+
end_point = data.tencentcloud_tcr_instances.my_ins.instance_list.0.internal_end_point
73+
}
74+
75+
resource "tencentcloud_tcr_token" "my_token" {
76+
instance_id = local.tcr_id
77+
description = "tcr token"
78+
}
79+
80+
data "tencentcloud_tcr_instances" "my_ins" {
81+
instance_id = local.tcr_id
82+
}
83+
84+
resource "tencentcloud_tcr_instance" "mytcr" {
85+
name = "tf-test-tcr-addon"
86+
instance_type = "basic"
87+
delete_bucket = true
88+
89+
tags = {
90+
test = "test"
91+
}
92+
}
93+
94+
resource "tencentcloud_tcr_namespace" "my_ns" {
95+
instance_id = local.tcr_id
96+
name = "tf_test_tcr_ns_addon"
97+
is_public = true
98+
is_auto_scan = true
99+
is_prevent_vul = true
100+
severity = "medium"
101+
cve_whitelist_items {
102+
cve_id = "cve-xxxxx"
103+
}
104+
}
54105
```
55106

56107
Install new addon by passing spec json to req_body directly

0 commit comments

Comments
 (0)