@@ -556,6 +556,52 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
556556 ValidateFunc : validateImageID ,
557557 Description : "The valid image id, format of img-xxx." ,
558558 },
559+ // InstanceAdvancedSettingsOverrides
560+ "desired_pod_num" : {
561+ Type : schema .TypeInt ,
562+ ForceNew : true ,
563+ Optional : true ,
564+ Default : - 1 ,
565+ Description : "Indicate to set desired pod number in node. valid when enable_customized_pod_cidr=true, " +
566+ "and it override `[globe_]desired_pod_num` for current node. Either all the fields `desired_pod_num` or none." ,
567+ },
568+ }
569+ }
570+
571+ func TkeExistCvmCreateInfo () map [string ]* schema.Schema {
572+ return map [string ]* schema.Schema {
573+ "node_role" : {
574+ Type : schema .TypeString ,
575+ ForceNew : true ,
576+ Optional : true ,
577+ ValidateFunc : validateAllowedStringValue ([]string {TKE_ROLE_WORKER , TKE_ROLE_MASTER_ETCD }),
578+ Description : "Role of existed node. value:MASTER_ETCD or WORKER." ,
579+ },
580+ "instances_para" : {
581+ Type : schema .TypeList ,
582+ ForceNew : true ,
583+ Optional : true ,
584+ MaxItems : 1 ,
585+ Elem : & schema.Resource {
586+ Schema : map [string ]* schema.Schema {
587+ "instance_ids" : {
588+ Type : schema .TypeList ,
589+ ForceNew : true ,
590+ Required : true ,
591+ Elem : & schema.Schema {Type : schema .TypeString },
592+ Description : "Cluster IDs." ,
593+ },
594+ },
595+ },
596+ Description : "Reinstallation parameters of an existing instance." ,
597+ },
598+ "desired_pod_numbers" : {
599+ Type : schema .TypeList ,
600+ Optional : true ,
601+ ForceNew : true ,
602+ Elem : & schema.Schema {Type : schema .TypeInt },
603+ Description : "Custom mode cluster, you can specify the number of pods for each node. corresponding to the existed_instances_para.instance_ids parameter." ,
604+ },
559605 }
560606}
561607
@@ -634,9 +680,9 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
634680 Type : schema .TypeString ,
635681 ForceNew : true ,
636682 Optional : true ,
637- Default : TKE_CLUSTER_OS_UBUNTU16 ,
683+ Default : TKE_CLUSTER_OS_LINUX24 ,
638684 Description : "Operating system of the cluster, the available values include: '" + strings .Join (TKE_CLUSTER_OS , "','" ) +
639- "'. Default is '" + TKE_CLUSTER_OS_UBUNTU16 + "'." ,
685+ "'. Default is '" + TKE_CLUSTER_OS_LINUX24 + "'." ,
640686 },
641687 "cluster_os_type" : {
642688 Type : schema .TypeString ,
@@ -746,6 +792,19 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
746792 ValidateFunc : validateAllowedStringValue (TKE_CLUSTER_NETWORK_TYPE ),
747793 Description : "Cluster network type, GR or VPC-CNI. Default is GR." ,
748794 },
795+ "enable_customized_pod_cidr" : {
796+ Type : schema .TypeBool ,
797+ ForceNew : true ,
798+ Optional : true ,
799+ Default : false ,
800+ Description : "Whether to enable the custom mode of node podCIDR size. Default is false." ,
801+ },
802+ "base_pod_num" : {
803+ Type : schema .TypeInt ,
804+ ForceNew : true ,
805+ Optional : true ,
806+ Description : "The number of basic pods. valid when enable_customized_pod_cidr=true." ,
807+ },
749808 "is_non_static_ip_mode" : {
750809 Type : schema .TypeBool ,
751810 ForceNew : true ,
@@ -965,6 +1024,15 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
9651024 },
9661025 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'." ,
9671026 },
1027+ "exist_instance" : {
1028+ Type : schema .TypeList ,
1029+ ForceNew : true ,
1030+ Optional : true ,
1031+ Elem : & schema.Resource {
1032+ Schema : TkeExistCvmCreateInfo (),
1033+ },
1034+ Description : "create tke cluster by existed instances." ,
1035+ },
9681036 "tags" : {
9691037 Type : schema .TypeMap ,
9701038 Optional : true ,
@@ -1012,6 +1080,12 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
10121080 ForceNew : true ,
10131081 Description : "Mount target. Default is not mounting." ,
10141082 },
1083+ "globe_desired_pod_num" : {
1084+ Type : schema .TypeInt ,
1085+ ForceNew : true ,
1086+ Optional : true ,
1087+ Description : "Indicate to set desired pod number in node. valid when enable_customized_pod_cidr=true, and it takes effect for all nodes." ,
1088+ },
10151089 "docker_graph_path" : {
10161090 Type : schema .TypeString ,
10171091 Optional : true ,
@@ -1280,6 +1354,37 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
12801354 return
12811355}
12821356
1357+ func tkeGetCvmExistInstancesPara (dMap map [string ]interface {}) (tke.ExistedInstancesForNode , error ) {
1358+
1359+ inst := tke.ExistedInstancesForNode {}
1360+
1361+ if temp , ok := dMap ["instances_para" ]; ok {
1362+ paras := temp .([]interface {})
1363+ if len (paras ) > 0 {
1364+ paraMap := paras [0 ].(map [string ]interface {})
1365+ instanceIds := paraMap ["instance_ids" ].([]interface {})
1366+ inst .ExistedInstancesPara = & tke.ExistedInstancesPara {}
1367+ inst .ExistedInstancesPara .InstanceIds = make ([]* string , 0 )
1368+ for _ , v := range instanceIds {
1369+ inst .ExistedInstancesPara .InstanceIds = append (inst .ExistedInstancesPara .InstanceIds , helper .String (v .(string )))
1370+ }
1371+ }
1372+ }
1373+ if temp , ok := dMap ["desired_pod_numbers" ]; ok {
1374+ inst .DesiredPodNumbers = make ([]* int64 , 0 )
1375+ podNums := temp .([]interface {})
1376+ for _ , v := range podNums {
1377+ inst .DesiredPodNumbers = append (inst .DesiredPodNumbers , helper .Int64 (int64 (v .(int ))))
1378+ }
1379+ }
1380+ if temp , ok := dMap ["node_role" ]; ok {
1381+ nodeRole := temp .(string )
1382+ inst .NodeRole = & nodeRole
1383+ }
1384+
1385+ return inst , nil
1386+ }
1387+
12831388func tkeGetNodePoolGlobalConfig (d * schema.ResourceData ) * tke.ModifyClusterAsGroupOptionAttributeRequest {
12841389 request := tke .NewModifyClusterAsGroupOptionAttributeRequest ()
12851390 request .ClusterId = helper .String (d .Id ())
@@ -1435,12 +1540,6 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
14351540
14361541 basic .ClusterOsType = d .Get ("cluster_os_type" ).(string )
14371542
1438- if basic .ClusterOsType == TKE_CLUSTER_OS_TYPE_DOCKER_CUSTOMIZE {
1439- if cluster_os != TKE_CLUSTER_OS_UBUNTU18 && cluster_os != TKE_CLUSTER_OS_CENTOS76 {
1440- return fmt .Errorf ("Only 'centos7.6x86_64' or 'ubuntu18.04.1 LTSx86_64' support 'DOCKER_CUSTOMIZE' now, can not be " + basic .ClusterOs )
1441- }
1442- }
1443-
14441543 basic .ClusterVersion = d .Get ("cluster_version" ).(string )
14451544 if v , ok := d .GetOk ("cluster_name" ); ok {
14461545 basic .ClusterName = v .(string )
@@ -1457,6 +1556,10 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
14571556 advanced .IsNonStaticIpMode = d .Get ("is_non_static_ip_mode" ).(bool )
14581557 advanced .DeletionProtection = d .Get ("deletion_protection" ).(bool )
14591558 advanced .KubeProxyMode = d .Get ("kube_proxy_mode" ).(string )
1559+ advanced .EnableCustomizedPodCIDR = d .Get ("enable_customized_pod_cidr" ).(bool )
1560+ if v , ok := d .GetOk ("base_pod_num" ); ok {
1561+ advanced .BasePodNumber = int64 (v .(int ))
1562+ }
14601563
14611564 if extraArgs , ok := d .GetOk ("cluster_extra_args" ); ok {
14621565 extraArgList := extraArgs .([]interface {})
@@ -1520,6 +1623,7 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15201623 }
15211624 }
15221625
1626+ overrideSettings := make ([]tke.InstanceAdvancedSettings , 0 )
15231627 if masters , ok := d .GetOk ("master_config" ); ok {
15241628 if clusterDeployType == TKE_DEPLOY_TYPE_MANAGED {
15251629 return fmt .Errorf ("if `cluster_deploy_type` is `MANAGED_CLUSTER` , You don't need define the master yourself" )
@@ -1535,6 +1639,13 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15351639
15361640 cvms .Master = append (cvms .Master , paraJson )
15371641 masterCount += count
1642+
1643+ if v , ok := master ["desired_pod_num" ]; ok {
1644+ dpNum := int64 (v .(int ))
1645+ if dpNum != - 1 {
1646+ overrideSettings = append (overrideSettings , tke.InstanceAdvancedSettings {DesiredPodNumber : helper .Int64 (dpNum )})
1647+ }
1648+ }
15381649 }
15391650 if masterCount < 3 {
15401651 return fmt .Errorf ("if `cluster_deploy_type` is `TKE_DEPLOY_TYPE_INDEPENDENT` len(master_config) should >=3" )
@@ -1551,11 +1662,17 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15511662 for index := range workerList {
15521663 worker := workerList [index ].(map [string ]interface {})
15531664 paraJson , _ , err := tkeGetCvmRunInstancesPara (worker , meta , vpcId , basic .ProjectId )
1554-
15551665 if err != nil {
15561666 return err
15571667 }
15581668 cvms .Work = append (cvms .Work , paraJson )
1669+
1670+ if v , ok := worker ["desired_pod_num" ]; ok {
1671+ dpNum := int64 (v .(int ))
1672+ if dpNum != - 1 {
1673+ overrideSettings = append (overrideSettings , tke.InstanceAdvancedSettings {DesiredPodNumber : helper .Int64 (dpNum )})
1674+ }
1675+ }
15591676 }
15601677 }
15611678
@@ -1578,10 +1695,28 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15781695 if temp , ok := d .GetOk ("mount_target" ); ok {
15791696 iAdvanced .MountTarget = temp .(string )
15801697 }
1698+ if temp , ok := d .GetOk ("globe_desired_pod_num" ); ok {
1699+ iAdvanced .DesiredPodNum = int64 (temp .(int ))
1700+ }
15811701
1582- service := TkeService {client : meta .(* TencentCloudClient ).apiV3Conn }
1702+ // ExistedInstancesForNode
1703+ existIntances := make ([]* tke.ExistedInstancesForNode , 0 )
1704+ if instances , ok := d .GetOk ("exist_instance" ); ok {
1705+ instanceList := instances .([]interface {})
1706+ for index := range instanceList {
1707+ instance := instanceList [index ].(map [string ]interface {})
1708+ existedInstance , _ := tkeGetCvmExistInstancesPara (instance )
1709+ existIntances = append (existIntances , & existedInstance )
1710+ }
1711+ }
1712+
1713+ // RunInstancesForNode(master_config+worker_config) 和 ExistedInstancesForNode 不能同时存在
1714+ if len (cvms .Master )+ len (cvms .Work ) > 0 && len (existIntances ) > 0 {
1715+ return fmt .Errorf ("master_config+worker_config and exist_instance can not exist at the same time" )
1716+ }
15831717
1584- id , err := service .CreateCluster (ctx , basic , advanced , cvms , iAdvanced , cidrSet , tags )
1718+ service := TkeService {client : meta .(* TencentCloudClient ).apiV3Conn }
1719+ id , err := service .CreateCluster (ctx , basic , advanced , cvms , iAdvanced , cidrSet , tags , existIntances , overrideSettings )
15851720 if err != nil {
15861721 return err
15871722 }
0 commit comments