diff --git a/.changelog/2764.txt b/.changelog/2764.txt new file mode 100644 index 0000000000..c21953370d --- /dev/null +++ b/.changelog/2764.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/tencentcloud_kubernetes_cluster_attachment: fix the issue that param `unschedulable` cannot work +``` diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go index e7dcba97e4..d846527f59 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go +++ b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go @@ -170,6 +170,7 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource { Optional: true, ForceNew: true, Default: true, + Deprecated: "This argument was deprecated, use `unschedulable` instead.", Description: "Indicate to schedule the adding node or not. Default is true.", }, "desired_pod_num": { @@ -234,6 +235,7 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + Deprecated: "This argument was no longer supported by TencentCloud TKE.", Description: "Mount target. Default is not mounting.", }, "docker_graph_path": { @@ -241,6 +243,7 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource { Optional: true, ForceNew: true, Default: "/var/lib/docker", + Deprecated: "This argument was no longer supported by TencentCloud TKE.", Description: "Docker graph path. Default is `/var/lib/docker`.", }, "data_disk": { @@ -300,6 +303,7 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource { Type: schema.TypeList, Optional: true, ForceNew: true, + Deprecated: "This argument was no longer supported by TencentCloud TKE.", Description: "Custom parameter information related to the node. This is a white-list parameter.", Elem: &schema.Schema{ Type: schema.TypeString, @@ -309,12 +313,14 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + Deprecated: "This argument was no longer supported by TencentCloud TKE.", Description: "Base64-encoded User Data text, the length limit is 16KB.", }, "pre_start_user_script": { Type: schema.TypeString, Optional: true, ForceNew: true, + Deprecated: "This argument was no longer supported by TencentCloud TKE.", Description: "Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.", }, "is_schedule": { @@ -322,6 +328,7 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource { Optional: true, ForceNew: true, Default: true, + Deprecated: "This argument was deprecated, use `unschedulable` instead.", Description: "Indicate to schedule the adding node or not. Default is true.", }, "desired_pod_num": { @@ -386,7 +393,7 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource { Optional: true, ForceNew: true, Default: 0, - Description: "Sets whether the joining node participates in the schedule. Default is '0'. Participate in scheduling.", + Description: "Sets whether the joining node participates in the schedule. Default is `0`, which means it participates in scheduling. Non-zero(eg: `1`) number means it does not participate in scheduling.", }, "security_groups": { @@ -496,9 +503,6 @@ func resourceTencentCloudKubernetesClusterAttachmentCreate(d *schema.ResourceDat } instanceAdvancedSettings.GPUArgs = &gPUArgs } - if v, ok := d.GetOkExists("unschedulable"); ok { - instanceAdvancedSettings.Unschedulable = helper.IntInt64(v.(int)) - } request.InstanceAdvancedSettings = &instanceAdvancedSettings } @@ -557,9 +561,6 @@ func resourceTencentCloudKubernetesClusterAttachmentCreate(d *schema.ResourceDat } instanceAdvancedSettings.GPUArgs = &gPUArgs2 } - if v, ok := d.GetOkExists("unschedulable"); ok { - instanceAdvancedSettings.Unschedulable = helper.IntInt64(v.(int)) - } request.InstanceAdvancedSettingsOverrides = append(request.InstanceAdvancedSettingsOverrides, &instanceAdvancedSettings) } } diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md index 842572027a..420a15b0b2 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md +++ b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md @@ -1,5 +1,7 @@ Provide a resource to attach an existing cvm to kubernetes cluster. +~> **NOTE:** Use `unschedulable` to set whether the join node participates in the schedule. The `is_schedule` of 'worker_config' and 'worker_config_overrides' was deprecated. + Example Usage ```hcl diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_extension.go b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_extension.go index b858b13b81..49627607c8 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_extension.go +++ b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_extension.go @@ -41,6 +41,9 @@ func resourceTencentCloudKubernetesClusterAttachmentCreatePostFillRequest0(ctx c return fmt.Errorf("parameters `key_ids` and `password` must set and only set one") } + if req.InstanceAdvancedSettings == nil { + req.InstanceAdvancedSettings = &tke.InstanceAdvancedSettings{} + } // labels req.InstanceAdvancedSettings = &tke.InstanceAdvancedSettings{} req.InstanceAdvancedSettings.Labels = GetTkeLabels(d, "labels") @@ -55,6 +58,11 @@ func resourceTencentCloudKubernetesClusterAttachmentCreatePostFillRequest0(ctx c } } + // only this unschedulable is valid, the is_schedule of worker_config and worker_config_overrides was deprecated. + if v, ok := d.GetOkExists("unschedulable"); ok { + req.InstanceAdvancedSettings.Unschedulable = helper.IntInt64(v.(int)) + } + // 检查是否已经绑定 if hasAttached, err := nodeHasAttachedToCluster(ctx, instanceId, *req.ClusterId); err != nil { return err diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_test.go b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_test.go index 05497c49bd..ef2ff9a36b 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_test.go +++ b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_test.go @@ -27,7 +27,18 @@ func TestAccTencentCloudKubernetesClusterAttachmentResource(t *testing.T) { testAccCheckTkeAttachExists("tencentcloud_kubernetes_cluster_attachment.test_attach"), resource.TestCheckResourceAttrSet("tencentcloud_kubernetes_cluster_attachment.test_attach", "cluster_id"), resource.TestCheckResourceAttrSet("tencentcloud_kubernetes_cluster_attachment.test_attach", "instance_id"), - resource.TestCheckResourceAttrSet("tencentcloud_kubernetes_cluster_attachment.test_attach", "unschedulable"), + resource.TestCheckResourceAttr("tencentcloud_kubernetes_cluster_attachment.test_attach", "unschedulable", "0"), + resource.TestCheckResourceAttr("tencentcloud_kubernetes_cluster_attachment.test_attach", "labels.test1", "test1"), + resource.TestCheckResourceAttr("tencentcloud_kubernetes_cluster_attachment.test_attach", "labels.test2", "test2"), + ), + }, + { + Config: testAccTkeAttachClusterUpdate(), + Check: resource.ComposeTestCheckFunc( + testAccCheckTkeAttachExists("tencentcloud_kubernetes_cluster_attachment.test_attach"), + resource.TestCheckResourceAttrSet("tencentcloud_kubernetes_cluster_attachment.test_attach", "cluster_id"), + resource.TestCheckResourceAttrSet("tencentcloud_kubernetes_cluster_attachment.test_attach", "instance_id"), + resource.TestCheckResourceAttr("tencentcloud_kubernetes_cluster_attachment.test_attach", "unschedulable", "1"), resource.TestCheckResourceAttr("tencentcloud_kubernetes_cluster_attachment.test_attach", "labels.test1", "test1"), resource.TestCheckResourceAttr("tencentcloud_kubernetes_cluster_attachment.test_attach", "labels.test2", "test2"), ), @@ -206,3 +217,58 @@ resource "tencentcloud_kubernetes_cluster_attachment" "test_attach" { } ` } + +func testAccTkeAttachClusterUpdate() string { + + return TkeNewDeps + ` +variable "cluster_cidr" { + default = "10.31.0.0/16" +} + +variable "availability_zone" { + default = "ap-guangzhou-3" +} + +data "tencentcloud_vpc_instances" "vpcs" { + name = "keep_tke_exclusive_vpc" +} + +resource "tencentcloud_kubernetes_cluster" "example" { + vpc_id = local.vpc_id + cluster_cidr = var.cluster_cidr + cluster_max_pod_num = 32 + cluster_name = "tf_example_cluster" + cluster_desc = "example for tke cluster" + cluster_max_service_num = 32 + cluster_internet = false # (can be ignored) open it after the nodes added + cluster_version = "1.22.5" + cluster_os = "tlinux2.2(tkernel3)x86_64" + cluster_deploy_type = "MANAGED_CLUSTER" + # without any worker config +} + +resource "tencentcloud_instance" "foo_attachment_new" { + instance_name = "tf-auto-test-1-2" + availability_zone = var.availability_zone + image_id = var.default_img_id + instance_type = local.final_type + system_disk_type = "CLOUD_PREMIUM" + system_disk_size = 50 + vpc_id = local.vpc_id + subnet_id = local.subnet_id1 +} + +resource "tencentcloud_kubernetes_cluster_attachment" "test_attach" { + cluster_id = tencentcloud_kubernetes_cluster.example.id + instance_id = tencentcloud_instance.foo_attachment_new.id + password = "Lo4wbdit" + unschedulable = 1 + + labels = { + "test1" = "test1", + "test2" = "test2", + } + +} +` +} diff --git a/website/docs/r/kubernetes_cluster_attachment.html.markdown b/website/docs/r/kubernetes_cluster_attachment.html.markdown index e6d6b67f34..d473cf3974 100644 --- a/website/docs/r/kubernetes_cluster_attachment.html.markdown +++ b/website/docs/r/kubernetes_cluster_attachment.html.markdown @@ -11,6 +11,8 @@ description: |- Provide a resource to attach an existing cvm to kubernetes cluster. +~> **NOTE:** Use `unschedulable` to set whether the join node participates in the schedule. The `is_schedule` of 'worker_config' and 'worker_config_overrides' was deprecated. + ## Example Usage ```hcl @@ -115,7 +117,7 @@ The following arguments are supported: * `key_ids` - (Optional, List: [`String`], ForceNew) The key pair to use for the instance, it looks like skey-16jig7tx, it should be set if `password` not set. * `labels` - (Optional, Map, ForceNew) Labels of tke attachment exits CVM. * `password` - (Optional, String, ForceNew) Password to access, should be set if `key_ids` not set. -* `unschedulable` - (Optional, Int, ForceNew) Sets whether the joining node participates in the schedule. Default is '0'. Participate in scheduling. +* `unschedulable` - (Optional, Int, ForceNew) Sets whether the joining node participates in the schedule. Default is `0`, which means it participates in scheduling. Non-zero(eg: `1`) number means it does not participate in scheduling. * `worker_config_overrides` - (Optional, List, ForceNew) Override variable worker_config, commonly used to attach existing instances. * `worker_config` - (Optional, List, ForceNew) Deploy the machine configuration information of the 'WORKER', commonly used to attach existing instances. @@ -157,13 +159,13 @@ The `worker_config_overrides` object supports the following: * `data_disk` - (Optional, List, ForceNew) Configurations of data disk. * `desired_pod_num` - (Optional, Int, ForceNew) Indicate to set desired pod number in node. valid when the cluster is podCIDR. -* `docker_graph_path` - (Optional, String, ForceNew) Docker graph path. Default is `/var/lib/docker`. -* `extra_args` - (Optional, List, ForceNew) Custom parameter information related to the node. This is a white-list parameter. +* `docker_graph_path` - (Optional, String, ForceNew, **Deprecated**) This argument was no longer supported by TencentCloud TKE. Docker graph path. Default is `/var/lib/docker`. +* `extra_args` - (Optional, List, ForceNew, **Deprecated**) This argument was no longer supported by TencentCloud TKE. Custom parameter information related to the node. This is a white-list parameter. * `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. +* `is_schedule` - (Optional, Bool, ForceNew, **Deprecated**) This argument was deprecated, use `unschedulable` instead. Indicate to schedule the adding node or not. Default is true. +* `mount_target` - (Optional, String, ForceNew, **Deprecated**) This argument was no longer supported by TencentCloud TKE. Mount target. Default is not mounting. +* `pre_start_user_script` - (Optional, String, ForceNew, **Deprecated**) This argument was no longer supported by TencentCloud TKE. Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes. +* `user_data` - (Optional, String, ForceNew, **Deprecated**) This argument was no longer supported by TencentCloud TKE. Base64-encoded User Data text, the length limit is 16KB. The `worker_config` object supports the following: @@ -172,7 +174,7 @@ The `worker_config` object supports the following: * `docker_graph_path` - (Optional, String, ForceNew) Docker graph path. Default is `/var/lib/docker`. * `extra_args` - (Optional, List, ForceNew) Custom parameter information related to the node. This is a white-list parameter. * `gpu_args` - (Optional, List, ForceNew) GPU driver parameters. -* `is_schedule` - (Optional, Bool, ForceNew) Indicate to schedule the adding node or not. Default is true. +* `is_schedule` - (Optional, Bool, ForceNew, **Deprecated**) This argument was deprecated, use `unschedulable` instead. 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.