Skip to content

Commit 29b150c

Browse files
authored
feat(tke): [119910893] support taints and security_group for tencentcloud_kubernetes_cluster_attachment (#2866)
* feat(tke): [119910893] support taints for tencentcloud_kubernetes_cluster_attachment * add doc and changelog * support security group
1 parent b51ce05 commit 29b150c

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
lines changed

.changelog/2866.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_kubernetes_cluster_attachment: support param `taints` of worker_config
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_kubernetes_cluster_attachment: support param `security_groups`
7+
```

tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,34 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource {
165165
ForceNew: true,
166166
Description: "Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.",
167167
},
168+
"taints": {
169+
Type: schema.TypeList,
170+
Optional: true,
171+
ForceNew: true,
172+
Description: "Node taint.",
173+
Elem: &schema.Resource{
174+
Schema: map[string]*schema.Schema{
175+
"key": {
176+
Type: schema.TypeString,
177+
Optional: true,
178+
ForceNew: true,
179+
Description: "Key of the taint.",
180+
},
181+
"value": {
182+
Type: schema.TypeString,
183+
Optional: true,
184+
ForceNew: true,
185+
Description: "Value of the taint.",
186+
},
187+
"effect": {
188+
Type: schema.TypeString,
189+
Optional: true,
190+
ForceNew: true,
191+
Description: "Effect of the taint.",
192+
},
193+
},
194+
},
195+
},
168196
"is_schedule": {
169197
Type: schema.TypeBool,
170198
Optional: true,
@@ -397,8 +425,10 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource {
397425
},
398426

399427
"security_groups": {
400-
Type: schema.TypeSet,
428+
Type: schema.TypeList,
401429
Computed: true,
430+
Optional: true,
431+
ForceNew: true,
402432
Description: "A list of security group IDs after attach to cluster.",
403433
Elem: &schema.Schema{
404434
Type: schema.TypeString,
@@ -490,6 +520,22 @@ func resourceTencentCloudKubernetesClusterAttachmentCreate(d *schema.ResourceDat
490520
if v, ok := instanceAdvancedSettingsMap["pre_start_user_script"]; ok {
491521
instanceAdvancedSettings.PreStartUserScript = helper.String(v.(string))
492522
}
523+
if v, ok := instanceAdvancedSettingsMap["taints"]; ok {
524+
for _, item := range v.([]interface{}) {
525+
taintsMap := item.(map[string]interface{})
526+
taint := tke.Taint{}
527+
if v, ok := taintsMap["key"]; ok {
528+
taint.Key = helper.String(v.(string))
529+
}
530+
if v, ok := taintsMap["value"]; ok {
531+
taint.Value = helper.String(v.(string))
532+
}
533+
if v, ok := taintsMap["effect"]; ok {
534+
taint.Effect = helper.String(v.(string))
535+
}
536+
instanceAdvancedSettings.Taints = append(instanceAdvancedSettings.Taints, &taint)
537+
}
538+
}
493539
if v, ok := instanceAdvancedSettingsMap["docker_graph_path"]; ok {
494540
instanceAdvancedSettings.DockerGraphPath = helper.String(v.(string))
495541
}
@@ -510,6 +556,14 @@ func resourceTencentCloudKubernetesClusterAttachmentCreate(d *schema.ResourceDat
510556
request.HostName = helper.String(v.(string))
511557
}
512558

559+
if v, ok := d.GetOk("security_groups"); ok {
560+
securityGroupIdsSet := v.([]interface{})
561+
for i := range securityGroupIdsSet {
562+
securityGroupIds := securityGroupIdsSet[i].(string)
563+
request.SecurityGroupIds = append(request.SecurityGroupIds, helper.String(securityGroupIds))
564+
}
565+
}
566+
513567
if v, ok := d.GetOk("worker_config_overrides"); ok {
514568
for _, item := range v.([]interface{}) {
515569
instanceAdvancedSettingsOverridesMap := item.(map[string]interface{})

tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_extension.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func resourceTencentCloudKubernetesClusterAttachmentReadRequestOnError2(ctx cont
170170
}
171171

172172
func resourceTencentCloudKubernetesClusterAttachmentReadRequestOnSuccess2(ctx context.Context, resp *tke.Instance) *resource.RetryError {
173+
// d := tccommon.ResourceDataFromContext(ctx)
173174
if resp == nil {
174175
return nil
175176
}
@@ -196,6 +197,33 @@ func resourceTencentCloudKubernetesClusterAttachmentReadRequestOnSuccess2(ctx co
196197
))
197198
}
198199

200+
// api cannot return Taints
201+
// if resp.InstanceAdvancedSettings.Taints != nil {
202+
// iAdvanced := resp.InstanceAdvancedSettings
203+
// taintsList := make([]map[string]interface{}, 0, len(iAdvanced.Taints))
204+
// if iAdvanced.Taints != nil {
205+
// for _, taints := range iAdvanced.Taints {
206+
// taintsMap := map[string]interface{}{}
207+
208+
// if taints.Key != nil {
209+
// taintsMap["key"] = taints.Key
210+
// }
211+
212+
// if taints.Value != nil {
213+
// taintsMap["value"] = taints.Value
214+
// }
215+
216+
// if taints.Effect != nil {
217+
// taintsMap["effect"] = taints.Effect
218+
// }
219+
220+
// taintsList = append(taintsList, taintsMap)
221+
// }
222+
223+
// _ = d.Set("taints", taintsList)
224+
// }
225+
// }
226+
199227
return nil
200228
}
201229

website/docs/r/kubernetes_cluster_attachment.html.markdown

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ The following arguments are supported:
117117
* `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.
118118
* `labels` - (Optional, Map, ForceNew) Labels of tke attachment exits CVM.
119119
* `password` - (Optional, String, ForceNew) Password to access, should be set if `key_ids` not set.
120+
* `security_groups` - (Optional, List: [`String`], ForceNew) A list of security group IDs after attach to cluster.
120121
* `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.
121122
* `worker_config_overrides` - (Optional, List, ForceNew) Override variable worker_config, commonly used to attach existing instances.
122123
* `worker_config` - (Optional, List, ForceNew) Deploy the machine configuration information of the 'WORKER', commonly used to attach existing instances.
@@ -155,6 +156,12 @@ The `gpu_args` object of `worker_config` supports the following:
155156
* `driver` - (Optional, Map) GPU driver version. Format like: `{ version: String, name: String }`. `version`: Version of GPU driver or CUDA; `name`: Name of GPU driver or CUDA.
156157
* `mig_enable` - (Optional, Bool) Whether to enable MIG.
157158

159+
The `taints` object of `worker_config` supports the following:
160+
161+
* `effect` - (Optional, String, ForceNew) Effect of the taint.
162+
* `key` - (Optional, String, ForceNew) Key of the taint.
163+
* `value` - (Optional, String, ForceNew) Value of the taint.
164+
158165
The `worker_config_overrides` object supports the following:
159166

160167
* `data_disk` - (Optional, List, ForceNew) Configurations of data disk.
@@ -177,14 +184,14 @@ The `worker_config` object supports the following:
177184
* `is_schedule` - (Optional, Bool, ForceNew, **Deprecated**) This argument was deprecated, use `unschedulable` instead. Indicate to schedule the adding node or not. Default is true.
178185
* `mount_target` - (Optional, String, ForceNew) Mount target. Default is not mounting.
179186
* `pre_start_user_script` - (Optional, String, ForceNew) Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.
187+
* `taints` - (Optional, List, ForceNew) Node taint.
180188
* `user_data` - (Optional, String, ForceNew) Base64-encoded User Data text, the length limit is 16KB.
181189

182190
## Attributes Reference
183191

184192
In addition to all arguments above, the following attributes are exported:
185193

186194
* `id` - ID of the resource.
187-
* `security_groups` - A list of security group IDs after attach to cluster.
188195
* `state` - State of the node.
189196

190197

0 commit comments

Comments
 (0)