Skip to content

Commit 1184a53

Browse files
authored
Merge pull request #540 from ChuGuai/master
add tke scale worker "labels"
2 parents b51fd05 + 42404d4 commit 1184a53

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## 1.46.2 (Unreleased)
2+
ENHANCEMENTS:
3+
4+
* Resource: `tencentcloud_kubernetes_scale_worker` add new argument `labels` to support scale worker labels.
5+
26
## 1.46.1 (October 29, 2020)
37

48
ENHANCEMENTS:

tencentcloud/resource_tc_kubernetes_scale_worker.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ variable "scale_instance_type" {
2020
2121
resource tencentcloud_kubernetes_scale_worker test_scale {
2222
cluster_id = "cls-godovr32"
23-
23+
labels = {
24+
"test1" = "test1",
25+
"test2" = "test2",
26+
}
2427
worker_config {
2528
count = 3
2629
availability_zone = var.availability_zone
@@ -67,6 +70,11 @@ resource tencentcloud_kubernetes_scale_worker test_scale {
6770
"root-dir=/var/lib/kubelet"
6871
]
6972
73+
labels = {
74+
"test1" = "test1",
75+
"test2" = "test2",
76+
}
77+
7078
worker_config {
7179
count = 3
7280
availability_zone = var.availability_zone
@@ -129,6 +137,12 @@ func resourceTencentCloudTkeScaleWorker() *schema.Resource {
129137
},
130138
Description: "Deploy the machine configuration information of the 'WORK' service, and create <=20 units for common users.",
131139
},
140+
"labels": {
141+
Type: schema.TypeMap,
142+
Optional: true,
143+
ForceNew: true,
144+
Description: "Labels of kubernetes scale worker created nodes.",
145+
},
132146
"extra_args": {
133147
Type: schema.TypeList,
134148
Optional: true,
@@ -196,6 +210,8 @@ func resourceTencentCloudTkeScaleWorkerCreate(d *schema.ResourceData, meta inter
196210
}
197211
}
198212

213+
iAdvanced.Labels = GetTkeLabels(d, "labels")
214+
199215
if temp, ok := d.GetOk("extra_args"); ok {
200216
extraArgs := helper.InterfacesStrings(temp.([]interface{}))
201217
for _, extraArg := range extraArgs {
@@ -328,7 +344,7 @@ func resourceTencentCloudTkeScaleWorkerRead(d *schema.ResourceData, meta interfa
328344
}
329345

330346
newWorkerInstancesList := make([]map[string]interface{}, 0, len(workers))
331-
347+
newWorkerLabelList := make([]map[string]string, 0, len(workers))
332348
for _, cvm := range workers {
333349
if _, ok := instanceMap[cvm.InstanceId]; !ok {
334350
continue
@@ -339,6 +355,13 @@ func resourceTencentCloudTkeScaleWorkerRead(d *schema.ResourceData, meta interfa
339355
tempMap["instance_state"] = cvm.InstanceState
340356
tempMap["failed_reason"] = cvm.FailedReason
341357
newWorkerInstancesList = append(newWorkerInstancesList, tempMap)
358+
359+
labels := cvm.InstanceAdvancedSettings.Labels
360+
var labelsMap = make(map[string]string, len(labels))
361+
for _, v := range labels {
362+
labelsMap[*v.Name] = *v.Value
363+
}
364+
newWorkerLabelList = append(newWorkerLabelList, labelsMap)
342365
}
343366

344367
// The machines I generated was deleted by others.
@@ -347,6 +370,7 @@ func resourceTencentCloudTkeScaleWorkerRead(d *schema.ResourceData, meta interfa
347370
return nil
348371
}
349372

373+
_ = d.Set("labels", newWorkerLabelList)
350374
return d.Set("worker_instances_list", newWorkerInstancesList)
351375
}
352376
func resourceTencentCloudTkeScaleWorkerDelete(d *schema.ResourceData, meta interface{}) error {

tencentcloud/resource_tc_kubernetes_scale_worker_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ resource tencentcloud_kubernetes_scale_worker test_scale {
189189
"root-dir=/var/lib/kubelet"
190190
]
191191
192+
labels = {
193+
"test1" = "test1",
194+
"test2" = "test2",
195+
}
196+
192197
worker_config {
193198
count = 1
194199
availability_zone = var.availability_zone

tencentcloud/service_tencentcloud_tke.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ type ClusterInfo struct {
7979
}
8080

8181
type InstanceInfo struct {
82-
InstanceId string
83-
InstanceRole string
84-
InstanceState string
85-
FailedReason string
82+
InstanceId string
83+
InstanceRole string
84+
InstanceState string
85+
FailedReason string
86+
InstanceAdvancedSettings *tke.InstanceAdvancedSettings
8687
}
8788

8889
type TkeService struct {
@@ -138,10 +139,11 @@ getMoreData:
138139
}
139140
has[*item.InstanceId] = true
140141
instanceInfo := InstanceInfo{
141-
InstanceId: *item.InstanceId,
142-
InstanceRole: *item.InstanceRole,
143-
InstanceState: *item.InstanceState,
144-
FailedReason: *item.FailedReason,
142+
InstanceId: *item.InstanceId,
143+
InstanceRole: *item.InstanceRole,
144+
InstanceState: *item.InstanceState,
145+
FailedReason: *item.FailedReason,
146+
InstanceAdvancedSettings: item.InstanceAdvancedSettings,
145147
}
146148
if instanceInfo.InstanceRole == TKE_ROLE_WORKER {
147149
workers = append(workers, instanceInfo)
@@ -433,6 +435,7 @@ func (me *TkeService) CreateClusterInstances(ctx context.Context,
433435
if len(iAdvanced.ExtraArgs.Kubelet) > 0 {
434436
request.InstanceAdvancedSettings.ExtraArgs = &iAdvanced.ExtraArgs
435437
}
438+
request.InstanceAdvancedSettings.Labels = iAdvanced.Labels
436439

437440
ratelimit.Check(request.GetAction())
438441
response, err := me.client.UseTkeClient().CreateClusterInstances(request)

website/docs/r/kubernetes_scale_worker.html.markdown

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ variable "scale_instance_type" {
3030
3131
resource tencentcloud_kubernetes_scale_worker test_scale {
3232
cluster_id = "cls-godovr32"
33-
33+
labels = {
34+
"test1" = "test1",
35+
"test2" = "test2",
36+
}
3437
worker_config {
3538
count = 3
3639
availability_zone = var.availability_zone
@@ -77,6 +80,11 @@ resource tencentcloud_kubernetes_scale_worker test_scale {
7780
"root-dir=/var/lib/kubelet"
7881
]
7982
83+
labels = {
84+
"test1" = "test1",
85+
"test2" = "test2",
86+
}
87+
8088
worker_config {
8189
count = 3
8290
availability_zone = var.availability_zone
@@ -108,6 +116,7 @@ The following arguments are supported:
108116
* `cluster_id` - (Required, ForceNew) ID of the cluster.
109117
* `worker_config` - (Required, ForceNew) Deploy the machine configuration information of the 'WORK' service, and create <=20 units for common users.
110118
* `extra_args` - (Optional, ForceNew) Custom parameter information related to the node.
119+
* `labels` - (Optional, ForceNew) Labels of kubernetes scale worker created nodes.
111120

112121
The `data_disk` object supports the following:
113122

0 commit comments

Comments
 (0)