-
Notifications
You must be signed in to change notification settings - Fork 140
feat(tke): [119900163]tke scale worker taints parameters #2859
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
Changes from 9 commits
ea33a20
53c7949
54c281f
26b42ed
2caa64d
5f7d79a
c346371
0462239
1e96705
456f2e5
50b075b
a937c36
fbe2f7b
994b235
ab4475c
e559a7d
b6d7308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
resource/tencentcloud_kubernetes_scale_worker: support `taints` parameter | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,90 @@ func customScaleWorkerResourceImporter(ctx context.Context, d *schema.ResourceDa | |
return []*schema.ResourceData{d}, nil | ||
} | ||
|
||
func resourceTencentCloudKubernetesScaleWorkerReadPostRequest1(ctx context.Context, req *tke.DescribeClusterInstancesRequest, resp *tke.DescribeClusterInstancesResponse) error { | ||
func resourceTencentCloudKubernetesScaleWorkerReadPostRequest1(ctx context.Context, req *cvm.DescribeInstancesRequest, resp *cvm.DescribeInstancesResponse) error { | ||
d := tccommon.ResourceDataFromContext(ctx) | ||
|
||
instances := make([]*cvm.Instance, 0) | ||
instances = append(instances, resp.Response.InstanceSet...) | ||
|
||
instanceList := make([]interface{}, 0, len(instances)) | ||
for _, instance := range instances { | ||
mapping := map[string]interface{}{ | ||
"count": 1, | ||
"instance_charge_type_prepaid_period": 1, | ||
"instance_type": helper.PString(instance.InstanceType), | ||
"subnet_id": helper.PString(instance.VirtualPrivateCloud.SubnetId), | ||
"availability_zone": helper.PString(instance.Placement.Zone), | ||
"instance_name": helper.PString(instance.InstanceName), | ||
"instance_charge_type": helper.PString(instance.InstanceChargeType), | ||
"system_disk_type": helper.PString(instance.SystemDisk.DiskType), | ||
"system_disk_size": helper.PInt64(instance.SystemDisk.DiskSize), | ||
"internet_charge_type": helper.PString(instance.InternetAccessible.InternetChargeType), | ||
"bandwidth_package_id": helper.PString(instance.InternetAccessible.BandwidthPackageId), | ||
"internet_max_bandwidth_out": helper.PInt64(instance.InternetAccessible.InternetMaxBandwidthOut), | ||
"security_group_ids": helper.StringsInterfaces(instance.SecurityGroupIds), | ||
"img_id": helper.PString(instance.ImageId), | ||
} | ||
|
||
if instance.RenewFlag != nil && helper.PString(instance.InstanceChargeType) == "PREPAID" { | ||
mapping["instance_charge_type_prepaid_renew_flag"] = helper.PString(instance.RenewFlag) | ||
} else { | ||
mapping["instance_charge_type_prepaid_renew_flag"] = "" | ||
} | ||
if helper.PInt64(instance.InternetAccessible.InternetMaxBandwidthOut) > 0 { | ||
mapping["public_ip_assigned"] = true | ||
} | ||
|
||
if instance.CamRoleName != nil { | ||
mapping["cam_role_name"] = instance.CamRoleName | ||
} | ||
if instance.LoginSettings != nil { | ||
if instance.LoginSettings.KeyIds != nil && len(instance.LoginSettings.KeyIds) > 0 { | ||
mapping["key_ids"] = helper.StringsInterfaces(instance.LoginSettings.KeyIds) | ||
} | ||
if instance.LoginSettings.Password != nil { | ||
mapping["password"] = helper.PString(instance.LoginSettings.Password) | ||
} | ||
} | ||
if instance.DisasterRecoverGroupId != nil && helper.PString(instance.DisasterRecoverGroupId) != "" { | ||
mapping["disaster_recover_group_ids"] = []string{helper.PString(instance.DisasterRecoverGroupId)} | ||
} | ||
if instance.HpcClusterId != nil { | ||
mapping["hpc_cluster_id"] = helper.PString(instance.HpcClusterId) | ||
} | ||
|
||
dataDisks := make([]interface{}, 0, len(instance.DataDisks)) | ||
for _, v := range instance.DataDisks { | ||
dataDisk := map[string]interface{}{ | ||
"disk_type": helper.PString(v.DiskType), | ||
"disk_size": helper.PInt64(v.DiskSize), | ||
"snapshot_id": helper.PString(v.DiskId), | ||
"encrypt": helper.PBool(v.Encrypt), | ||
"kms_key_id": helper.PString(v.KmsKeyId), | ||
} | ||
dataDisks = append(dataDisks, dataDisk) | ||
} | ||
|
||
mapping["data_disk"] = dataDisks // worker_config.data_disk | ||
instanceList = append(instanceList, mapping) | ||
} | ||
if importFlag1 { | ||
_ = d.Set("worker_config", instanceList) | ||
} | ||
|
||
// The machines I generated was deleted by others. | ||
if len(WorkersNewWorkerInstancesList) == 0 { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
_ = d.Set("cluster_id", GlobalClusterId) | ||
_ = d.Set("labels", WorkersLabelsMap) | ||
_ = d.Set("worker_instances_list", WorkersNewWorkerInstancesList) | ||
|
||
return nil | ||
} | ||
func resourceTencentCloudKubernetesScaleWorkerReadPostRequest2(ctx context.Context, req *tke.DescribeClusterInstancesRequest, resp *tke.DescribeClusterInstancesResponse) error { | ||
d := tccommon.ResourceDataFromContext(ctx) | ||
var has = map[string]bool{} | ||
|
||
|
@@ -198,90 +281,6 @@ func resourceTencentCloudKubernetesScaleWorkerReadPostRequest1(ctx context.Conte | |
return nil | ||
} | ||
|
||
func resourceTencentCloudKubernetesScaleWorkerReadPostRequest2(ctx context.Context, req *cvm.DescribeInstancesRequest, resp *cvm.DescribeInstancesResponse) error { | ||
d := tccommon.ResourceDataFromContext(ctx) | ||
|
||
instances := make([]*cvm.Instance, 0) | ||
instances = append(instances, resp.Response.InstanceSet...) | ||
|
||
instanceList := make([]interface{}, 0, len(instances)) | ||
for _, instance := range instances { | ||
mapping := map[string]interface{}{ | ||
"count": 1, | ||
"instance_charge_type_prepaid_period": 1, | ||
"instance_type": helper.PString(instance.InstanceType), | ||
"subnet_id": helper.PString(instance.VirtualPrivateCloud.SubnetId), | ||
"availability_zone": helper.PString(instance.Placement.Zone), | ||
"instance_name": helper.PString(instance.InstanceName), | ||
"instance_charge_type": helper.PString(instance.InstanceChargeType), | ||
"system_disk_type": helper.PString(instance.SystemDisk.DiskType), | ||
"system_disk_size": helper.PInt64(instance.SystemDisk.DiskSize), | ||
"internet_charge_type": helper.PString(instance.InternetAccessible.InternetChargeType), | ||
"bandwidth_package_id": helper.PString(instance.InternetAccessible.BandwidthPackageId), | ||
"internet_max_bandwidth_out": helper.PInt64(instance.InternetAccessible.InternetMaxBandwidthOut), | ||
"security_group_ids": helper.StringsInterfaces(instance.SecurityGroupIds), | ||
"img_id": helper.PString(instance.ImageId), | ||
} | ||
|
||
if instance.RenewFlag != nil && helper.PString(instance.InstanceChargeType) == "PREPAID" { | ||
mapping["instance_charge_type_prepaid_renew_flag"] = helper.PString(instance.RenewFlag) | ||
} else { | ||
mapping["instance_charge_type_prepaid_renew_flag"] = "" | ||
} | ||
if helper.PInt64(instance.InternetAccessible.InternetMaxBandwidthOut) > 0 { | ||
mapping["public_ip_assigned"] = true | ||
} | ||
|
||
if instance.CamRoleName != nil { | ||
mapping["cam_role_name"] = instance.CamRoleName | ||
} | ||
if instance.LoginSettings != nil { | ||
if instance.LoginSettings.KeyIds != nil && len(instance.LoginSettings.KeyIds) > 0 { | ||
mapping["key_ids"] = helper.StringsInterfaces(instance.LoginSettings.KeyIds) | ||
} | ||
if instance.LoginSettings.Password != nil { | ||
mapping["password"] = helper.PString(instance.LoginSettings.Password) | ||
} | ||
} | ||
if instance.DisasterRecoverGroupId != nil && helper.PString(instance.DisasterRecoverGroupId) != "" { | ||
mapping["disaster_recover_group_ids"] = []string{helper.PString(instance.DisasterRecoverGroupId)} | ||
} | ||
if instance.HpcClusterId != nil { | ||
mapping["hpc_cluster_id"] = helper.PString(instance.HpcClusterId) | ||
} | ||
|
||
dataDisks := make([]interface{}, 0, len(instance.DataDisks)) | ||
for _, v := range instance.DataDisks { | ||
dataDisk := map[string]interface{}{ | ||
"disk_type": helper.PString(v.DiskType), | ||
"disk_size": helper.PInt64(v.DiskSize), | ||
"snapshot_id": helper.PString(v.DiskId), | ||
"encrypt": helper.PBool(v.Encrypt), | ||
"kms_key_id": helper.PString(v.KmsKeyId), | ||
} | ||
dataDisks = append(dataDisks, dataDisk) | ||
} | ||
|
||
mapping["data_disk"] = dataDisks // worker_config.data_disk | ||
instanceList = append(instanceList, mapping) | ||
} | ||
if importFlag1 { | ||
_ = d.Set("worker_config", instanceList) | ||
} | ||
|
||
// The machines I generated was deleted by others. | ||
if len(WorkersNewWorkerInstancesList) == 0 { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
_ = d.Set("cluster_id", GlobalClusterId) | ||
_ = d.Set("labels", WorkersLabelsMap) | ||
_ = d.Set("worker_instances_list", WorkersNewWorkerInstancesList) | ||
|
||
return nil | ||
} | ||
|
||
func resourceTencentCloudKubernetesScaleWorkerDeletePostRequest0(ctx context.Context, req *tke.DescribeClustersRequest, resp *tke.DescribeClustersResponse) *resource.RetryError { | ||
if len(resp.Response.Clusters) == 0 { | ||
return resource.NonRetryableError(fmt.Errorf("The cluster has been deleted")) | ||
|
@@ -396,6 +395,23 @@ func resourceTencentCloudKubernetesScaleWorkerCreateOnStart(ctx context.Context) | |
iAdvanced.PreStartUserScript = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("taints"); ok { | ||
for _, item := range v.([]interface{}) { | ||
taintsMap := item.(map[string]interface{}) | ||
taint := tke.Taint{} | ||
if v, ok := taintsMap["key"]; ok { | ||
taint.Key = helper.String(v.(string)) | ||
} | ||
if v, ok := taintsMap["value"]; ok { | ||
taint.Value = helper.String(v.(string)) | ||
} | ||
if v, ok := taintsMap["effect"]; ok { | ||
taint.Effect = helper.String(v.(string)) | ||
} | ||
iAdvanced.Taints = append(iAdvanced.Taints, &taint) | ||
} | ||
} | ||
|
||
if v, ok := d.GetOk("user_script"); ok { | ||
iAdvanced.UserScript = helper.String(v.(string)) | ||
} | ||
|
@@ -609,3 +625,55 @@ func resourceTencentCloudKubernetesScaleWorkerDeleteOnExit(ctx context.Context) | |
} | ||
return nil | ||
} | ||
|
||
func resourceTencentCloudKubernetesScaleWorkerReadPostFillRequest1(ctx context.Context, req *cvm.DescribeInstancesRequest) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个方法的改动跟taints有什么关系? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 把之前你改的那段放到 Hook 里面了(需要改动 DSL),重新生成代码 |
||
d := tccommon.ResourceDataFromContext(ctx) | ||
meta := tccommon.ProviderMetaFromContext(ctx) | ||
logId := tccommon.GetLogId(ctx) | ||
|
||
idSplit := strings.Split(d.Id(), tccommon.FILED_SP) | ||
if len(idSplit) != 2 { | ||
return fmt.Errorf("id is broken,%s", d.Id()) | ||
} | ||
clusterId := idSplit[0] | ||
|
||
request := tke.NewDescribeClusterInstancesRequest() | ||
request.ClusterId = helper.String(clusterId) | ||
|
||
instanceSet := make([]*tke.Instance, 0) | ||
|
||
var offset int64 = 0 | ||
var pageSize int64 = 100 | ||
for { | ||
request.Offset = &offset | ||
request.Limit = &pageSize | ||
ratelimit.Check(request.GetAction()) | ||
|
||
response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTkeClient().DescribeClusterInstances(request) | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) | ||
|
||
if err := resourceTencentCloudKubernetesScaleWorkerReadPostRequest2(ctx, request, response); err != nil { | ||
return err | ||
} | ||
|
||
if response == nil || len(response.Response.InstanceSet) < 1 { | ||
break | ||
} | ||
count := len(response.Response.InstanceSet) | ||
instanceSet = append(instanceSet, response.Response.InstanceSet...) | ||
|
||
if count < int(pageSize) { | ||
break | ||
} | ||
offset += pageSize | ||
} | ||
if instanceSet == nil { | ||
d.SetId("") | ||
log.Printf("[WARN]%s resource `kubernetes_scale_worker` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) | ||
return nil | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taints加到tkeGetInstanceAdvancedPara()里有问题吧。这个方法是多个资源共用的。node_pool也会用这个方法。