Skip to content

feature: TKE node pool support backup instance types #658

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
Aug 24, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.58.4 (Aug 24, 2021)

ENHANCEMENTS:
* Resource `resource_tc_kubernetes_node_pool.go` support `backup_instance_type` for `auto_scaling_config`

## 1.58.3 (Aug 18, 2021)

ENHANCEMENTS:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.234
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.199
Expand All @@ -45,7 +45,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.234
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199 h1:
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199/go.mod h1:b7dNjabPys0/iLwRFd8MVE5EkJTNAh4qtaHQOOLchx4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.199 h1:TeLKOemumLTjWpkRKNVNhpb7VMDlOPaVEuukrWmab30=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.199/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.234 h1:yAtw4jVBsQZ/KcM2nMHRzcpIfSXRw0Alt7wVTR9OodM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.234/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199 h1:ajgJogYSIQ5u1PIbiV5nsvr5K0fYpm1/T7Dy+mxEM6U=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199 h1:L0twFkJMOZzLkX08w8S14nX6oanD8YxMQDIaYXVim6A=
Expand Down Expand Up @@ -500,6 +502,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.199 h1:ku4oDXW
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.199/go.mod h1:SEUO10oGtg+4AGCfpJDn9ynf47P+ZiyvhzOyXLt0mOY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.199 h1:AHlrfOhAZnmwQOZ4aitzOb3Tzzw3LBKViPtI40F+ldI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.199/go.mod h1:ij3CHdPvqI2aSMcl7+jdI0yCO7oOiywKTAa55qmO2iI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.234 h1:bJU0a3yEir4BHTiIHgLvsVqDAFeuHe/r3PML3V92R/o=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.234/go.mod h1:ij3CHdPvqI2aSMcl7+jdI0yCO7oOiywKTAa55qmO2iI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199 h1:6Yt74l4pA5QtzhwMNIEUt0spXdSBKH744DDqTHJOCP0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199/go.mod h1:Yw6OQ33z3s4k0HVYTNSffB12qOzEJ2Zf1Vj4+5S3sRs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.199 h1:UDZ59pvaqjDy2QIsMsv9hxm0BEJLmPIbHF1ms0MqaRk=
Expand Down
60 changes: 57 additions & 3 deletions tencentcloud/resource_tc_kubernetes_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,30 @@ import (
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func getNodePoolInstanceTypes(d *schema.ResourceData) []*string {
configParas := d.Get("auto_scaling_config").([]interface{})
dMap := configParas[0].(map[string]interface{})
instanceType, _ := dMap["instance_type"]
currInsType := instanceType.(string)
v, ok := dMap["backup_instance_types"]
backupInstanceTypes := v.([]interface{})
instanceTypes := make([]*string, 0)
if !ok || len(backupInstanceTypes) == 0 {
instanceTypes = append(instanceTypes, &currInsType)
return instanceTypes
}
headType := backupInstanceTypes[0].(string)
if headType != currInsType {
instanceTypes = append(instanceTypes, &currInsType)
}
for i := range backupInstanceTypes {
insType := backupInstanceTypes[i].(string)
instanceTypes = append(instanceTypes, &insType)
}

return instanceTypes
}

func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
needSchema := map[string]*schema.Schema{
"instance_type": {
Expand All @@ -116,6 +140,12 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
ForceNew: true,
Description: "Specified types of CVM instance.",
},
"backup_instance_types": {
Type: schema.TypeList,
Optional: true,
Description: "Backup CVM instance types if specified instance type sold out or mismatch.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"system_disk_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -457,7 +487,7 @@ func composeParameterToAsScalingGroupParaSerial(d *schema.ResourceData) (string,
}

//this function is similar to kubernetesAsScalingConfigParaSerial, but less parameter
func comosedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, meta interface{}) (string, error) {
func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, meta interface{}) (string, error) {
var (
result string
errRet error
Expand Down Expand Up @@ -687,7 +717,7 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
return err
}

configParaStr, err := comosedKubernetesAsScalingConfigParaSerial(configParas[0].(map[string]interface{}), meta)
configParaStr, err := composedKubernetesAsScalingConfigParaSerial(configParas[0].(map[string]interface{}), meta)
if err != nil {
return err
}
Expand Down Expand Up @@ -742,7 +772,16 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
return err
}

//modify os and image
instanceTypes := getNodePoolInstanceTypes(d)

if len(instanceTypes) != 0 {
err := service.ModifyClusterNodePoolInstanceTypes(ctx, clusterId, nodePoolId, instanceTypes)
if err != nil {
return err
}
}

//modify os, instanceTypes and image
err = resourceKubernetesNodePoolUpdate(d, meta)
if err != nil {
return err
Expand Down Expand Up @@ -811,6 +850,21 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
}
d.SetPartial("desired_capacity")
}

if d.HasChange("auto_scaling_config.0.backup_instance_types") {
instanceTypes := getNodePoolInstanceTypes(d)
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
errRet := service.ModifyClusterNodePoolInstanceTypes(ctx, clusterId, nodePoolId, instanceTypes)
if errRet != nil {
return retryError(errRet)
}
return nil
})
if err != nil {
return err
}
d.Set("auto_scaling_config.0.backup_instance_types", instanceTypes)
}
d.Partial(false)

return resourceKubernetesNodePoolRead(d, meta)
Expand Down
22 changes: 22 additions & 0 deletions tencentcloud/service_tencentcloud_tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,28 @@ func (me *TkeService) ModifyClusterNodePoolDesiredCapacity(ctx context.Context,
return
}

func (me *TkeService) ModifyClusterNodePoolInstanceTypes(ctx context.Context, clusterId, nodePoolId string, instanceTypes []*string) (errRet error) {
logId := getLogId(ctx)
request := tke.NewModifyNodePoolInstanceTypesRequest()

defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, reason[%s]\n", logId, request.GetAction(), errRet.Error())
}
}()
request.ClusterId = &clusterId
request.NodePoolId = &nodePoolId
request.InstanceTypes = instanceTypes

ratelimit.Check(request.GetAction())
_, err := me.client.UseTkeClient().ModifyNodePoolInstanceTypes(request)
if err != nil {
errRet = err
return
}
return
}

func (me *TkeService) DeleteClusterNodePool(ctx context.Context, id, nodePoolId string, deleteKeepInstance bool) (errRet error) {

logId := getLogId(ctx)
Expand Down
Loading