Skip to content

Commit

Permalink
feat(tke): [115617024]add pre_start_user_script field (#2543)
Browse files Browse the repository at this point in the history
* add pre_start_user_script field

* add changelog 2543.txt
  • Loading branch information
bruceybian authored Feb 28, 2024
1 parent 793c2de commit eda6dd6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/2543.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_kubernetes_node_pool: add `pre_start_user_script` field
```
2 changes: 1 addition & 1 deletion tencentcloud/acctest/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const (

DefaultSecurityGroup = "sg-ijato2x1"

DefaultProjectId = "1250480"
DefaultProjectId = "0"

DefaultTkeOSImageId = "img-2lr9q49h"
DefaultTkeOSImageName = "tlinux2.2(tkernel3)x86_64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ func TkeInstanceAdvancedSetting() map[string]*schema.Schema {
Optional: true,
Description: "Base64-encoded User Data text, the length limit is 16KB.",
},
"pre_start_user_script": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Description: "Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.",
},
"is_schedule": {
Type: schema.TypeBool,
ForceNew: true,
Expand Down Expand Up @@ -303,6 +309,10 @@ func tkeGetInstanceAdvancedPara(dMap map[string]interface{}, meta interface{}) (
setting.UserScript = helper.String(v.(string))
}

if v, ok := dMap["pre_start_user_script"]; ok {
setting.PreStartUserScript = helper.String(v.(string))
}

if v, ok := dMap["docker_graph_path"]; ok {
setting.DockerGraphPath = helper.String(v.(string))
}
Expand Down
4 changes: 4 additions & 0 deletions tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,10 @@ func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) er
nodeConfig["docker_graph_path"] = "/var/lib/docker"
}

if helper.PString(nodePool.PreStartUserScript) != "" {
nodeConfig["pre_start_user_script"] = helper.PString(nodePool.PreStartUserScript)
}

if importFlag {
if nodePool.ExtraArgs != nil && len(nodePool.ExtraArgs.Kubelet) > 0 {
extraArgs := make([]string, 0)
Expand Down
16 changes: 10 additions & 6 deletions tencentcloud/services/tke/resource_tc_kubernetes_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestAccTencentCloudKubernetesNodePoolResource_basic(t *testing.T) {
testAccCheckTkeNodePoolExists,
resource.TestCheckResourceAttrSet(testTkeClusterNodePoolResourceKey, "cluster_id"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "node_config.#", "1"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "node_config.0.pre_start_user_script", "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg=="),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.#", "1"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.system_disk_size", "50"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.data_disk.#", "1"),
Expand Down Expand Up @@ -180,8 +181,8 @@ func TestAccTencentCloudKubernetesNodePoolResource_basic(t *testing.T) {
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "default_cooldown", "350"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "termination_policies.#", "1"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "termination_policies.0", "NEWEST_INSTANCE"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "tags.keep-test-np1", "testI"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "tags.keep-test-np3", "testIII"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "tags.keep-test-np1", "test1"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "tags.keep-test-np3", "test3"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.orderly_security_group_ids.#", "4"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.host_name", "12.123.1.1"),
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.host_name_style", "UNIQUE"),
Expand Down Expand Up @@ -382,6 +383,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
extra_args = [
"root-dir=/var/lib/kubelet"
]
pre_start_user_script = "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg=="
}
}
`
Expand Down Expand Up @@ -446,6 +448,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
extra_args = [
"root-dir=/var/lib/kubelet"
]
pre_start_user_script = "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg=="
}
}
`
Expand Down Expand Up @@ -514,14 +517,15 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
}
tags = {
keep-test-np1 = "testI"
keep-test-np3 = "testIII"
keep-test-np1 = "test1"
keep-test-np3 = "test3"
}
node_config {
extra_args = [
"root-dir=/var/lib/kubelet"
]
pre_start_user_script = "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg=="
}
}
`
Expand Down Expand Up @@ -627,8 +631,8 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
}
tags = {
keep-test-np1 = "testI"
keep-test-np3 = "testIII"
keep-test-np1 = "test1"
keep-test-np3 = "test3"
}
node_config {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/kubernetes_cluster_attachment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ The `worker_config_overrides` object supports the following:
* `gpu_args` - (Optional, List, ForceNew) GPU driver parameters.
* `is_schedule` - (Optional, Bool, ForceNew) Indicate to schedule the adding node or not. Default is true.
* `mount_target` - (Optional, String, ForceNew) Mount target. Default is not mounting.
* `pre_start_user_script` - (Optional, String, ForceNew) Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.
* `user_data` - (Optional, String, ForceNew) Base64-encoded User Data text, the length limit is 16KB.

The `worker_config` object supports the following:
Expand All @@ -172,6 +173,7 @@ The `worker_config` object supports the following:
* `gpu_args` - (Optional, List, ForceNew) GPU driver parameters.
* `is_schedule` - (Optional, Bool, ForceNew) Indicate to schedule the adding node or not. Default is true.
* `mount_target` - (Optional, String, ForceNew) Mount target. Default is not mounting.
* `pre_start_user_script` - (Optional, String, ForceNew) Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.
* `user_data` - (Optional, String, ForceNew) Base64-encoded User Data text, the length limit is 16KB.

## Attributes Reference
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/kubernetes_node_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ The `node_config` object supports the following:
* `gpu_args` - (Optional, List, ForceNew) GPU driver parameters.
* `is_schedule` - (Optional, Bool, ForceNew) Indicate to schedule the adding node or not. Default is true.
* `mount_target` - (Optional, String, ForceNew) Mount target. Default is not mounting.
* `pre_start_user_script` - (Optional, String, ForceNew) Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.
* `user_data` - (Optional, String, ForceNew) Base64-encoded User Data text, the length limit is 16KB.

The `taints` object supports the following:
Expand Down

0 comments on commit eda6dd6

Please sign in to comment.