Skip to content

Commit bd00ea6

Browse files
authored
Merge pull request #627 from rostachen/master
tke add desired_pod_num and update cluster_os; as update heartbeat_timeout
2 parents 415a6e4 + a932beb commit bd00ea6

32 files changed

+1534
-72
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
## 1.56.8 (Unreleased)
1+
## 1.56.9 (Unreleased)
2+
## 1.56.8 (May 26, 2021)
3+
4+
ENHANCEMENTS:
5+
6+
* Resource `tencentcloud_kubernetes_cluster_attachment.worker_config` add `desired_pod_num`.
7+
* Resource `tencentcloud_kubernetes_cluster_attachment` add `worker_config_overrides`.
8+
* Resource `tencentcloud_kubernetes_scale_worker` add `desired_pod_num`.
9+
* Resource `tencentcloud_kubernetes_cluster` add `enable_customized_pod_cidr`, `base_pod_num`, `globe_desired_pod_num`, and `exist_instance`.
10+
* Resource `tencentcloud_kubernetes_cluster` update available value of `cluster_os`.
11+
* Resource `tencentcloud_as_lifecycle_hook` update `heartbeat_timeout` value ranges.
12+
213
## 1.56.7 (May 12, 2021)
314

415
ENHANCEMENTS:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/mattn/go-colorable v0.1.6 // indirect
1616
github.com/mitchellh/go-homedir v1.1.0
1717
github.com/pkg/errors v0.9.1
18-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.155
18+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.165
1919
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
2020
github.com/zclconf/go-cty v1.4.2 // indirect
2121
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
441441
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
442442
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0KQWXKNqmwe8vEeSUiUj4Rlee9CMVX2ZUQ=
443443
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
444-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.155 h1:jFyQ7gV9e3HD4yRqTpN6P3+bZwqlYaAhkb87gTc2zT4=
445-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.155/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
444+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.165 h1:d9L8aoQ781XBO8pnE9EvFm64ptfBVMqVNcKQ2MS+TUM=
445+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.165/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
446446
github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8=
447447
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
448448
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=

tencentcloud/extension_tke.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ package tencentcloud
22

33
const (
44
TKE_CLUSTER_OS_CENTOS72 = "centos7.2x86_64"
5-
TKE_CLUSTER_OS_CENTOS76 = "centos7.6x86_64"
6-
TKE_CLUSTER_OS_UBUNTU16 = "ubuntu16.04.1 LTSx86_64"
7-
TKE_CLUSTER_OS_UBUNTU18 = "ubuntu18.04.1 LTSx86_64"
5+
TKE_CLUSTER_OS_CENTOS76 = "centos7.6.0_x64"
6+
TKE_CLUSTER_OS_UBUNTU18 = "ubuntu18.04.1x86_64"
87
TKE_CLUSTER_OS_LINUX24 = "tlinux2.4x86_64"
98
TKE_CLUSTER_OS_LINUX22 = "tlinux2.2(tkernel3)x86_64"
109
TKE_CLUSTER_OS_LINUXF22 = "Tencent tlinux release 2.2 (Final)"
1110
)
1211

13-
var TKE_CLUSTER_OS = []string{TKE_CLUSTER_OS_CENTOS72, TKE_CLUSTER_OS_CENTOS76, TKE_CLUSTER_OS_UBUNTU16, TKE_CLUSTER_OS_UBUNTU18, TKE_CLUSTER_OS_LINUX24}
12+
var TKE_CLUSTER_OS = []string{TKE_CLUSTER_OS_CENTOS76, TKE_CLUSTER_OS_UBUNTU18, TKE_CLUSTER_OS_LINUX24}
1413

1514
var tkeClusterOsMap = map[string]string{TKE_CLUSTER_OS_CENTOS72: TKE_CLUSTER_OS_CENTOS72,
16-
TKE_CLUSTER_OS_CENTOS76: "centos7.6.0_x64",
17-
TKE_CLUSTER_OS_UBUNTU16: TKE_CLUSTER_OS_UBUNTU16,
18-
TKE_CLUSTER_OS_UBUNTU18: "ubuntu18.04.1x86_64",
19-
TKE_CLUSTER_OS_LINUX24: "tlinux2.4x86_64",
15+
TKE_CLUSTER_OS_CENTOS76: TKE_CLUSTER_OS_CENTOS76,
16+
TKE_CLUSTER_OS_UBUNTU18: TKE_CLUSTER_OS_UBUNTU18,
17+
TKE_CLUSTER_OS_LINUX24: TKE_CLUSTER_OS_LINUX24,
2018
TKE_CLUSTER_OS_LINUX22: TKE_CLUSTER_OS_LINUX22,
2119
TKE_CLUSTER_OS_LINUXF22: TKE_CLUSTER_OS_LINUXF22,
2220
}

