Skip to content

fix(tke): [118694498] fix unschedulable cannot work. #2764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2764.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/tencentcloud_kubernetes_cluster_attachment: fix the issue that param `unschedulable` cannot work
```
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -234,13 +235,15 @@ 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": {
Type: schema.TypeString,
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": {
Expand Down Expand Up @@ -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,
Expand All @@ -309,19 +313,22 @@ 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": {
Type: schema.TypeBool,
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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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",
}
}
`
}
18 changes: 10 additions & 8 deletions website/docs/r/kubernetes_cluster_attachment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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:

Expand All @@ -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.
Expand Down
Loading