@@ -549,9 +549,56 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
549
549
Elem : & schema.Schema {Type : schema .TypeString },
550
550
Description : "Disaster recover groups to which a CVM instance belongs. Only support maximum 1." ,
551
551
},
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
+ },
552
598
}
553
599
}
554
600
601
+
555
602
func TkeNodePoolGlobalConfig () map [string ]* schema.Schema {
556
603
return map [string ]* schema.Schema {
557
604
"is_scale_in_enabled" : {
@@ -627,9 +674,9 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
627
674
Type : schema .TypeString ,
628
675
ForceNew : true ,
629
676
Optional : true ,
630
- Default : TKE_CLUSTER_OS_UBUNTU16 ,
677
+ Default : TKE_CLUSTER_OS_LINUX24 ,
631
678
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 + "'." ,
633
680
},
634
681
"cluster_os_type" : {
635
682
Type : schema .TypeString ,
@@ -739,6 +786,19 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
739
786
ValidateFunc : validateAllowedStringValue (TKE_CLUSTER_NETWORK_TYPE ),
740
787
Description : "Cluster network type, GR or VPC-CNI. Default is GR." ,
741
788
},
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
+ },
742
802
"is_non_static_ip_mode" : {
743
803
Type : schema .TypeBool ,
744
804
ForceNew : true ,
@@ -958,6 +1018,15 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
958
1018
},
959
1019
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'." ,
960
1020
},
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
+ },
961
1030
"tags" : {
962
1031
Type : schema .TypeMap ,
963
1032
Optional : true ,
@@ -1005,6 +1074,12 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
1005
1074
ForceNew : true ,
1006
1075
Description : "Mount target. Default is not mounting." ,
1007
1076
},
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
+ },
1008
1083
"docker_graph_path" : {
1009
1084
Type : schema .TypeString ,
1010
1085
Optional : true ,
@@ -1269,6 +1344,37 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
1269
1344
return
1270
1345
}
1271
1346
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
+
1272
1378
func tkeGetNodePoolGlobalConfig (d * schema.ResourceData ) * tke.ModifyClusterAsGroupOptionAttributeRequest {
1273
1379
request := tke .NewModifyClusterAsGroupOptionAttributeRequest ()
1274
1380
request .ClusterId = helper .String (d .Id ())
@@ -1424,12 +1530,6 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
1424
1530
1425
1531
basic .ClusterOsType = d .Get ("cluster_os_type" ).(string )
1426
1532
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
-
1433
1533
basic .ClusterVersion = d .Get ("cluster_version" ).(string )
1434
1534
if v , ok := d .GetOk ("cluster_name" ); ok {
1435
1535
basic .ClusterName = v .(string )
@@ -1446,6 +1546,10 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
1446
1546
advanced .IsNonStaticIpMode = d .Get ("is_non_static_ip_mode" ).(bool )
1447
1547
advanced .DeletionProtection = d .Get ("deletion_protection" ).(bool )
1448
1548
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
+ }
1449
1553
1450
1554
if extraArgs , ok := d .GetOk ("cluster_extra_args" ); ok {
1451
1555
extraArgList := extraArgs .([]interface {})
@@ -1509,6 +1613,7 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
1509
1613
}
1510
1614
}
1511
1615
1616
+ overrideSettings := make ([]tke.InstanceAdvancedSettings , 0 )
1512
1617
if masters , ok := d .GetOk ("master_config" ); ok {
1513
1618
if clusterDeployType == TKE_DEPLOY_TYPE_MANAGED {
1514
1619
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
1524
1629
1525
1630
cvms .Master = append (cvms .Master , paraJson )
1526
1631
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
+ }
1527
1639
}
1528
1640
if masterCount < 3 {
1529
1641
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
1540
1652
for index := range workerList {
1541
1653
worker := workerList [index ].(map [string ]interface {})
1542
1654
paraJson , _ , err := tkeGetCvmRunInstancesPara (worker , meta , vpcId , basic .ProjectId )
1543
-
1544
1655
if err != nil {
1545
1656
return err
1546
1657
}
1547
1658
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
+ }
1548
1666
}
1549
1667
}
1550
1668
@@ -1567,10 +1685,28 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
1567
1685
if temp , ok := d .GetOk ("mount_target" ); ok {
1568
1686
iAdvanced .MountTarget = temp .(string )
1569
1687
}
1688
+ if temp , ok := d .GetOk ("globe_desired_pod_num" ); ok {
1689
+ iAdvanced .DesiredPodNum = int64 (temp .(int ))
1690
+ }
1570
1691
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
+ }
1572
1707
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 )
1574
1710
if err != nil {
1575
1711
return err
1576
1712
}
0 commit comments