tencentcloud/resource_tc_as_lifecycle_hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func resourceTencentCloudAsLifecycleHook() *schema.Resource {
6565
Type: schema.TypeInt,
6666
Optional: true,
6767
Default: 300,
68-
ValidateFunc: validateIntegerInRange(30, 3600),
69-
Description: "Defines the amount of time, in seconds, that can elapse before the lifecycle hook times out. Valid value ranges: (30~3600). and default value is `300`.",
68+
ValidateFunc: validateIntegerInRange(30, 7200),
69+
Description: "Defines the amount of time, in seconds, that can elapse before the lifecycle hook times out. Valid value ranges: (30~7200). and default value is `300`.",
7070
},
7171
"notification_metadata": {
7272
Type: schema.TypeString,

tencentcloud/resource_tc_container_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func resourceTencentCloudContainerClusterCreate(d *schema.ResourceData, meta int
449449
runInstancesParas := runInstancesPara.ToJsonString()
450450
cvms.Work = []string{runInstancesParas}
451451

452-
id, err := service.CreateCluster(ctx, basic, cAdvanced, cvms, iAdvanced, cidrSet, map[string]string{})
452+
id, err := service.CreateCluster(ctx, basic, cAdvanced, cvms, iAdvanced, cidrSet, map[string]string{}, nil, nil)
453453
if err != nil {
454454
return err
455455
}

tencentcloud/resource_tc_kubernetes_cluster.go

Lines changed: 147 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,56 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
549549
Elem: &schema.Schema{Type: schema.TypeString},
550550
Description: "Disaster recover groups to which a CVM instance belongs. Only support maximum 1.",
551551
},
552+
// InstanceAdvancedSettingsOverrides
553+
"desired_pod_num": {
554+
Type: schema.TypeInt,
555+
ForceNew: true,
556+
Optional: true,
557+
Default: -1,
558+
Description: "Indicate to set desired pod number in node. valid when enable_customized_pod_cidr=true, " +
559+
"and it override `[globe_]desired_pod_num` for current node. Either all the fields `desired_pod_num` or none.",
560+
},
561+
}
562+
}
563+
564+
func TkeExistCvmCreateInfo() map[string]*schema.Schema {
565+
return map[string]*schema.Schema{
566+
"node_role": {
567+
Type: schema.TypeString,
568+
ForceNew: true,
569+
Optional: true,
570+
ValidateFunc: validateAllowedStringValue([]string{TKE_ROLE_WORKER, TKE_ROLE_MASTER_ETCD}),
571+
Description: "Role of existed node. value:MASTER_ETCD or WORKER.",
572+
},
573+
"instances_para": {
574+
Type: schema.TypeList,
575+
ForceNew: true,
576+
Optional: true,
577+
MaxItems: 1,
578+
Elem: &schema.Resource{
579+
Schema: map[string]*schema.Schema{
580+
"instance_ids": {
581+
Type: schema.TypeList,
582+
ForceNew: true,
583+
Required: true,
584+
Elem: &schema.Schema{Type: schema.TypeString},
585+
Description: "Cluster IDs.",
586+
},
587+
},
588+
},
589+
Description: "Reinstallation parameters of an existing instance.",
590+
},
591+
"desired_pod_numbers": {
592+
Type: schema.TypeList,
593+
Optional: true,
594+
ForceNew: true,
595+
Elem: &schema.Schema{Type: schema.TypeInt},
596+
Description: "Custom mode cluster, you can specify the number of pods for each node. corresponding to the existed_instances_para.instance_ids parameter.",
597+
},
552598
}
553599
}
554600

