Skip to content

Commit 1e3c869

Browse files
authored
Fix/nodepool disk encrypt (#1195)
* feat: nodepool - data disk support encrypt end throuput performance * fix: np - node os deprecated replace
1 parent 71940d5 commit 1e3c869

File tree

12 files changed

+2303
-786
lines changed

12 files changed

+2303
-786
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.358
2424
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285
2525
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.199
26-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.363
26+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.466
2727
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409
2828
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.199
2929
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.409

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285 h1:gFmukRG
434434
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285/go.mod h1:aGlXSWjtSnE6kuqcaRy/NKj1CLiB8NlMSHGsDn+k7Ag=
435435
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.199 h1:e9M5HSIq2xw61Oz9whoaq+QT95rZtowkY/2zhdzx9v4=
436436
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.199/go.mod h1:ynirFavajqWLAcgEp9ZiMd9xn5JnKTJhQisArjMxNtk=
437-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.363 h1:Js8YGmBRRjEdjGaAgfugq8e6lI5d21Eiid22wU/QpNQ=
438-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.363/go.mod h1:ic2rqJIJObd0d/VnIHwQWdwZQe8oWSEOzG1lcx8TG0M=
437+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.466 h1:JnE62AvMprCOe1/cnLJvjgeBoUOGxhdc0DG2mhs8cjo=
438+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.466/go.mod h1:NBTNnh4SpOTGvr69Ttt4ABQplvwt6eEZXSmO5f9Anf0=
439439
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409 h1:ToZpNh78SVdKakkeR9YV1a65tjtC4NJl+hrJqTuhO3g=
440440
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409/go.mod h1:U24yUxCDruJLayOsP/onO2E/7+9ljeNsNO+phu+PeiM=
441441
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.199 h1:MkIdFgEGF+baYAU9Z/PUmudfuamCGtLsedQpopwyHNU=
@@ -456,7 +456,6 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412 h1:mQbC16t
456456
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412/go.mod h1:xU6edJlUvcW4ffnVhE+BLlwOsU6LGzQPdEcAJGC18Fo=
457457
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.194/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
458458
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.358/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
459-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.363/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
460459
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.383/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
461460
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.391/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
462461
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.397/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
@@ -483,8 +482,6 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.490 h1:mmz2
483482
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.490/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
484483
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445 h1:Bh7XD0ypNMHYyBOM8hhKsSu+y0VVKUnJVS+YKKhfpGg=
485484
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445/go.mod h1:jMDD351efCFpT1+KVFbcpu6SbmP4TYmp4qkoCfr63nQ=
486-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359 h1:cNKqelPgUxrJkLY0Azd2QHr/UMYOPPnmqs88clt2akk=
487-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359/go.mod h1:GlTYjlrf8EKEMu+Z2MXfaM2/nHGUBBF/huBBJqGyGwI=
488485
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.488 h1:A1seXWtMf2atBjSNYvcwxyDoFzCMgqyVnsxnWzhqJEA=
489486
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.488/go.mod h1:T8mL4dQLkPTL6VtVMeBYol3asSUS53ycP9PJf5Qp1GE=
490487
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335 h1:D8qrelkK5udv8RzJJIABMzItGIyaZoYnxEVeIsYqiNw=
@@ -753,13 +750,16 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
753750
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
754751
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
755752
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
753+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
756754
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
757755
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
758756
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
757+
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
759758
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
760759
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
761760
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
762761
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
762+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
763763
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
764764
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
765765
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

tencentcloud/basic_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ const (
9595
defaultTkeOSImageName = "tlinux2.2(tkernel3)x86_64"
9696
)
9797

98+
// Project
99+
const defaultProjectVariable = `
100+
variable "default_project" {
101+
default = ` + defaultProjectId + `
102+
}
103+
`
104+
98105
// EMR
99106
const (
100107
defaultEMRVpcId = defaultVpcId
@@ -642,7 +649,7 @@ variable "tke_cidr_c" {
642649

643650
const TkeDefaultNodeInstanceVar = `
644651
variable "ins_type" {
645-
default = "S5.MEDIUM4"
652+
default = "SA2.LARGE8"
646653
}
647654
`
648655

tencentcloud/resource_tc_kubernetes_cluster_endpoint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
154154
155155
}
156156
unschedulable = 0
157-
node_os="Tencent tlinux release 2.2 (Final)"
157+
node_os="tlinux2.2(tkernel3)x86_64"
158158
}
159159
160160
`

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 95 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,17 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
215215
Elem: &schema.Resource{
216216
Schema: map[string]*schema.Schema{
217217
"disk_type": {
218-
Type: schema.TypeString,
219-
Optional: true,
220-
ForceNew: true,
218+
Type: schema.TypeString,
219+
Optional: true,
220+
//ForceNew: true,
221221
Default: SYSTEM_DISK_TYPE_CLOUD_PREMIUM,
222222
ValidateFunc: validateAllowedStringValue(SYSTEM_DISK_ALLOW_TYPE),
223223
Description: "Types of disk. Valid value: `CLOUD_PREMIUM` and `CLOUD_SSD`.",
224224
},
225225
"disk_size": {
226-
Type: schema.TypeInt,
227-
Optional: true,
228-
ForceNew: true,
226+
Type: schema.TypeInt,
227+
Optional: true,
228+
//ForceNew: true,
229229
Default: 0,
230230
Description: "Volume of disk in GB. Default is `0`.",
231231
},
@@ -240,6 +240,16 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
240240
Optional: true,
241241
Description: "Indicates whether the disk remove after instance terminated.",
242242
},
243+
"encrypt": {
244+
Type: schema.TypeBool,
245+
Optional: true,
246+
Description: "Specify whether to encrypt data disk, default: false. NOTE: Make sure the instance type is offering and the cam role `QcloudKMSAccessForCVMRole` was provided.",
247+
},
248+
"throughput_performance": {
249+
Type: schema.TypeInt,
250+
Optional: true,
251+
Description: "Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD` and `data_size` > 460GB.",
252+
},
243253
},
244254
},
245255
},
@@ -487,6 +497,11 @@ func ResourceTencentCloudKubernetesNodePool() *schema.Resource {
487497
Default: true,
488498
Description: "Indicate to keep the CVM instance when delete the node pool. Default is `true`.",
489499
},
500+
//"deletion_protection": {
501+
// Type: schema.TypeBool,
502+
// Optional: true,
503+
// Description: "Indicates whether the node pool deletion protection is enabled.",
504+
//},
490505
"node_os": {
491506
Type: schema.TypeString,
492507
Optional: true,
@@ -651,6 +666,8 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
651666
diskSize := uint64(value["disk_size"].(int))
652667
snapshotId := value["snapshot_id"].(string)
653668
deleteWithInstance, dOk := value["delete_with_instance"].(bool)
669+
encrypt, eOk := value["encrypt"].(bool)
670+
throughputPerformance := value["throughput_performance"].(int)
654671
dataDisk := as.DataDisk{
655672
DiskType: &diskType,
656673
}
@@ -663,6 +680,12 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
663680
if dOk {
664681
dataDisk.DeleteWithInstance = &deleteWithInstance
665682
}
683+
if eOk {
684+
dataDisk.Encrypt = &encrypt
685+
}
686+
if throughputPerformance > 0 {
687+
dataDisk.ThroughputPerformance = helper.IntUint64(throughputPerformance)
688+
}
666689
request.DataDisks = append(request.DataDisks, &dataDisk)
667690
}
668691
}
@@ -795,6 +818,8 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
795818
diskSize := uint64(value["disk_size"].(int))
796819
snapshotId := value["snapshot_id"].(string)
797820
deleteWithInstance, dOk := value["delete_with_instance"].(bool)
821+
encrypt, eOk := value["encrypt"].(bool)
822+
throughputPerformance := value["throughput_performance"].(int)
798823
dataDisk := as.DataDisk{
799824
DiskType: &diskType,
800825
}
@@ -807,6 +832,12 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
807832
if dOk {
808833
dataDisk.DeleteWithInstance = &deleteWithInstance
809834
}
835+
if eOk {
836+
dataDisk.Encrypt = &encrypt
837+
}
838+
if throughputPerformance > 0 {
839+
dataDisk.ThroughputPerformance = helper.IntUint64(throughputPerformance)
840+
}
810841
request.DataDisks = append(request.DataDisks, &dataDisk)
811842
}
812843
} else {
@@ -871,6 +902,13 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
871902
return request
872903
}
873904

