Skip to content

Commit 57e27c5

Browse files
authored
feat(tke): [117335378]Add pre_start_user_script and user_script fields (#2651)
* Add pre_start_user_script and user_script fields * add changelog 2651.txt * update test * update test * update test * update e2e test * update e2e test * update e2e test
1 parent 2482011 commit 57e27c5

6 files changed

+73
-7
lines changed

.changelog/2651.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_scale_worker: Add `pre_start_user_script` and `user_script` fields
3+
```

tencentcloud/services/tke/resource_tc_kubernetes_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
307307
Type: schema.TypeString,
308308
ForceNew: true,
309309
Optional: true,
310-
Description: "ase64-encoded User Data text, the length limit is 16KB.",
310+
Description: "User data provided to instances, needs to be encoded in base64, and the maximum supported data size is 16KB.",
311311
},
312312
"cam_role_name": {
313313
Type: schema.TypeString,

tencentcloud/services/tke/resource_tc_kubernetes_scale_worker.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func ResourceTencentCloudTkeScaleWorker() *schema.Resource {
8383
Optional: true,
8484
ForceNew: true,
8585
Default: 0,
86-
Description: "Sets whether the joining node participates in the schedule. Default is '0'. Participate in scheduling.",
86+
Description: "Set whether the added node participates in scheduling. The default value is 0, which means participating in scheduling; non-0 means not participating in scheduling. After the node initialization is completed, you can execute kubectl uncordon nodename to join the node in scheduling.",
8787
},
8888
"desired_pod_num": {
8989
Type: schema.TypeInt,
@@ -150,6 +150,18 @@ func ResourceTencentCloudTkeScaleWorker() *schema.Resource {
150150
},
151151
},
152152
},
153+
"pre_start_user_script": {
154+
Type: schema.TypeString,
155+
ForceNew: true,
156+
Optional: true,
157+
Description: "Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.",
158+
},
159+
"user_script": {
160+
Type: schema.TypeString,
161+
ForceNew: true,
162+
Optional: true,
163+
Description: "Base64 encoded user script, this script will be executed after the k8s component is run. The user needs to ensure that the script is reentrant and retry logic. The script and its generated log files can be viewed in the /data/ccs_userscript/ path of the node, if required. The node needs to be initialized before it can be added to the schedule. It can be used with the unschedulable parameter. After the final initialization of userScript is completed, add the kubectl uncordon nodename --kubeconfig=/root/.kube/config command to add the node to the schedule.",
164+
},
153165
// Computed values
154166
"worker_instances_list": {
155167
Type: schema.TypeList,
@@ -213,6 +225,14 @@ func resourceTencentCloudTkeScaleWorkerCreate(d *schema.ResourceData, meta inter
213225
iAdvanced.Unschedulable = helper.Int64(int64(temp.(int)))
214226
}
215227

228+
if v, ok := d.GetOk("pre_start_user_script"); ok {
229+
iAdvanced.PreStartUserScript = helper.String(v.(string))
230+
}
231+
232+
if v, ok := d.GetOk("user_script"); ok {
233+
iAdvanced.UserScript = helper.String(v.(string))
234+
}
235+
216236
if workers, ok := d.GetOk("worker_config"); ok {
217237
workerList := workers.([]interface{})
218238
for index := range workerList {
@@ -366,6 +386,8 @@ func resourceTencentCloudTkeScaleWorkerRead(d *schema.ResourceData, meta interfa
366386
}
367387

368388
_ = d.Set("unschedulable", helper.PInt64(cvm.InstanceAdvancedSettings.Unschedulable))
389+
_ = d.Set("pre_start_user_script", helper.PString(cvm.InstanceAdvancedSettings.PreStartUserScript))
390+
_ = d.Set("user_script", helper.PString(cvm.InstanceAdvancedSettings.UserScript))
369391

370392
if importFlag {
371393
_ = d.Set("docker_graph_path", helper.PString(cvm.InstanceAdvancedSettings.DockerGraphPath))

tencentcloud/services/tke/resource_tc_kubernetes_scale_worker_test.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func TestAccTencentCloudKubernetesScaleWorkerResource(t *testing.T) {
119119
resource.TestCheckResourceAttrSet(testTkeScaleWorkerResourceKey, "worker_instances_list.0.instance_id"),
120120
resource.TestCheckResourceAttrSet(testTkeScaleWorkerResourceKey, "worker_instances_list.0.instance_role"),
121121
resource.TestCheckResourceAttrSet(testTkeScaleWorkerResourceKey, "unschedulable"),
122+
resource.TestCheckResourceAttr(testTkeScaleWorkerResourceKey, "user_script", "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg=="),
122123
),
123124
},
124125
{
@@ -230,7 +231,43 @@ func testAccCheckTkeScaleWorkerExists(n string) resource.TestCheckFunc {
230231
}
231232
}
232233

233-
const testAccTkeScaleWorkerInstanceBasic = tcacctest.TkeExclusiveNetwork + tcacctest.TkeDataSource + tcacctest.DefaultSecurityGroupData
234+
const testAccTkeScaleWorkerInstanceBasic = tcacctest.TkeDataSource + `
235+
variable "default_az" {
236+
default = "ap-guangzhou-3"
237+
}
238+
239+
data "tencentcloud_vpc_instances" "vpc" {
240+
name = "keep-tke-vpc"
241+
}
242+
243+
data "tencentcloud_vpc_subnets" "subnet" {
244+
vpc_id = data.tencentcloud_vpc_instances.vpc.instance_list.0.vpc_id
245+
}
246+
247+
data "tencentcloud_instance_types" "default" {
248+
filter {
249+
name = "zone"
250+
values = [var.default_az]
251+
}
252+
filter {
253+
name = "instance-charge-type"
254+
values = ["POSTPAID_BY_HOUR"]
255+
}
256+
cpu_core_count = 2
257+
exclude_sold_out = true
258+
}
259+
260+
data "tencentcloud_security_groups" "internal" {
261+
name = "keep-tke"
262+
}
263+
264+
locals {
265+
vpc_id = data.tencentcloud_vpc_subnets.subnet.instance_list.0.vpc_id
266+
subnet_id = data.tencentcloud_vpc_subnets.subnet.instance_list.0.subnet_id
267+
scale_instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
268+
sg_id = data.tencentcloud_security_groups.internal.security_groups.0.security_group_id
269+
}
270+
`
234271

235272
const testAccTkeScaleWorkerInstance string = testAccTkeScaleWorkerInstanceBasic + `
236273
@@ -246,6 +283,7 @@ resource tencentcloud_kubernetes_scale_worker test_scale {
246283
"test2" = "test2",
247284
}
248285
unschedulable = 0
286+
user_script = "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg=="
249287
250288
worker_config {
251289
count = 1
@@ -284,6 +322,7 @@ resource tencentcloud_kubernetes_scale_worker test_scale {
284322
"test2" = "test2",
285323
}
286324
unschedulable = 0
325+
user_script = "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg=="
287326
288327
worker_config {
289328
count = 1

website/docs/r/kubernetes_cluster.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ The `master_config` object supports the following:
948948
* `security_group_ids` - (Optional, List, ForceNew) Security groups to which a CVM instance belongs.
949949
* `system_disk_size` - (Optional, Int, ForceNew) Volume of system disk in GB. Default is `50`.
950950
* `system_disk_type` - (Optional, String, ForceNew) System disk type. For more information on limits of system disk types, see [Storage Overview](https://intl.cloud.tencent.com/document/product/213/4952). Valid values: `LOCAL_BASIC`: local disk, `LOCAL_SSD`: local SSD disk, `CLOUD_SSD`: SSD, `CLOUD_PREMIUM`: Premium Cloud Storage. NOTE: `CLOUD_BASIC`, `LOCAL_BASIC` and `LOCAL_SSD` are deprecated.
951-
* `user_data` - (Optional, String, ForceNew) ase64-encoded User Data text, the length limit is 16KB.
951+
* `user_data` - (Optional, String, ForceNew) User data provided to instances, needs to be encoded in base64, and the maximum supported data size is 16KB.
952952

953953
The `node_pool_global_config` object supports the following:
954954

@@ -990,7 +990,7 @@ The `worker_config` object supports the following:
990990
* `security_group_ids` - (Optional, List, ForceNew) Security groups to which a CVM instance belongs.
991991
* `system_disk_size` - (Optional, Int, ForceNew) Volume of system disk in GB. Default is `50`.
992992
* `system_disk_type` - (Optional, String, ForceNew) System disk type. For more information on limits of system disk types, see [Storage Overview](https://intl.cloud.tencent.com/document/product/213/4952). Valid values: `LOCAL_BASIC`: local disk, `LOCAL_SSD`: local SSD disk, `CLOUD_SSD`: SSD, `CLOUD_PREMIUM`: Premium Cloud Storage. NOTE: `CLOUD_BASIC`, `LOCAL_BASIC` and `LOCAL_SSD` are deprecated.
993-
* `user_data` - (Optional, String, ForceNew) ase64-encoded User Data text, the length limit is 16KB.
993+
* `user_data` - (Optional, String, ForceNew) User data provided to instances, needs to be encoded in base64, and the maximum supported data size is 16KB.
994994

995995
## Attributes Reference
996996

website/docs/r/kubernetes_scale_worker.html.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ The following arguments are supported:
125125
* `gpu_args` - (Optional, List, ForceNew) GPU driver parameters.
126126
* `labels` - (Optional, Map, ForceNew) Labels of kubernetes scale worker created nodes.
127127
* `mount_target` - (Optional, String, ForceNew) Mount target. Default is not mounting.
128-
* `unschedulable` - (Optional, Int, ForceNew) Sets whether the joining node participates in the schedule. Default is '0'. Participate in scheduling.
128+
* `pre_start_user_script` - (Optional, String, ForceNew) Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.
129+
* `unschedulable` - (Optional, Int, ForceNew) Set whether the added node participates in scheduling. The default value is 0, which means participating in scheduling; non-0 means not participating in scheduling. After the node initialization is completed, you can execute kubectl uncordon nodename to join the node in scheduling.
130+
* `user_script` - (Optional, String, ForceNew) Base64 encoded user script, this script will be executed after the k8s component is run. The user needs to ensure that the script is reentrant and retry logic. The script and its generated log files can be viewed in the /data/ccs_userscript/ path of the node, if required. The node needs to be initialized before it can be added to the schedule. It can be used with the unschedulable parameter. After the final initialization of userScript is completed, add the kubectl uncordon nodename --kubeconfig=/root/.kube/config command to add the node to the schedule.
129131

130132
The `data_disk` object of `worker_config` supports the following:
131133

@@ -183,7 +185,7 @@ The `worker_config` object supports the following:
183185
* `security_group_ids` - (Optional, List, ForceNew) Security groups to which a CVM instance belongs.
184186
* `system_disk_size` - (Optional, Int, ForceNew) Volume of system disk in GB. Default is `50`.
185187
* `system_disk_type` - (Optional, String, ForceNew) System disk type. For more information on limits of system disk types, see [Storage Overview](https://intl.cloud.tencent.com/document/product/213/4952). Valid values: `LOCAL_BASIC`: local disk, `LOCAL_SSD`: local SSD disk, `CLOUD_SSD`: SSD, `CLOUD_PREMIUM`: Premium Cloud Storage. NOTE: `CLOUD_BASIC`, `LOCAL_BASIC` and `LOCAL_SSD` are deprecated.
186-
* `user_data` - (Optional, String, ForceNew) ase64-encoded User Data text, the length limit is 16KB.
188+
* `user_data` - (Optional, String, ForceNew) User data provided to instances, needs to be encoded in base64, and the maximum supported data size is 16KB.
187189

188190
## Attributes Reference
189191

0 commit comments

Comments
 (0)