Skip to content

tke add desired_pod_num and update cluster_os; as update heartbeat_timeout #627

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 1 commit into from
May 26, 2021
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
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## 1.56.8 (Unreleased)
## 1.56.9 (Unreleased)
## 1.56.8 (May 26, 2021)

ENHANCEMENTS:

* Resource `tencentcloud_kubernetes_cluster_attachment.worker_config` add `desired_pod_num`.
* Resource `tencentcloud_kubernetes_cluster_attachment` add `worker_config_overrides`.
* Resource `tencentcloud_kubernetes_scale_worker` add `desired_pod_num`.
* Resource `tencentcloud_kubernetes_cluster` add `enable_customized_pod_cidr`, `base_pod_num`, `globe_desired_pod_num`, and `exist_instance`.
* Resource `tencentcloud_kubernetes_cluster` update available value of `cluster_os`.
* Resource `tencentcloud_as_lifecycle_hook` update `heartbeat_timeout` value ranges.

## 1.56.7 (May 12, 2021)

ENHANCEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/tencentcloud/tencentcloud-sdk-go v1.0.155
github.com/tencentcloud/tencentcloud-sdk-go v1.0.165
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
github.com/zclconf/go-cty v1.4.2 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0KQWXKNqmwe8vEeSUiUj4Rlee9CMVX2ZUQ=
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
github.com/tencentcloud/tencentcloud-sdk-go v1.0.155 h1:jFyQ7gV9e3HD4yRqTpN6P3+bZwqlYaAhkb87gTc2zT4=
github.com/tencentcloud/tencentcloud-sdk-go v1.0.155/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
github.com/tencentcloud/tencentcloud-sdk-go v1.0.165 h1:d9L8aoQ781XBO8pnE9EvFm64ptfBVMqVNcKQ2MS+TUM=
github.com/tencentcloud/tencentcloud-sdk-go v1.0.165/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8=
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=
Expand Down
14 changes: 6 additions & 8 deletions tencentcloud/extension_tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ package tencentcloud

const (
TKE_CLUSTER_OS_CENTOS72 = "centos7.2x86_64"
TKE_CLUSTER_OS_CENTOS76 = "centos7.6x86_64"
TKE_CLUSTER_OS_UBUNTU16 = "ubuntu16.04.1 LTSx86_64"
TKE_CLUSTER_OS_UBUNTU18 = "ubuntu18.04.1 LTSx86_64"
TKE_CLUSTER_OS_CENTOS76 = "centos7.6.0_x64"
TKE_CLUSTER_OS_UBUNTU18 = "ubuntu18.04.1x86_64"
TKE_CLUSTER_OS_LINUX24 = "tlinux2.4x86_64"
TKE_CLUSTER_OS_LINUX22 = "tlinux2.2(tkernel3)x86_64"
TKE_CLUSTER_OS_LINUXF22 = "Tencent tlinux release 2.2 (Final)"
)

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}
var TKE_CLUSTER_OS = []string{TKE_CLUSTER_OS_CENTOS76, TKE_CLUSTER_OS_UBUNTU18, TKE_CLUSTER_OS_LINUX24}

var tkeClusterOsMap = map[string]string{TKE_CLUSTER_OS_CENTOS72: TKE_CLUSTER_OS_CENTOS72,
TKE_CLUSTER_OS_CENTOS76: "centos7.6.0_x64",
TKE_CLUSTER_OS_UBUNTU16: TKE_CLUSTER_OS_UBUNTU16,
TKE_CLUSTER_OS_UBUNTU18: "ubuntu18.04.1x86_64",
TKE_CLUSTER_OS_LINUX24: "tlinux2.4x86_64",
TKE_CLUSTER_OS_CENTOS76: TKE_CLUSTER_OS_CENTOS76,
TKE_CLUSTER_OS_UBUNTU18: TKE_CLUSTER_OS_UBUNTU18,
TKE_CLUSTER_OS_LINUX24: TKE_CLUSTER_OS_LINUX24,
TKE_CLUSTER_OS_LINUX22: TKE_CLUSTER_OS_LINUX22,
TKE_CLUSTER_OS_LINUXF22: TKE_CLUSTER_OS_LINUXF22,
}
Expand Down
4 changes: 2 additions & 2 deletions tencentcloud/resource_tc_as_lifecycle_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func resourceTencentCloudAsLifecycleHook() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
Default: 300,
ValidateFunc: validateIntegerInRange(30, 3600),
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`.",
ValidateFunc: validateIntegerInRange(30, 7200),
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`.",
},
"notification_metadata": {
Type: schema.TypeString,
Expand Down
2 changes: 1 addition & 1 deletion tencentcloud/resource_tc_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func resourceTencentCloudContainerClusterCreate(d *schema.ResourceData, meta int
runInstancesParas := runInstancesPara.ToJsonString()
cvms.Work = []string{runInstancesParas}

id, err := service.CreateCluster(ctx, basic, cAdvanced, cvms, iAdvanced, cidrSet, map[string]string{})
id, err := service.CreateCluster(ctx, basic, cAdvanced, cvms, iAdvanced, cidrSet, map[string]string{}, nil, nil)
if err != nil {
return err
}
Expand Down
158 changes: 147 additions & 11 deletions tencentcloud/resource_tc_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,56 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Disaster recover groups to which a CVM instance belongs. Only support maximum 1.",
},
// InstanceAdvancedSettingsOverrides
"desired_pod_num": {
Type: schema.TypeInt,
ForceNew: true,
Optional: true,
Default: -1,
Description: "Indicate to set desired pod number in node. valid when enable_customized_pod_cidr=true, " +
"and it override `[globe_]desired_pod_num` for current node. Either all the fields `desired_pod_num` or none.",
},
}
}