905+
func desiredCapacityOutRange(d *schema.ResourceData) bool {
906+
capacity := d.Get("desired_capacity").(int)
907+
minSize := d.Get("min_size").(int)
908+
maxSize := d.Get("max_size").(int)
909+
return capacity > maxSize || capacity < minSize
910+
}
911+
874912
func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) error {
875913
defer logElapsed("resource.tencentcloud_kubernetes_node_pool.read")()
876914

@@ -967,6 +1005,10 @@ func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) er
9671005
_ = d.Set("node_os_type", nodePool.OsCustomizeType)
9681006
}
9691007

1008+
//if nodePool.DeletionProtection != nil {
1009+
// _ = d.Set("deletion_protection", nodePool.DeletionProtection)
1010+
//}
1011+
9701012
//set composed struct
9711013
lables := make(map[string]interface{}, len(nodePool.Labels))
9721014
for _, v := range nodePool.Labels {
@@ -1031,6 +1073,12 @@ func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) er
10311073
if item.DeleteWithInstance != nil {
10321074
disk["delete_with_instance"] = *item.DeleteWithInstance
10331075
}
1076+
if item.Encrypt != nil {
1077+
disk["encrypt"] = *item.Encrypt
1078+
}
1079+
if item.ThroughputPerformance != nil {
1080+
disk["throughput_performance"] = *item.ThroughputPerformance
1081+
}
10341082
dataDisks = append(dataDisks, disk)
10351083
}
10361084
launchConfig["data_disk"] = dataDisks
@@ -1155,6 +1203,8 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
11551203
nodeOs := d.Get("node_os").(string)
11561204
nodeOsType := d.Get("node_os_type").(string)
11571205

