From eda6dd603573298ac1af2905e270755a2fb0c83b Mon Sep 17 00:00:00 2001 From: bruceybian <49861427+bruceybian@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:37:19 +0800 Subject: [PATCH] feat(tke): [115617024]add pre_start_user_script field (#2543) * add pre_start_user_script field * add changelog 2543.txt --- .changelog/2543.txt | 3 +++ tencentcloud/acctest/basic.go | 2 +- .../resource_tc_kubernetes_cluster_attachment.go | 10 ++++++++++ .../tke/resource_tc_kubernetes_node_pool.go | 4 ++++ .../tke/resource_tc_kubernetes_node_pool_test.go | 16 ++++++++++------ .../kubernetes_cluster_attachment.html.markdown | 2 ++ .../docs/r/kubernetes_node_pool.html.markdown | 1 + 7 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 .changelog/2543.txt diff --git a/.changelog/2543.txt b/.changelog/2543.txt new file mode 100644 index 0000000000..219be20734 --- /dev/null +++ b/.changelog/2543.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_kubernetes_node_pool: add `pre_start_user_script` field +``` \ No newline at end of file diff --git a/tencentcloud/acctest/basic.go b/tencentcloud/acctest/basic.go index 061b27e7e8..ac178352b1 100644 --- a/tencentcloud/acctest/basic.go +++ b/tencentcloud/acctest/basic.go @@ -101,7 +101,7 @@ const ( DefaultSecurityGroup = "sg-ijato2x1" - DefaultProjectId = "1250480" + DefaultProjectId = "0" DefaultTkeOSImageId = "img-2lr9q49h" DefaultTkeOSImageName = "tlinux2.2(tkernel3)x86_64" diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go index 487da50eda..b705b1072b 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go +++ b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go @@ -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, @@ -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)) } diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go b/tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go index 025e470af4..bfaf38e800 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go +++ b/tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go @@ -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) diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_node_pool_test.go b/tencentcloud/services/tke/resource_tc_kubernetes_node_pool_test.go index f29d09a17f..a454e80694 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_node_pool_test.go +++ b/tencentcloud/services/tke/resource_tc_kubernetes_node_pool_test.go @@ -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"), @@ -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"), @@ -382,6 +383,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" { extra_args = [ "root-dir=/var/lib/kubelet" ] + pre_start_user_script = "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg==" } } ` @@ -446,6 +448,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" { extra_args = [ "root-dir=/var/lib/kubelet" ] + pre_start_user_script = "IyEvYmluL3NoIGVjaG8gImhlbGxvIHdvcmxkIg==" } } ` @@ -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==" } } ` @@ -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 { diff --git a/website/docs/r/kubernetes_cluster_attachment.html.markdown b/website/docs/r/kubernetes_cluster_attachment.html.markdown index cade2e9d7b..285de6a14d 100644 --- a/website/docs/r/kubernetes_cluster_attachment.html.markdown +++ b/website/docs/r/kubernetes_cluster_attachment.html.markdown @@ -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: @@ -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 diff --git a/website/docs/r/kubernetes_node_pool.html.markdown b/website/docs/r/kubernetes_node_pool.html.markdown index d44b7183c6..f9f05f9a35 100644 --- a/website/docs/r/kubernetes_node_pool.html.markdown +++ b/website/docs/r/kubernetes_node_pool.html.markdown @@ -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: