Skip to content

Commit e0bd653

Browse files
authored
Merge pull request #654 from tencentcloudstack/feat/tke-disk-mount-setting
feat: tke support worker data disk mount setting
2 parents 9a8d0af + 3722570 commit e0bd653

8 files changed

+111
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.58.1 (Aug 17, 2021)
2+
ENHANCEMENTS:
3+
* Resource `resource_tc_kubernetes_cluster.go` extend worker instance data disk mount settings
4+
15
## 1.58.0 (Aug 11, 2021)
26

37
FEATURES:

tencentcloud/resource_tc_container_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func resourceTencentCloudContainerClusterCreate(d *schema.ResourceData, meta int
449449
runInstancesParas := runInstancesPara.ToJsonString()
450450
cvms.Work = []string{runInstancesParas}
451451

452-
id, err := service.CreateCluster(ctx, basic, cAdvanced, cvms, iAdvanced, cidrSet, map[string]string{}, nil, nil)
452+
id, err := service.CreateCluster(ctx, basic, cAdvanced, cvms, iAdvanced, cidrSet, map[string]string{}, nil, nil, nil)
453453
if err != nil {
454454
return err
455455
}

tencentcloud/resource_tc_kubernetes_cluster.go

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
4343
cluster_internet = true
4444
managed_cluster_internet_security_policies = ["3.3.3.3", "1.1.1.1"]
4545
cluster_deploy_type = "MANAGED_CLUSTER"
46+
data_disk {
47+
disk_type = "CLOUD_PREMIUM"
48+
disk_size = 50
49+
}
4650
4751
worker_config {
4852
count = 1
@@ -460,6 +464,25 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
460464
Optional: true,
461465
Description: "Data disk snapshot ID.",
462466
},
467+
"file_system": {
468+
Type: schema.TypeString,
469+
ForceNew: true,
470+
Optional: true,
471+
Description: "File system, e.g. `ext3/ext4/xfs`.",
472+
},
473+
"auto_format_and_mount": {
474+
Type: schema.TypeBool,
475+
ForceNew: true,
476+
Optional: true,
477+
Default: true,
478+
Description: "Indicate whether to auto format and mount or not. Default is `false`.",
479+
},
480+
"mount_target": {
481+
Type: schema.TypeString,
482+
ForceNew: true,
483+
Optional: true,
484+
Description: "Mount target.",
485+
},
463486
},
464487
},
465488
},
@@ -1492,15 +1515,16 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
14921515
ctx := context.WithValue(context.TODO(), logIdKey, logId)
14931516

14941517
var (
1495-
basic ClusterBasicSetting
1496-
advanced ClusterAdvancedSettings
1497-
cvms RunInstancesForNode
1498-
iAdvanced InstanceAdvancedSettings
1499-
cidrSet ClusterCidrSettings
1500-
securityPolicies []string
1501-
clusterInternet = d.Get("cluster_internet").(bool)
1502-
clusterIntranet = d.Get("cluster_intranet").(bool)
1503-
intranetSubnetId = d.Get("cluster_intranet_subnet_id").(string)
1518+
basic ClusterBasicSetting
1519+
advanced ClusterAdvancedSettings
1520+
cvms RunInstancesForNode
1521+
iAdvanced InstanceAdvancedSettings
1522+
iDiskMountSettings []*tke.InstanceDataDiskMountSetting
1523+
cidrSet ClusterCidrSettings
1524+
securityPolicies []string
1525+
clusterInternet = d.Get("cluster_internet").(bool)
1526+
clusterIntranet = d.Get("cluster_intranet").(bool)
1527+
intranetSubnetId = d.Get("cluster_intranet_subnet_id").(string)
15041528
)
15051529

15061530
if temp, ok := d.GetOkExists("managed_cluster_internet_security_policies"); ok {
@@ -1686,6 +1710,46 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
16861710
overrideSettings.Work = append(overrideSettings.Work, tke.InstanceAdvancedSettings{DesiredPodNumber: helper.Int64(dpNum)})
16871711
}
16881712
}
1713+
1714+
if v, ok := worker["data_disk"]; ok {
1715+
var (
1716+
instanceType = worker["instance_type"].(string)
1717+
zone = worker["availability_zone"].(string)
1718+
)
1719+
iDiskMountSetting := &tke.InstanceDataDiskMountSetting{
1720+
InstanceType: &instanceType,
1721+
Zone: &zone,
1722+
}
1723+
1724+
diskList := v.([]interface{})
1725+
for _, d := range diskList {
1726+
var (
1727+
disk = d.(map[string]interface{})
1728+
diskType = disk["disk_type"].(string)
1729+
diskSize = int64(disk["disk_size"].(int))
1730+
fileSystem = disk["file_system"].(string)
1731+
autoFormatAndMount = disk["auto_format_and_mount"].(bool)
1732+
mountTarget = disk["mount_target"].(string)
1733+
)
1734+
1735+
dataDisk := &tke.DataDisk{
1736+
DiskType: &diskType,
1737+
DiskSize: &diskSize,
1738+
AutoFormatAndMount: &autoFormatAndMount,
1739+
}
1740+
1741+
if fileSystem != "" {
1742+
dataDisk.FileSystem = &fileSystem
1743+
}
1744+
if mountTarget != "" {
1745+
dataDisk.MountTarget = &mountTarget
1746+
}
1747+
1748+
iDiskMountSetting.DataDisks = append(iDiskMountSetting.DataDisks, dataDisk)
1749+
}
1750+
1751+
iDiskMountSettings = append(iDiskMountSettings, iDiskMountSetting)
1752+
}
16891753
}
16901754
}
16911755

@@ -1713,23 +1777,23 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
17131777
}
17141778

17151779
// ExistedInstancesForNode
1716-
existIntances := make([]*tke.ExistedInstancesForNode, 0)
1780+
existInstances := make([]*tke.ExistedInstancesForNode, 0)
17171781
if instances, ok := d.GetOk("exist_instance"); ok {
17181782
instanceList := instances.([]interface{})
17191783
for index := range instanceList {
17201784
instance := instanceList[index].(map[string]interface{})
17211785
existedInstance, _ := tkeGetCvmExistInstancesPara(instance)
1722-
existIntances = append(existIntances, &existedInstance)
1786+
existInstances = append(existInstances, &existedInstance)
17231787
}
17241788
}
17251789

17261790
// RunInstancesForNode(master_config+worker_config) 和 ExistedInstancesForNode 不能同时存在
1727-
if len(cvms.Master)+len(cvms.Work) > 0 && len(existIntances) > 0 {
1791+
if len(cvms.Master)+len(cvms.Work) > 0 && len(existInstances) > 0 {
17281792
return fmt.Errorf("master_config+worker_config and exist_instance can not exist at the same time")
17291793
}
17301794

17311795
service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
1732-
id, err := service.CreateCluster(ctx, basic, advanced, cvms, iAdvanced, cidrSet, tags, existIntances, &overrideSettings)
1796+
id, err := service.CreateCluster(ctx, basic, advanced, cvms, iAdvanced, cidrSet, tags, existInstances, &overrideSettings, iDiskMountSettings)
17331797
if err != nil {
17341798
return err
17351799
}

tencentcloud/service_tencentcloud_tke.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type InstanceAdvancedSettings struct {
6060
Unschedulable int64
6161
DesiredPodNum int64
6262
Labels []*tke.Label
63+
DataDisks []*tke.DataDisk
6364
ExtraArgs tke.InstanceExtraArgs
6465
}
6566

@@ -82,12 +83,13 @@ type ClusterInfo struct {
8283
}
8384

8485
type InstanceInfo struct {
85-
InstanceId string
86-
InstanceRole string
87-
InstanceState string
88-
FailedReason string
89-
InstanceAdvancedSettings *tke.InstanceAdvancedSettings
90-
LanIp string
86+
InstanceId string
87+
InstanceRole string
88+
InstanceState string
89+
FailedReason string
90+
InstanceAdvancedSettings *tke.InstanceAdvancedSettings
91+
InstanceDataDiskMountSetting *tke.InstanceDataDiskMountSetting
92+
LanIp string
9193
}
9294

9395
type TkeService struct {
@@ -395,6 +397,7 @@ func (me *TkeService) CreateCluster(ctx context.Context,
395397
tags map[string]string,
396398
existedInstance []*tke.ExistedInstancesForNode,
397399
overrideSettings *OverrideSettings,
400+
iDiskMountSettings []*tke.InstanceDataDiskMountSetting,
398401
) (id string, errRet error) {
399402

400403
logId := getLogId(ctx)
@@ -459,6 +462,10 @@ func (me *TkeService) CreateCluster(ctx context.Context,
459462
request.InstanceAdvancedSettings.Labels = iAdvanced.Labels
460463
}
461464

465+
if len(iAdvanced.DataDisks) > 0 {
466+
request.InstanceAdvancedSettings.DataDisks = iAdvanced.DataDisks
467+
}
468+
462469
if len(overrideSettings.Master)+len(overrideSettings.Work) > 0 &&
463470
len(overrideSettings.Master)+len(overrideSettings.Work) != (len(cvms.Master)+len(cvms.Work)) {
464471
return "", fmt.Errorf("len(overrideSettings) != (len(cvms.Master)+len(cvms.Work))")
@@ -497,6 +504,10 @@ func (me *TkeService) CreateCluster(ctx context.Context,
497504
request.RunInstancesForNode = append(request.RunInstancesForNode, &node)
498505
}
499506

507+
if len(iDiskMountSettings) != 0 {
508+
request.InstanceDataDiskMountSettings = iDiskMountSettings
509+
}
510+
500511
request.ClusterCIDRSettings = &tke.ClusterCIDRSettings{}
501512

502513
maxNodePodNum := uint64(cidrSetting.MaxNodePodNum)

website/docs/r/kubernetes_cluster.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
5353
cluster_internet = true
5454
managed_cluster_internet_security_policies = ["3.3.3.3", "1.1.1.1"]
5555
cluster_deploy_type = "MANAGED_CLUSTER"
56+
data_disk {
57+
disk_type = "CLOUD_PREMIUM"
58+
disk_size = 50
59+
}
5660
5761
worker_config {
5862
count = 1
@@ -329,8 +333,11 @@ The `cluster_extra_args` object supports the following:
329333

330334
The `data_disk` object supports the following:
331335

336+
* `auto_format_and_mount` - (Optional, ForceNew) Indicate whether to auto format and mount or not. Default is `false`.
332337
* `disk_size` - (Optional, ForceNew) Volume of disk in GB. Default is `0`.
333338
* `disk_type` - (Optional, ForceNew) Types of disk, available values: `CLOUD_PREMIUM` and `CLOUD_SSD` and `CLOUD_HSSD` and `CLOUD_TSSD`.
339+
* `file_system` - (Optional, ForceNew) File system, e.g. `ext3/ext4/xfs`.
340+
* `mount_target` - (Optional, ForceNew) Mount target.
334341
* `snapshot_id` - (Optional, ForceNew) Data disk snapshot ID.
335342

336343
The `exist_instance` object supports the following:

website/docs/r/kubernetes_scale_worker.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ The `data_disk` object supports the following:
134134

135135
The `data_disk` object supports the following:
136136

137+
* `auto_format_and_mount` - (Optional, ForceNew) Indicate whether to auto format and mount or not. Default is `false`.
137138
* `disk_size` - (Optional, ForceNew) Volume of disk in GB. Default is `0`.
138139
* `disk_type` - (Optional, ForceNew) Types of disk, available values: `CLOUD_PREMIUM` and `CLOUD_SSD` and `CLOUD_HSSD` and `CLOUD_TSSD`.
140+
* `file_system` - (Optional, ForceNew) File system, e.g. `ext3/ext4/xfs`.
141+
* `mount_target` - (Optional, ForceNew) Mount target.
139142
* `snapshot_id` - (Optional, ForceNew) Data disk snapshot ID.
140143

141144
The `worker_config` object supports the following:

website/docs/r/mysql_instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The following arguments are supported:
5656
* `auto_renew_flag` - (Optional) Auto renew flag. NOTES: Only supported prepaid instance.
5757
* `availability_zone` - (Optional, ForceNew) Indicates which availability zone will be used.
5858
* `charge_type` - (Optional, ForceNew) Pay type of instance. Valid values:`PREPAID`, `POSTPAID`. Default is `POSTPAID`.
59+
* `cpu` - (Optional) CPU cores.
5960
* `engine_version` - (Optional, ForceNew) The version number of the database engine to use. Supported versions include 5.5/5.6/5.7/8.0, and default is 5.7.
6061
* `first_slave_zone` - (Optional, ForceNew) Zone information about first slave instance.
6162
* `force_delete` - (Optional) Indicate whether to delete instance directly or not. Default is `false`. If set true, the instance will be deleted instead of staying recycle bin. Note: only works for `PREPAID` instance. When the main mysql instance set true, this para of the readonly mysql instance will not take effect.

website/docs/r/mysql_readonly_instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The following arguments are supported:
4242
* `volume_size` - (Required) Disk size (in GB).
4343
* `auto_renew_flag` - (Optional) Auto renew flag. NOTES: Only supported prepaid instance.
4444
* `charge_type` - (Optional, ForceNew) Pay type of instance. Valid values:`PREPAID`, `POSTPAID`. Default is `POSTPAID`.
45+
* `cpu` - (Optional) CPU cores.
4546
* `force_delete` - (Optional) Indicate whether to delete instance directly or not. Default is `false`. If set true, the instance will be deleted instead of staying recycle bin. Note: only works for `PREPAID` instance. When the main mysql instance set true, this para of the readonly mysql instance will not take effect.
4647
* `intranet_port` - (Optional) Public access port. Valid value ranges: [1024~65535]. The default value is `3306`.
4748
* `pay_type` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Please use `charge_type` instead. Pay type of instance. Valid values: `0`, `1`. `0`: prepaid, `1`: postpaid.

0 commit comments

Comments
 (0)