|
6 | 6 | "log"
|
7 | 7 | "strings"
|
8 | 8 |
|
| 9 | + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" |
| 10 | + |
9 | 11 | as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
|
10 | 12 | sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
|
11 | 13 |
|
@@ -616,45 +618,49 @@ func resourceTencentCloudKubernetesNodePoolUpdateOnStart(ctx context.Context) er
|
616 | 618 | "labels",
|
617 | 619 | "tags",
|
618 | 620 | ) {
|
619 |
| - request := tke.NewModifyClusterNodePoolRequest() |
620 |
| - request.ClusterId = &clusterId |
621 |
| - request.NodePoolId = &nodePoolId |
| 621 | + var body map[string]interface{} |
| 622 | + nodeOs := d.Get("node_os").(string) |
| 623 | + nodeOsType := d.Get("node_os_type").(string) |
| 624 | + //自定镜像不能指定节点操作系统类型 |
| 625 | + if strings.Contains(nodeOs, "img-") { |
| 626 | + nodeOsType = "" |
| 627 | + } |
622 | 628 |
|
623 | 629 | labels := GetTkeLabels(d, "labels")
|
624 |
| - tags := helper.GetTags(d, "tags") |
625 |
| - if len(labels) > 0 { |
626 |
| - request.Labels = labels |
| 630 | + body = map[string]interface{}{ |
| 631 | + "ClusterId": clusterId, |
| 632 | + "NodePoolId": nodePoolId, |
| 633 | + "OsName": nodeOs, |
| 634 | + "OsCustomizeType": nodeOsType, |
| 635 | + "Labels": labels, |
627 | 636 | }
|
| 637 | + |
| 638 | + tags := helper.GetTags(d, "tags") |
628 | 639 | if len(tags) > 0 {
|
| 640 | + var tmpTags []*tke.Tag |
629 | 641 | for k, v := range tags {
|
630 | 642 | key := k
|
631 | 643 | val := v
|
632 |
| - request.Tags = append(request.Tags, &tke.Tag{ |
| 644 | + tmpTags = append(tmpTags, &tke.Tag{ |
633 | 645 | Key: &key,
|
634 | 646 | Value: &val,
|
635 | 647 | })
|
636 | 648 | }
|
| 649 | + |
| 650 | + body["Tags"] = tmpTags |
637 | 651 | }
|
638 | 652 |
|
639 |
| - nodeOs := d.Get("node_os").(string) |
640 |
| - nodeOsType := d.Get("node_os_type").(string) |
641 |
| - //自定镜像不能指定节点操作系统类型 |
642 |
| - if strings.Contains(nodeOs, "img-") { |
643 |
| - nodeOsType = "" |
| 653 | + client := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOmitNilClient("tke") |
| 654 | + request := tchttp.NewCommonRequest("tke", "2018-05-25", "ModifyClusterNodePool") |
| 655 | + err := request.SetActionParameters(body) |
| 656 | + if err != nil { |
| 657 | + return err |
644 | 658 | }
|
645 |
| - request.OsName = &nodeOs |
646 |
| - request.OsCustomizeType = &nodeOsType |
647 |
| - err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { |
648 |
| - result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTkeClient().ModifyClusterNodePool(request) |
649 |
| - if e != nil { |
650 |
| - return tccommon.RetryError(e) |
651 |
| - } else { |
652 |
| - log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) |
653 |
| - } |
654 |
| - return nil |
655 |
| - }) |
| 659 | + |
| 660 | + response := tchttp.NewCommonResponse() |
| 661 | + err = client.Send(request, response) |
656 | 662 | if err != nil {
|
657 |
| - log.Printf("[CRITAL]%s update kubernetes node pool failed, reason:%+v", logId, err) |
| 663 | + fmt.Printf("update kubernetes node pool taints failed: %v \n", err) |
658 | 664 | return err
|
659 | 665 | }
|
660 | 666 |
|
@@ -1243,3 +1249,86 @@ func desiredCapacityOutRange(d *schema.ResourceData) bool {
|
1243 | 1249 | maxSize := d.Get("max_size").(int)
|
1244 | 1250 | return capacity > maxSize || capacity < minSize
|
1245 | 1251 | }
|
| 1252 | + |
| 1253 | +func resourceTencentCloudKubernetesNodePoolUpdatePostHandleResponse0(ctx context.Context, resp *tke.ModifyClusterNodePoolResponse) error { |
| 1254 | + d := tccommon.ResourceDataFromContext(ctx) |
| 1255 | + meta := tccommon.ProviderMetaFromContext(ctx) |
| 1256 | + logId := tccommon.GetLogId(tccommon.ContextNil) |
| 1257 | + |
| 1258 | + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) |
| 1259 | + if len(idSplit) != 2 { |
| 1260 | + return fmt.Errorf("id is broken,%s", d.Id()) |
| 1261 | + } |
| 1262 | + clusterId := idSplit[0] |
| 1263 | + nodePoolId := idSplit[1] |
| 1264 | + |
| 1265 | + if d.HasChange("taints") { |
| 1266 | + _, n := d.GetChange("taints") |
| 1267 | + |
| 1268 | + // clean taints |
| 1269 | + if len(n.([]interface{})) == 0 { |
| 1270 | + body := map[string]interface{}{ |
| 1271 | + "ClusterId": clusterId, |
| 1272 | + "NodePoolId": nodePoolId, |
| 1273 | + "Taints": []interface{}{}, |
| 1274 | + } |
| 1275 | + |
| 1276 | + client := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOmitNilClient("tke") |
| 1277 | + request := tchttp.NewCommonRequest("tke", "2018-05-25", "ModifyClusterNodePool") |
| 1278 | + err := request.SetActionParameters(body) |
| 1279 | + if err != nil { |
| 1280 | + return err |
| 1281 | + } |
| 1282 | + |
| 1283 | + response := tchttp.NewCommonResponse() |
| 1284 | + err = client.Send(request, response) |
| 1285 | + if err != nil { |
| 1286 | + fmt.Printf("update kubernetes node pool taints failed: %v \n", err) |
| 1287 | + return err |
| 1288 | + } |
| 1289 | + } else { |
| 1290 | + request := tke.NewModifyClusterNodePoolRequest() |
| 1291 | + request.ClusterId = helper.String(clusterId) |
| 1292 | + request.NodePoolId = helper.String(nodePoolId) |
| 1293 | + |
| 1294 | + if v, ok := d.GetOk("taints"); ok { |
| 1295 | + for _, item := range v.([]interface{}) { |
| 1296 | + taintsMap := item.(map[string]interface{}) |
| 1297 | + taint := tke.Taint{} |
| 1298 | + if v, ok := taintsMap["key"]; ok { |
| 1299 | + taint.Key = helper.String(v.(string)) |
| 1300 | + } |
| 1301 | + |
| 1302 | + if v, ok := taintsMap["value"]; ok { |
| 1303 | + taint.Value = helper.String(v.(string)) |
| 1304 | + } |
| 1305 | + |
| 1306 | + if v, ok := taintsMap["effect"]; ok { |
| 1307 | + taint.Effect = helper.String(v.(string)) |
| 1308 | + } |
| 1309 | + |
| 1310 | + request.Taints = append(request.Taints, &taint) |
| 1311 | + } |
| 1312 | + } |
| 1313 | + |
| 1314 | + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { |
| 1315 | + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTkeV20180525Client().ModifyClusterNodePoolWithContext(ctx, request) |
| 1316 | + if e != nil { |
| 1317 | + return tccommon.RetryError(e) |
| 1318 | + } else { |
| 1319 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) |
| 1320 | + } |
| 1321 | + |
| 1322 | + return nil |
| 1323 | + }) |
| 1324 | + |
| 1325 | + if err != nil { |
| 1326 | + log.Printf("[CRITAL]%s update kubernetes node pool taints failed, reason:%+v", logId, err) |
| 1327 | + return err |
| 1328 | + } |
| 1329 | + } |
| 1330 | + |
| 1331 | + return nil |
| 1332 | + } |
| 1333 | + return nil |
| 1334 | +} |
0 commit comments