Skip to content

Commit c37585c

Browse files
authored
feat(tke): [116385148]Fix the tags field of node pool created by tke (#2554)
* Fix the tags field of node pool created by tke * add changelog 2554.txt
1 parent b39bd75 commit c37585c

File tree

6 files changed

+227
-3
lines changed

6 files changed

+227
-3
lines changed

.changelog/2554.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_kubernetes_node_pool: Fix the problem of creating node pool tags field.
3+
```

tencentcloud/acctest/basic.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@ variable "tke_cidr_c" {
761761

762762
const TkeDefaultNodeInstanceVar = `
763763
variable "ins_type" {
764-
default = "SA2.LARGE8"
764+
//default = "SA2.LARGE8"
765+
default = "S2.MEDIUM2"
765766
}
766767
`
767768

tencentcloud/acctest/tke_basic.go

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
package acctest
2+
3+
const (
4+
TkeDefaultZone = "ap-guangzhou-3"
5+
TkeDefaultVpcCidr = "172.16.0.0/16"
6+
TkeDefaultSubnetCidr1 = "172.16.0.0/20"
7+
TkeDefaultSubnetCidr2 = "172.16.16.0/20"
8+
TkeDefaultImgId = "img-2lr9q49h"
9+
)
10+
11+
// todo tke cluster
12+
const TkeResourceKubernetesClusterTestCase = TkeResourceVpcTestCase + TkeResourceSecurityGroupTestCase + TkeDatasourceInstanceTypeTestCase + TkeDefaultVariable + `
13+
resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
14+
vpc_id = local.vpc_id
15+
cluster_cidr = var.tke_cidr_a.0
16+
cluster_max_pod_num = 32
17+
cluster_name = "` + DefaultTkeClusterName + `"
18+
cluster_desc = "test cluster desc"
19+
cluster_max_service_num = 32
20+
cluster_internet = true
21+
cluster_internet_domain = "tf.cluster-internet.com"
22+
cluster_intranet = true
23+
cluster_intranet_domain = "tf.cluster-intranet.com"
24+
cluster_version = "1.22.5"
25+
cluster_os = "tlinux2.2(tkernel3)x86_64"
26+
cluster_level = "L5"
27+
auto_upgrade_cluster_level = true
28+
cluster_intranet_subnet_id = local.subnet_id1
29+
cluster_internet_security_group = local.sg_id
30+
managed_cluster_internet_security_policies = ["3.3.3.3", "1.1.1.1"]
31+
worker_config {
32+
count = 1
33+
availability_zone = var.availability_zone
34+
instance_type = local.final_type
35+
system_disk_type = "CLOUD_SSD"
36+
system_disk_size = 60
37+
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
38+
internet_max_bandwidth_out = 100
39+
public_ip_assigned = true
40+
subnet_id = local.subnet_id1
41+
img_id = var.default_img_id
42+
security_group_ids = [local.sg_id]
43+
44+
data_disk {
45+
disk_type = "CLOUD_PREMIUM"
46+
disk_size = 50
47+
file_system = "ext3"
48+
auto_format_and_mount = "true"
49+
mount_target = "/var/lib/docker"
50+
disk_partition = "/dev/sdb1"
51+
}
52+
53+
enhanced_security_service = false
54+
enhanced_monitor_service = false
55+
user_data = "dGVzdA=="
56+
password = "ZZXXccvv1212"
57+
}
58+
59+
cluster_deploy_type = "MANAGED_CLUSTER"
60+
61+
tags = {
62+
"test" = "test"
63+
}
64+
65+
unschedulable = 0
66+
67+
labels = {
68+
"test1" = "test1",
69+
"test2" = "test2",
70+
}
71+
extra_args = [
72+
"root-dir=/var/lib/kubelet"
73+
]
74+
}
75+
`
76+
77+
// sg
78+
const TkeResourceSecurityGroupTestCase = DefaultInstanceVariable + `
79+
resource "tencentcloud_security_group" "example" {
80+
name = "tf_tke_sg_test"
81+
description = "sg test"
82+
}
83+
84+
locals {
85+
sg_id = tencentcloud_security_group.example.id
86+
sg_id2 = tencentcloud_security_group.example.id
87+
}
88+
`
89+
90+
//InstanceType
91+
const TkeDatasourceInstanceTypeTestCase = DefaultInstanceVariable + `
92+
data "tencentcloud_instance_types" "ins_type" {
93+
filter {
94+
name = "instance-family"
95+
values = ["S2"]
96+
}
97+
98+
cpu_core_count = 2
99+
memory_size = 2
100+
}
101+
102+
locals {
103+
type1 = [
104+
for i in data.tencentcloud_instance_types.ins_type.instance_types : i
105+
if lookup(i, "instance_charge_type") == "POSTPAID_BY_HOUR"
106+
]
107+
type2 = [for i in data.tencentcloud_instance_types.ins_type.instance_types : i]
108+
final_type = concat(local.type1, local.type2)[0].instance_type
109+
}
110+
`
111+
112+
// vpc
113+
const TkeResourceVpcTestCase = DefaultInstanceVariable + `
114+
resource "tencentcloud_vpc" "tke_vpc" {
115+
name = "tf_tke_vpc_test"
116+
cidr_block = var.vpc_cidr
117+
}
118+
119+
resource "tencentcloud_subnet" "tke_subnet1" {
120+
name = "tf_tke_subnet_test1"
121+
vpc_id = tencentcloud_vpc.vpc.id
122+
availability_zone = var.availability_zone
123+
cidr_block = var.subnet_cidr1
124+
is_multicast = false
125+
}
126+
127+
resource "tencentcloud_subnet" "tke_subnet2" {
128+
name = "tf_tke_subnet_test2"
129+
vpc_id = tencentcloud_vpc.vpc.id
130+
availability_zone = var.availability_zone
131+
cidr_block = var.subnet_cidr2
132+
is_multicast = false
133+
}
134+
135+
locals {
136+
vpc_id = tencentcloud_vpc.tke_vpc.id
137+
subnet_id1 = tencentcloud_subnet.tke_subnet1.id
138+
subnet_id2 = tencentcloud_subnet.tke_subnet2.id
139+
}
140+
`
141+
142+
const TkeDefaultVariable = `
143+
//variable "availability_zone" {
144+
// default = "` + TkeDefaultZone + `"
145+
//}
146+
147+
variable "vpc_cidr" {
148+
default = "` + TkeDefaultVpcCidr + `"
149+
}
150+
151+
variable "subnet_cidr1" {
152+
default = "` + TkeDefaultSubnetCidr1 + `"
153+
}
154+
155+
variable "subnet_cidr2" {
156+
default = "` + TkeDefaultSubnetCidr2 + `"
157+
}
158+
159+
variable "tke_cidr_a" {
160+
default = [
161+
"10.31.0.0/23",
162+
"10.31.2.0/24",
163+
"10.31.3.0/24",
164+
"10.31.16.0/24",
165+
"10.31.32.0/24"
166+
]
167+
}
168+
169+
variable "tke_cidr_b" {
170+
default = [
171+
"172.18.0.0/20",
172+
"172.18.16.0/21",
173+
"172.18.24.0/21",
174+
"172.18.32.0/20",
175+
"172.18.48.0/20"
176+
]
177+
}
178+
179+
variable "tke_cidr_c" {
180+
default = [
181+
"192.168.0.0/18",
182+
"192.168.64.0/19",
183+
"192.168.96.0/20",
184+
"192.168.112.0/21",
185+
"192.168.120.0/21"
186+
]
187+
}
188+
189+
variable "default_img_id" {
190+
default = "` + TkeDefaultImgId + `"
191+
}
192+
193+
variable "default_project" {
194+
default = ` + DefaultProjectId + `
195+
}
196+
197+
variable "default_img_id" {
198+
default = "` + DefaultTkeOSImageId + `"
199+
}
200+
201+
variable "default_img" {
202+
default = "` + DefaultTkeOSImageName + `"
203+
}
204+
`

tencentcloud/services/tke/resource_tc_kubernetes_node_pool.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,7 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
13261326

13271327
labels := GetTkeLabels(d, "labels")
13281328
taints := GetTkeTaints(d, "taints")
1329+
tags := GetTkeTags(d, "tags")
13291330

13301331
//compose InstanceAdvancedSettings
13311332
if workConfig, ok := helper.InterfacesHeadMap(d, "node_config"); ok {
@@ -1353,7 +1354,7 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
13531354

13541355
service := TkeService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
13551356

1356-
nodePoolId, err := service.CreateClusterNodePool(ctx, clusterId, name, groupParaStr, configParaStr, enableAutoScale, nodeOs, nodeOsType, labels, taints, iAdvanced, deletionProtection)
1357+
nodePoolId, err := service.CreateClusterNodePool(ctx, clusterId, name, groupParaStr, configParaStr, enableAutoScale, nodeOs, nodeOsType, labels, taints, iAdvanced, deletionProtection, tags)
13571358
if err != nil {
13581359
return err
13591360
}

tencentcloud/services/tke/resource_tc_kubernetes_node_pool_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
598598
spot_instance_type = "one-time"
599599
spot_max_price = "1000"
600600
cam_role_name = "TCB_QcsRole"
601+
601602
602603
data_disk {
603604
disk_type = "CLOUD_PREMIUM"

tencentcloud/services/tke/service_tencentcloud_tke.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,16 @@ func GetTkeTaints(d *schema.ResourceData, k string) []*tke.Taint {
14781478
return taints
14791479
}
14801480

1481+
func GetTkeTags(d *schema.ResourceData, k string) []*tke.Tag {
1482+
tags := make([]*tke.Tag, 0)
1483+
if raw, ok := d.GetOk(k); ok {
1484+
for k, v := range raw.(map[string]interface{}) {
1485+
tags = append(tags, &tke.Tag{Key: helper.String(k), Value: helper.String(v.(string))})
1486+
}
1487+
}
1488+
return tags
1489+
}
1490+
14811491
func (me *TkeService) ModifyClusterAsGroupAttribute(ctx context.Context, id, asGroupId string, maxSize, minSize int64) (errRet error) {
14821492

14831493
logId := tccommon.GetLogId(ctx)
@@ -1505,7 +1515,7 @@ func (me *TkeService) ModifyClusterAsGroupAttribute(ctx context.Context, id, asG
15051515
return
15061516
}
15071517

1508-
func (me *TkeService) CreateClusterNodePool(ctx context.Context, clusterId, name, groupPara, configPara string, enableAutoScale bool, nodeOs string, nodeOsType string, labels []*tke.Label, taints []*tke.Taint, iAdvanced tke.InstanceAdvancedSettings, deletionProtection bool) (asGroupId string, errRet error) {
1518+
func (me *TkeService) CreateClusterNodePool(ctx context.Context, clusterId, name, groupPara, configPara string, enableAutoScale bool, nodeOs string, nodeOsType string, labels []*tke.Label, taints []*tke.Taint, iAdvanced tke.InstanceAdvancedSettings, deletionProtection bool, tags []*tke.Tag) (asGroupId string, errRet error) {
15091519
logId := tccommon.GetLogId(ctx)
15101520
request := tke.NewCreateClusterNodePoolRequest()
15111521

@@ -1534,6 +1544,10 @@ func (me *TkeService) CreateClusterNodePool(ctx context.Context, clusterId, name
15341544
request.Taints = taints
15351545
}
15361546

1547+
if len(tags) > 0 {
1548+
request.Tags = tags
1549+
}
1550+
15371551
ratelimit.Check(request.GetAction())
15381552
response, err := me.client.UseTkeClient().CreateClusterNodePool(request)
15391553
if err != nil {

0 commit comments

Comments
 (0)