From f2551d367c30eaa985db26c1d060a2f9354e5db7 Mon Sep 17 00:00:00 2001 From: nickyinluo Date: Thu, 24 Oct 2024 11:38:05 +0800 Subject: [PATCH 1/2] feat(tke): [120040332]: support annotations field --- .../tke/resource_tc_kubernetes_node_pool.go | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go b/tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go index 2aca906f9e..bfb7a74d37 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go +++ b/tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go @@ -533,6 +533,27 @@ func ResourceTencentCloudKubernetesNodePool() *schema.Resource { Description: "Indicates whether the node pool deletion protection is enabled.", }, + "annotations": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Description: "Node Annotation List.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name in the map table.", + }, + "value": { + Type: schema.TypeString, + Required: true, + Description: "Value in the map table.", + }, + }, + }, + }, + "node_os": { Type: schema.TypeString, Optional: true, @@ -687,6 +708,20 @@ func resourceTencentCloudKubernetesNodePoolCreate(d *schema.ResourceData, meta i request.DeletionProtection = helper.Bool(v.(bool)) } + if v, ok := d.GetOk("annotations"); ok { + for _, item := range v.(*schema.Set).List() { + annotationsMap := item.(map[string]interface{}) + annotationValue := tkev20180525.AnnotationValue{} + if v, ok := annotationsMap["name"]; ok { + annotationValue.Name = helper.String(v.(string)) + } + if v, ok := annotationsMap["value"]; ok { + annotationValue.Value = helper.String(v.(string)) + } + request.Annotations = append(request.Annotations, &annotationValue) + } + } + if err := resourceTencentCloudKubernetesNodePoolCreatePostFillRequest0(ctx, request); err != nil { return err } @@ -844,6 +879,25 @@ func resourceTencentCloudKubernetesNodePoolRead(d *schema.ResourceData, meta int _ = d.Set("deletion_protection", respData1.DeletionProtection) } + annotationsList := make([]map[string]interface{}, 0, len(respData1.Annotations)) + if respData1.Annotations != nil { + for _, annotations := range respData1.Annotations { + annotationsMap := map[string]interface{}{} + + if annotations.Name != nil { + annotationsMap["name"] = annotations.Name + } + + if annotations.Value != nil { + annotationsMap["value"] = annotations.Value + } + + annotationsList = append(annotationsList, annotationsMap) + } + + _ = d.Set("annotations", annotationsList) + } + if err := resourceTencentCloudKubernetesNodePoolReadPostHandleResponse1(ctx, respData1); err != nil { return err } @@ -871,7 +925,7 @@ func resourceTencentCloudKubernetesNodePoolUpdate(d *schema.ResourceData, meta i } needChange := false - mutableArgs := []string{"name", "max_size", "min_size", "taints", "enable_auto_scale", "deletion_protection"} + mutableArgs := []string{"name", "max_size", "min_size", "enable_auto_scale", "deletion_protection", "annotations"} for _, v := range mutableArgs { if d.HasChange(v) { needChange = true @@ -906,6 +960,20 @@ func resourceTencentCloudKubernetesNodePoolUpdate(d *schema.ResourceData, meta i request.DeletionProtection = helper.Bool(v.(bool)) } + if v, ok := d.GetOk("annotations"); ok { + for _, item := range v.(*schema.Set).List() { + annotationsMap := item.(map[string]interface{}) + annotationValue := tkev20180525.AnnotationValue{} + if v, ok := annotationsMap["name"]; ok { + annotationValue.Name = helper.String(v.(string)) + } + if v, ok := annotationsMap["value"]; ok { + annotationValue.Value = helper.String(v.(string)) + } + request.Annotations = append(request.Annotations, &annotationValue) + } + } + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTkeV20180525Client().ModifyClusterNodePoolWithContext(ctx, request) if e != nil { From b2e7e15d088224e005f8850895db82ce21717459 Mon Sep 17 00:00:00 2001 From: nickyinluo Date: Thu, 24 Oct 2024 14:59:27 +0800 Subject: [PATCH 2/2] add changelog and doc --- .changelog/2909.txt | 3 +++ website/docs/r/kubernetes_node_pool.html.markdown | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 .changelog/2909.txt diff --git a/.changelog/2909.txt b/.changelog/2909.txt new file mode 100644 index 0000000000..c9701fa99e --- /dev/null +++ b/.changelog/2909.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_kubernetes_node_pool: support `annotations` field +``` \ No newline at end of file diff --git a/website/docs/r/kubernetes_node_pool.html.markdown b/website/docs/r/kubernetes_node_pool.html.markdown index 0e7c45e7d3..5ace797ad4 100644 --- a/website/docs/r/kubernetes_node_pool.html.markdown +++ b/website/docs/r/kubernetes_node_pool.html.markdown @@ -163,6 +163,7 @@ The following arguments are supported: * `min_size` - (Required, Int) Minimum number of node. * `name` - (Required, String) Name of the node pool. The name does not exceed 25 characters, and only supports Chinese, English, numbers, underscores, separators (`-`) and decimal points. * `vpc_id` - (Required, String, ForceNew) ID of VPC network. +* `annotations` - (Optional, Set) Node Annotation List. * `default_cooldown` - (Optional, Int) Seconds of scaling group cool down. Default value is `300`. * `delete_keep_instance` - (Optional, Bool) Indicate to keep the CVM instance when delete the node pool. Default is `true`. * `deletion_protection` - (Optional, Bool) Indicates whether the node pool deletion protection is enabled. @@ -184,6 +185,11 @@ The following arguments are supported: * `unschedulable` - (Optional, Int, ForceNew) Sets whether the joining node participates in the schedule. Default is '0'. Participate in scheduling. * `zones` - (Optional, List: [`String`]) List of auto scaling group available zones, for Basic network it is required. +The `annotations` object supports the following: + +* `name` - (Required, String) Name in the map table. +* `value` - (Required, String) Value in the map table. + The `auto_scaling_config` object supports the following: * `instance_type` - (Required, String, ForceNew) Specified types of CVM instance.