1206+
//deletionProtection := d.Get("deletion_protection").(bool)
1207+
11581208
service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
11591209

11601210
nodePoolId, err := service.CreateClusterNodePool(ctx, clusterId, name, groupParaStr, configParaStr, enableAutoScale, nodeOs, nodeOsType, labels, taints, iAdvanced)
@@ -1233,11 +1283,43 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12331283
d.SetPartial("auto_scaling_config")
12341284
}
12351285

1286+
var capacityHasChanged = false
1287+
// assuming
1288+
// min 1 max 6 desired 2
1289+
// to
1290+
// min 3 max 6 desired 5
1291+
// modify min/max first will cause error, this case must upgrade desired first
1292+
if d.HasChange("desired_capacity") || !desiredCapacityOutRange(d) {
1293+
desiredCapacity := int64(d.Get("desired_capacity").(int))
1294+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
1295+
errRet := service.ModifyClusterNodePoolDesiredCapacity(ctx, clusterId, nodePoolId, desiredCapacity)
1296+
if errRet != nil {
1297+
return retryError(errRet)
1298+
}
1299+
return nil
1300+
})
1301+
if err != nil {
1302+
return err
1303+
}
1304+
capacityHasChanged = true
1305+
}
1306+
12361307
// ModifyClusterNodePool
1237-
if d.HasChange("min_size") || d.HasChange("max_size") || d.HasChange("name") || d.HasChange("labels") || d.HasChange("taints") || d.HasChange("enable_auto_scale") || d.HasChange("node_os_type") || d.HasChange("node_os") {
1308+
if d.HasChanges(
1309+
"min_size",
1310+
"max_size",
1311+
"name",
1312+
"labels",
1313+
"taints",
1314+
//"deletion_protection",
1315+
"enable_auto_scale",
1316+
"node_os_type",
1317+
"node_os",
1318+
) {
12381319
maxSize := int64(d.Get("max_size").(int))
12391320
minSize := int64(d.Get("min_size").(int))
12401321
enableAutoScale := d.Get("enable_auto_scale").(bool)
1322+
//deletionProtection := d.Get("deletion_protection").(bool)
12411323
name := d.Get("name").(string)
12421324
nodeOs := d.Get("node_os").(string)
12431325
nodeOsType := d.Get("node_os_type").(string)
@@ -1253,14 +1335,6 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12531335
if err != nil {
12541336
return err
12551337
}
1256-
d.SetPartial("min_size")
1257-
d.SetPartial("max_size")
1258-
d.SetPartial("name")
1259-
d.SetPartial("enable_auto_scale")
1260-
d.SetPartial("node_os")
1261-
d.SetPartial("node_os_type")
1262-
d.SetPartial("labels")
1263-
d.SetPartial("taints")
12641338
}
12651339

12661340
// ModifyScalingGroup
@@ -1329,7 +1403,7 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
13291403
d.SetPartial("termination_policies")
13301404
}
13311405

1332-
if d.HasChange("desired_capacity") {
1406+
if d.HasChange("desired_capacity") && !capacityHasChanged {
13331407
desiredCapacity := int64(d.Get("desired_capacity").(int))
13341408
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
13351409
errRet := service.ModifyClusterNodePoolDesiredCapacity(ctx, clusterId, nodePoolId, desiredCapacity)
@@ -1341,7 +1415,6 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
13411415
if err != nil {
13421416
return err
13431417
}
1344-
d.SetPartial("desired_capacity")
13451418
}
13461419

13471420
if d.HasChange("auto_scaling_config.0.backup_instance_types") {
@@ -1372,13 +1445,18 @@ func resourceKubernetesNodePoolDelete(d *schema.ResourceData, meta interface{})
13721445
service = TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
13731446
items = strings.Split(d.Id(), FILED_SP)
13741447
deleteKeepInstance = d.Get("delete_keep_instance").(bool)
1448+
//deletionProtection = d.Get("deletion_protection").(bool)
13751449
)
13761450
if len(items) != 2 {
13771451
return fmt.Errorf("resource_tc_kubernetes_node_pool id is broken")
13781452
}
13791453
clusterId := items[0]
13801454
nodePoolId := items[1]
13811455

1456+
//if deletionProtection {
1457+
// return fmt.Errorf("deletion protection was enabled, please set `deletion_protection` to `false` and apply first")
1458+
//}
1459+
13821460
//delete as group
13831461
hasDelete := false
13841462
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {

0 commit comments

Comments
 (0)