@@ -549,9 +549,56 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
549549 Elem : & schema.Schema {Type : schema .TypeString },
550550 Description : "Disaster recover groups to which a CVM instance belongs. Only support maximum 1." ,
551551 },
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+ },
552598 }
553599}
554600
601+
555602func TkeNodePoolGlobalConfig () map [string ]* schema.Schema {
556603 return map [string ]* schema.Schema {
557604 "is_scale_in_enabled" : {
@@ -627,9 +674,9 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
627674 Type : schema .TypeString ,
628675 ForceNew : true ,
629676 Optional : true ,
630- Default : TKE_CLUSTER_OS_UBUNTU16 ,
677+ Default : TKE_CLUSTER_OS_LINUX24 ,
631678 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 + "'." ,
633680 },
634681 "cluster_os_type" : {
635682 Type : schema .TypeString ,
@@ -739,6 +786,19 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
739786 ValidateFunc : validateAllowedStringValue (TKE_CLUSTER_NETWORK_TYPE ),
740787 Description : "Cluster network type, GR or VPC-CNI. Default is GR." ,
741788 },
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+ },
742802 "is_non_static_ip_mode" : {
743803 Type : schema .TypeBool ,
744804 ForceNew : true ,
@@ -958,6 +1018,15 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
9581018 },
9591019 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'." ,
9601020 },
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+ },
9611030 "tags" : {
9621031 Type : schema .TypeMap ,
9631032 Optional : true ,
@@ -1005,6 +1074,12 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
10051074 ForceNew : true ,
10061075 Description : "Mount target. Default is not mounting." ,
10071076 },
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+ },
10081083 "docker_graph_path" : {
10091084 Type : schema .TypeString ,
10101085 Optional : true ,
@@ -1269,6 +1344,37 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
12691344 return
12701345}
12711346
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+
12721378func tkeGetNodePoolGlobalConfig (d * schema.ResourceData ) * tke.ModifyClusterAsGroupOptionAttributeRequest {
12731379 request := tke .NewModifyClusterAsGroupOptionAttributeRequest ()
12741380 request .ClusterId = helper .String (d .Id ())
@@ -1424,12 +1530,6 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
14241530
14251531 basic .ClusterOsType = d .Get ("cluster_os_type" ).(string )
14261532
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-
14331533 basic .ClusterVersion = d .Get ("cluster_version" ).(string )
14341534 if v , ok := d .GetOk ("cluster_name" ); ok {
14351535 basic .ClusterName = v .(string )
@@ -1446,6 +1546,10 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
14461546 advanced .IsNonStaticIpMode = d .Get ("is_non_static_ip_mode" ).(bool )
14471547 advanced .DeletionProtection = d .Get ("deletion_protection" ).(bool )
14481548 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+ }
14491553
14501554 if extraArgs , ok := d .GetOk ("cluster_extra_args" ); ok {
14511555 extraArgList := extraArgs .([]interface {})
@@ -1509,6 +1613,7 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15091613 }
15101614 }
15111615
1616+ overrideSettings := make ([]tke.InstanceAdvancedSettings , 0 )
15121617 if masters , ok := d .GetOk ("master_config" ); ok {
15131618 if clusterDeployType == TKE_DEPLOY_TYPE_MANAGED {
15141619 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
15241629
15251630 cvms .Master = append (cvms .Master , paraJson )
15261631 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+ }
15271639 }
15281640 if masterCount < 3 {
15291641 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
15401652 for index := range workerList {
15411653 worker := workerList [index ].(map [string ]interface {})
15421654 paraJson , _ , err := tkeGetCvmRunInstancesPara (worker , meta , vpcId , basic .ProjectId )
1543-
15441655 if err != nil {
15451656 return err
15461657 }
15471658 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+ }
15481666 }
15491667 }
15501668
@@ -1567,10 +1685,28 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
15671685 if temp , ok := d .GetOk ("mount_target" ); ok {
15681686 iAdvanced .MountTarget = temp .(string )
15691687 }
1688+ if temp , ok := d .GetOk ("globe_desired_pod_num" ); ok {
1689+ iAdvanced .DesiredPodNum = int64 (temp .(int ))
1690+ }
15701691
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+ }
15721707
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 )
15741710 if err != nil {
15751711 return err
15761712 }
0 commit comments