func TkeExistCvmCreateInfo() map[string]*schema.Schema {
return map[string]*schema.Schema{
"node_role": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
ValidateFunc: validateAllowedStringValue([]string{TKE_ROLE_WORKER, TKE_ROLE_MASTER_ETCD}),
Description: "Role of existed node. value:MASTER_ETCD or WORKER.",
},
"instances_para": {
Type: schema.TypeList,
ForceNew: true,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_ids": {
Type: schema.TypeList,
ForceNew: true,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Cluster IDs.",
},
},
},
Description: "Reinstallation parameters of an existing instance.",
},
"desired_pod_numbers": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeInt},
Description: "Custom mode cluster, you can specify the number of pods for each node. corresponding to the existed_instances_para.instance_ids parameter.",
},
}
}


func TkeNodePoolGlobalConfig() map[string]*schema.Schema {
return map[string]*schema.Schema{
"is_scale_in_enabled": {
Expand Down Expand Up @@ -627,9 +674,9 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Default: TKE_CLUSTER_OS_UBUNTU16,
Default: TKE_CLUSTER_OS_LINUX24,
Description: "Operating system of the cluster, the available values include: '" + strings.Join(TKE_CLUSTER_OS, "','") +
"'. Default is '" + TKE_CLUSTER_OS_UBUNTU16 + "'.",
"'. Default is '" + TKE_CLUSTER_OS_LINUX24 + "'.",
},
"cluster_os_type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -739,6 +786,19 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
ValidateFunc: validateAllowedStringValue(TKE_CLUSTER_NETWORK_TYPE),
Description: "Cluster network type, GR or VPC-CNI. Default is GR.",
},
"enable_customized_pod_cidr": {
Type: schema.TypeBool,
ForceNew: true,
Optional: true,
Default: false,
Description: "Whether to enable the custom mode of node podCIDR size. Default is false.",
},
"base_pod_num": {
Type: schema.TypeInt,
ForceNew: true,
Optional: true,
Description: "The number of basic pods. valid when enable_customized_pod_cidr=true.",
},
"is_non_static_ip_mode": {
Type: schema.TypeBool,
ForceNew: true,
Expand Down Expand Up @@ -958,6 +1018,15 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
},
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'.",
},
"exist_instance": {
Type: schema.TypeList,
ForceNew: true,
Optional: true,
Elem: &schema.Resource{
Schema: TkeExistCvmCreateInfo(),
},
Description: "create tke cluster by existed instances.",
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -1005,6 +1074,12 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
ForceNew: true,
Description: "Mount target. Default is not mounting.",
},
"globe_desired_pod_num": {
Type: schema.TypeInt,
ForceNew: true,
Optional: true,
Description: "Indicate to set desired pod number in node. valid when enable_customized_pod_cidr=true, and it takes effect for all nodes.",
},
"docker_graph_path": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1269,6 +1344,37 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
return
}