601+
555602
func TkeNodePoolGlobalConfig() map[string]*schema.Schema {
556603
return map[string]*schema.Schema{
557604
"is_scale_in_enabled": {
@@ -627,9 +674,9 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
627674
Type: schema.TypeString,
628675
ForceNew: true,
629676
Optional: true,
630-
Default: TKE_CLUSTER_OS_UBUNTU16,
677+
Default: TKE_CLUSTER_OS_LINUX24,
631678
Description: "Operating system of the cluster, the available values include: '" + strings.Join(TKE_CLUSTER_OS, "','") +
632-
"'. Default is '" + TKE_CLUSTER_OS_UBUNTU16 + "'.",
679+
"'. Default is '" + TKE_CLUSTER_OS_LINUX24 + "'.",
633680
},
634681
"cluster_os_type": {
635682
Type: schema.TypeString,
@@ -739,6 +786,19 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
739786
ValidateFunc: validateAllowedStringValue(TKE_CLUSTER_NETWORK_TYPE),
740787
Description: "Cluster network type, GR or VPC-CNI. Default is GR.",
741788
},
789+
"enable_customized_pod_cidr": {
790+
Type: schema.TypeBool,
791+
ForceNew: true,
792+
Optional: true,
793+
Default: false,
794+
Description: "Whether to enable the custom mode of node podCIDR size. Default is false.",
795+
},
796+
"base_pod_num": {
797+
Type: schema.TypeInt,
798+
ForceNew: true,
799+
Optional: true,
800+
Description: "The number of basic pods. valid when enable_customized_pod_cidr=true.",
801+
},
742802
"is_non_static_ip_mode": {
743803
Type: schema.TypeBool,
744804
ForceNew: true,
@@ -958,6 +1018,15 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
9581018
},
9591019
Description: "Deploy the machine configuration information of the 'WORKER' service, and create <=20 units for common users. The other 'WORK' service are added by 'tencentcloud_kubernetes_worker'.",
9601020
},
1021+
"exist_instance": {
1022+
Type: schema.TypeList,
1023+
ForceNew: true,
1024+
Optional: true,
1025+
Elem: &schema.Resource{
1026+
Schema: TkeExistCvmCreateInfo(),
1027+
},
1028+
Description: "create tke cluster by existed instances.",
1029+
},
9611030
"tags": {
9621031
Type: schema.TypeMap,
9631032
Optional: true,
@@ -1005,6 +1074,12 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
10051074
ForceNew: true,
10061075
Description: "Mount target. Default is not mounting.",
10071076
},
1077+
"globe_desired_pod_num": {
1078+
Type: schema.TypeInt,
1079+
ForceNew: true,
1080+
Optional: true,
1081+
Description: "Indicate to set desired pod number in node. valid when enable_customized_pod_cidr=true, and it takes effect for all nodes.",
1082+
},
10081083
"docker_graph_path": {
10091084
Type: schema.TypeString,
10101085
Optional: true,
@@ -1269,6 +1344,37 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
12691344
return
12701345
}
12711346

1347+
func tkeGetCvmExistInstancesPara(dMap map[string]interface{}) (tke.ExistedInstancesForNode, error) {
1348+
1349+
inst := tke.ExistedInstancesForNode{}
1350+
1351+
if temp, ok := dMap["instances_para"]; ok {
1352+
paras := temp.([]interface{})
1353+
if len(paras) > 0 {
1354+
paraMap := paras[0].(map[string]interface{})
1355+
instanceIds := paraMap["instance_ids"].([]interface{})
1356+
inst.ExistedInstancesPara = &tke.ExistedInstancesPara{}
1357+
inst.ExistedInstancesPara.InstanceIds = make([]*string, 0)
1358+
for _, v := range instanceIds {
1359+
inst.ExistedInstancesPara.InstanceIds = append(inst.ExistedInstancesPara.InstanceIds, helper.String(v.(string)))
1360+
}
1361+
}
1362+
}
1363+
if temp, ok := dMap["desired_pod_numbers"]; ok {
1364+
inst.DesiredPodNumbers = make([]*int64, 0)
1365+
podNums := temp.([]interface{})
1366+
for _, v := range podNums {
1367+
inst.DesiredPodNumbers = append(inst.DesiredPodNumbers, helper.Int64(int64(v.(int))))
1368+
}
1369+
}
1370+
if temp, ok := dMap["node_role"]; ok {
1371+
nodeRole := temp.(string)
1372+
inst.NodeRole = &nodeRole
1373+
}
1374+
1375+
return inst, nil
1376+
}
1377+
12721378
func tkeGetNodePoolGlobalConfig(d *schema.ResourceData) *tke.ModifyClusterAsGroupOptionAttributeRequest {
12731379
request := tke.NewModifyClusterAsGroupOptionAttributeRequest()
12741380
request.ClusterId = helper.String(d.Id())
@@ -1424,12 +1530,6 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
14241530

14251531
basic.ClusterOsType = d.Get("cluster_os_type").(string)
14261532

1427-
if basic.ClusterOsType == TKE_CLUSTER_OS_TYPE_DOCKER_CUSTOMIZE {
1428-
if cluster_os != TKE_CLUSTER_OS_UBUNTU18 && cluster_os != TKE_CLUSTER_OS_CENTOS76 {
1429-
return fmt.Errorf("Only 'centos7.6x86_64' or 'ubuntu18.04.1 LTSx86_64' support 'DOCKER_CUSTOMIZE' now, can not be " + basic.ClusterOs)
1430-
}
1431-
}
1432-
14331533
basic.ClusterVersion = d.Get("cluster_version").(string)
14341534
if v, ok := d.GetOk("cluster_name"); ok {
14351535
basic.ClusterName = v.(string)
@@ -1446,6 +1546,10 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
14461546
advanced.IsNonStaticIpMode = d.Get("is_non_static_ip_mode").(bool)
14471547
advanced.DeletionProtection = d.Get("deletion_protection").(bool)
14481548
advanced.KubeProxyMode = d.Get("kube_proxy_mode").(string)
1549+
advanced.EnableCustomizedPodCIDR = d.Get("enable_customized_pod_cidr").(bool)
1550+
if v, ok := d.GetOk("base_pod_num"); ok {
1551+
advanced.BasePodNumber = int64(v.(int))
1552+
}
14491553

14501554
if extraArgs, ok := d.GetOk("cluster_extra_args"); ok {
14511555
extraArgList := extraArgs.([]interface{})
@@ -1509,6 +1613,7 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15091613
}
15101614
}
15111615

1616+
overrideSettings := make([]tke.InstanceAdvancedSettings, 0)
15121617
if masters, ok := d.GetOk("master_config"); ok {
15131618
if clusterDeployType == TKE_DEPLOY_TYPE_MANAGED {
15141619
return fmt.Errorf("if `cluster_deploy_type` is `MANAGED_CLUSTER` , You don't need define the master yourself")
@@ -1524,6 +1629,13 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15241629

15251630
cvms.Master = append(cvms.Master, paraJson)
15261631
masterCount += count
1632+
1633+
if v, ok := master["desired_pod_num"]; ok {
1634+
dpNum := int64(v.(int))
1635+
if dpNum != -1 {
1636+
overrideSettings = append(overrideSettings, tke.InstanceAdvancedSettings{DesiredPodNumber: helper.Int64(dpNum)})
1637+
}
1638+
}
15271639
}
15281640
if masterCount < 3 {
15291641
return fmt.Errorf("if `cluster_deploy_type` is `TKE_DEPLOY_TYPE_INDEPENDENT` len(master_config) should >=3")
@@ -1540,11 +1652,17 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15401652
for index := range workerList {
15411653
worker := workerList[index].(map[string]interface{})
15421654
paraJson, _, err := tkeGetCvmRunInstancesPara(worker, meta, vpcId, basic.ProjectId)
1543-
15441655
if err != nil {
15451656
return err
15461657
}
15471658
cvms.Work = append(cvms.Work, paraJson)
1659+
1660+
if v, ok := worker["desired_pod_num"]; ok {
1661+
dpNum := int64(v.(int))
1662+
if dpNum != -1 {
1663+
overrideSettings = append(overrideSettings, tke.InstanceAdvancedSettings{DesiredPodNumber: helper.Int64(dpNum)})
1664+
}
1665+
}
15481666
}
15491667
}
15501668

@@ -1567,10 +1685,28 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15671685
if temp, ok := d.GetOk("mount_target"); ok {
15681686
iAdvanced.MountTarget = temp.(string)
15691687
}
1688+
if temp, ok := d.GetOk("globe_desired_pod_num"); ok {
1689+
iAdvanced.DesiredPodNum = int64(temp.(int))
1690+
}
15701691

1571-
service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
1692+
// ExistedInstancesForNode
1693+
existIntances := make([]*tke.ExistedInstancesForNode, 0)
1694+
if instances, ok := d.GetOk("exist_instance"); ok {
1695+
instanceList := instances.([]interface{})
1696+
for index := range instanceList {
1697+
instance := instanceList[index].(map[string]interface{})
1698+
existedInstance, _ := tkeGetCvmExistInstancesPara(instance)
1699+
existIntances = append(existIntances, &existedInstance)
1700+
}
1701+
}
1702+
1703+
// RunInstancesForNode(master_config+worker_config) 和 ExistedInstancesForNode 不能同时存在
1704+
if len(cvms.Master)+len(cvms.Work) > 0 && len(existIntances) > 0 {
1705+
return fmt.Errorf("master_config+worker_config and exist_instance can not exist at the same time")
1706+
}
15721707

1573-
id, err := service.CreateCluster(ctx, basic, advanced, cvms, iAdvanced, cidrSet, tags)
1708+
service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
1709+
id, err := service.CreateCluster(ctx, basic, advanced, cvms, iAdvanced, cidrSet, tags, existIntances, overrideSettings)
15741710
if err != nil {
15751711
return err
15761712
}

0 commit comments

Comments
 (0)