func tkeGetCvmExistInstancesPara(dMap map[string]interface{}) (tke.ExistedInstancesForNode, error) {

inst := tke.ExistedInstancesForNode{}

if temp, ok := dMap["instances_para"]; ok {
paras := temp.([]interface{})
if len(paras) > 0 {
paraMap := paras[0].(map[string]interface{})
instanceIds := paraMap["instance_ids"].([]interface{})
inst.ExistedInstancesPara = &tke.ExistedInstancesPara{}
inst.ExistedInstancesPara.InstanceIds = make([]*string, 0)
for _, v := range instanceIds {
inst.ExistedInstancesPara.InstanceIds = append(inst.ExistedInstancesPara.InstanceIds, helper.String(v.(string)))
}
}
}
if temp, ok := dMap["desired_pod_numbers"]; ok {
inst.DesiredPodNumbers = make([]*int64, 0)
podNums := temp.([]interface{})
for _, v := range podNums {
inst.DesiredPodNumbers = append(inst.DesiredPodNumbers, helper.Int64(int64(v.(int))))
}
}
if temp, ok := dMap["node_role"]; ok {
nodeRole := temp.(string)
inst.NodeRole = &nodeRole
}

return inst, nil
}

func tkeGetNodePoolGlobalConfig(d *schema.ResourceData) *tke.ModifyClusterAsGroupOptionAttributeRequest {
request := tke.NewModifyClusterAsGroupOptionAttributeRequest()
request.ClusterId = helper.String(d.Id())
Expand Down Expand Up @@ -1424,12 +1530,6 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface

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

if basic.ClusterOsType == TKE_CLUSTER_OS_TYPE_DOCKER_CUSTOMIZE {
if cluster_os != TKE_CLUSTER_OS_UBUNTU18 && cluster_os != TKE_CLUSTER_OS_CENTOS76 {
return fmt.Errorf("Only 'centos7.6x86_64' or 'ubuntu18.04.1 LTSx86_64' support 'DOCKER_CUSTOMIZE' now, can not be " + basic.ClusterOs)
}
}

basic.ClusterVersion = d.Get("cluster_version").(string)
if v, ok := d.GetOk("cluster_name"); ok {
basic.ClusterName = v.(string)
Expand All @@ -1446,6 +1546,10 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
advanced.IsNonStaticIpMode = d.Get("is_non_static_ip_mode").(bool)
advanced.DeletionProtection = d.Get("deletion_protection").(bool)
advanced.KubeProxyMode = d.Get("kube_proxy_mode").(string)
advanced.EnableCustomizedPodCIDR = d.Get("enable_customized_pod_cidr").(bool)
if v, ok := d.GetOk("base_pod_num"); ok {
advanced.BasePodNumber = int64(v.(int))
}

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

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

cvms.Master = append(cvms.Master, paraJson)
masterCount += count

if v, ok := master["desired_pod_num"]; ok {
dpNum := int64(v.(int))
if dpNum != -1 {
overrideSettings = append(overrideSettings, tke.InstanceAdvancedSettings{DesiredPodNumber: helper.Int64(dpNum)})
}
}
}
if masterCount < 3 {
return fmt.Errorf("if `cluster_deploy_type` is `TKE_DEPLOY_TYPE_INDEPENDENT` len(master_config) should >=3")
Expand All @@ -1540,11 +1652,17 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
for index := range workerList {
worker := workerList[index].(map[string]interface{})
paraJson, _, err := tkeGetCvmRunInstancesPara(worker, meta, vpcId, basic.ProjectId)

if err != nil {
return err
}
cvms.Work = append(cvms.Work, paraJson)

if v, ok := worker["desired_pod_num"]; ok {
dpNum := int64(v.(int))
if dpNum != -1 {
overrideSettings = append(overrideSettings, tke.InstanceAdvancedSettings{DesiredPodNumber: helper.Int64(dpNum)})
}
}
}
}

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

service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
// ExistedInstancesForNode
existIntances := make([]*tke.ExistedInstancesForNode, 0)
if instances, ok := d.GetOk("exist_instance"); ok {
instanceList := instances.([]interface{})
for index := range instanceList {
instance := instanceList[index].(map[string]interface{})
existedInstance, _ := tkeGetCvmExistInstancesPara(instance)
existIntances = append(existIntances, &existedInstance)
}
}

// RunInstancesForNode(master_config+worker_config) 和 ExistedInstancesForNode 不能同时存在
if len(cvms.Master)+len(cvms.Work) > 0 && len(existIntances) > 0 {
return fmt.Errorf("master_config+worker_config and exist_instance can not exist at the same time")
}

id, err := service.CreateCluster(ctx, basic, advanced, cvms, iAdvanced, cidrSet, tags)
service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
id, err := service.CreateCluster(ctx, basic, advanced, cvms, iAdvanced, cidrSet, tags, existIntances, overrideSettings)
if err != nil {
return err
}
Expand Down
Loading