Skip to content

Commit aa4bb93

Browse files
Implement boot disk config for Hyperdisk provisioned iops and throughput for container node_config resources. (#14600) (#23840)
[upstream:645934ebca8130252a9d836a431ef5b9677b7ee4] Signed-off-by: Modular Magician <[email protected]>
1 parent 32cc1e5 commit aa4bb93

File tree

4 files changed

+543
-5
lines changed

4 files changed

+543
-5
lines changed

.changelog/14600.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added `boot_disk` to `node_config` in `google_container_cluster` and `google_container_node_pool`
3+
```

google/services/container/node_config.go

Lines changed: 126 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ func schemaNodeConfig() *schema.Schema {
159159
Description: `Type of the disk attached to each node. Such as pd-standard, pd-balanced or pd-ssd`,
160160
},
161161

162+
"boot_disk": schemaBootDiskConfig(),
163+
162164
"guest_accelerator": {
163165
Type: schema.TypeList,
164166
Optional: true,
@@ -869,6 +871,45 @@ func schemaNodeConfig() *schema.Schema {
869871
}
870872
}
871873

874+
func schemaBootDiskConfig() *schema.Schema {
875+
return &schema.Schema{
876+
Type: schema.TypeList,
877+
Optional: true,
878+
Computed: true,
879+
MaxItems: 1,
880+
Description: `Boot disk configuration for node pools nodes.`,
881+
Elem: &schema.Resource{
882+
Schema: map[string]*schema.Schema{
883+
"disk_type": {
884+
Type: schema.TypeString,
885+
Optional: true,
886+
Computed: true,
887+
Description: `Type of the disk attached to each node. Such as pd-standard, pd-balanced or pd-ssd`,
888+
},
889+
"size_gb": {
890+
Type: schema.TypeInt,
891+
Optional: true,
892+
Computed: true,
893+
ValidateFunc: validation.IntAtLeast(10),
894+
Description: `Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB.`,
895+
},
896+
"provisioned_iops": {
897+
Type: schema.TypeInt,
898+
Optional: true,
899+
Computed: true,
900+
Description: `Configured IOPs provisioning. Only valid with disk type hyperdisk-balanced.`,
901+
},
902+
"provisioned_throughput": {
903+
Type: schema.TypeInt,
904+
Optional: true,
905+
Computed: true,
906+
Description: `Configured throughput provisioning. Only valid with disk type hyperdisk-balanced.`,
907+
},
908+
},
909+
},
910+
}
911+
}
912+
872913
// Separate since this currently only supports a single value -- a subset of
873914
// the overall NodeKubeletConfig
874915
func schemaNodePoolAutoConfigNodeKubeletConfig() *schema.Schema {
@@ -1004,6 +1045,10 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
10041045
nc.DiskType = v.(string)
10051046
}
10061047

1048+
if v, ok := nodeConfig["boot_disk"]; ok {
1049+
nc.BootDisk = expandBootDiskConfig(v)
1050+
}
1051+
10071052
if v, ok := nodeConfig["local_ssd_count"]; ok {
10081053
nc.LocalSsdCount = int64(v.(int))
10091054
}
@@ -1255,6 +1300,36 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
12551300
return nc
12561301
}
12571302

1303+
func expandBootDiskConfig(v interface{}) *container.BootDisk {
1304+
bd := &container.BootDisk{}
1305+
if v == nil {
1306+
return nil
1307+
}
1308+
ls := v.([]interface{})
1309+
if len(ls) == 0 {
1310+
return nil
1311+
}
1312+
cfg := ls[0].(map[string]interface{})
1313+
1314+
if v, ok := cfg["disk_type"]; ok {
1315+
bd.DiskType = v.(string)
1316+
}
1317+
1318+
if v, ok := cfg["size_gb"]; ok {
1319+
bd.SizeGb = int64(v.(int))
1320+
}
1321+
1322+
if v, ok := cfg["provisioned_iops"]; ok {
1323+
bd.ProvisionedIops = int64(v.(int))
1324+
}
1325+
1326+
if v, ok := cfg["provisioned_throughput"]; ok {
1327+
bd.ProvisionedThroughput = int64(v.(int))
1328+
}
1329+
1330+
return bd
1331+
}
1332+
12581333
func expandResourceManagerTags(v interface{}) *container.ResourceManagerTags {
12591334
if v == nil {
12601335
return nil
@@ -1617,6 +1692,7 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
16171692
"containerd_config": flattenContainerdConfig(c.ContainerdConfig),
16181693
"disk_size_gb": c.DiskSizeGb,
16191694
"disk_type": c.DiskType,
1695+
"boot_disk": flattenBootDiskConfig(c.BootDisk),
16201696
"guest_accelerator": flattenContainerGuestAccelerators(c.Accelerators),
16211697
"local_ssd_count": c.LocalSsdCount,
16221698
"logging_variant": flattenLoggingVariant(c.LoggingConfig),
@@ -1663,6 +1739,23 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
16631739
return config
16641740
}
16651741

1742+
func flattenBootDiskConfig(c *container.BootDisk) []map[string]interface{} {
1743+
config := []map[string]interface{}{}
1744+
1745+
if c == nil {
1746+
return config
1747+
}
1748+
1749+
config = append(config, map[string]interface{}{
1750+
"disk_type": c.DiskType,
1751+
"size_gb": c.SizeGb,
1752+
"provisioned_iops": c.ProvisionedIops,
1753+
"provisioned_throughput": c.ProvisionedThroughput,
1754+
})
1755+
1756+
return config
1757+
}
1758+
16661759
func flattenResourceManagerTags(c *container.ResourceManagerTags) map[string]interface{} {
16671760
if c == nil {
16681761
return nil
@@ -2171,7 +2264,9 @@ func nodePoolNodeConfigUpdate(d *schema.ResourceData, config *transport_tpg.Conf
21712264
if d.HasChange("node_config.0.disk_size_gb") ||
21722265
d.HasChange("node_config.0.disk_type") ||
21732266
d.HasChange("node_config.0.machine_type") ||
2174-
d.HasChange("node_config.0.storage_pools") {
2267+
d.HasChange("node_config.0.storage_pools") ||
2268+
d.HasChange("node_config.0.boot_disk") {
2269+
21752270
req := &container.UpdateNodePoolRequest{
21762271
Name: name,
21772272
DiskSizeGb: int64(d.Get("node_config.0.disk_size_gb").(int)),
@@ -2189,6 +2284,34 @@ func nodePoolNodeConfigUpdate(d *schema.ResourceData, config *transport_tpg.Conf
21892284
req.StoragePools = storagePools
21902285
}
21912286

2287+
if v, ok := d.GetOk("node_config.0.boot_disk"); ok {
2288+
bd := expandBootDiskConfig(v)
2289+
req.BootDisk = bd
2290+
2291+
// The following checks are to ensure that the migrating fields are handled properly.
2292+
// Migrating fields are disk_type -> boot_disk.disk_type and disk_size_gb -> boot_disk.size_gb
2293+
// If the legacy (top level) disk_type field is not changing, nil it out to allow the API to fill it in.
2294+
legacyDiskTypeOld, legacyDiskTypeNew := d.GetChange("node_config.0.disk_type")
2295+
if legacyDiskTypeOld == legacyDiskTypeNew {
2296+
req.DiskType = ""
2297+
}
2298+
// If the new boot disk configuration disk_filed is not changing, nil it out to allow the API to fill it in.
2299+
bootDiskTypeOld, bootDiskTypeNew := d.GetChange("node_config.0.boot_disk.0.disk_type")
2300+
if bootDiskTypeOld == bootDiskTypeNew {
2301+
req.BootDisk.DiskType = ""
2302+
}
2303+
// If the legacy (top level) disk_size_gb field is not changing, nil it out to allow the API to fill it in.
2304+
legacyDiskSizeGbOld, legacyDiskSizeGbNew := d.GetChange("node_config.0.disk_size_gb")
2305+
if legacyDiskSizeGbOld == legacyDiskSizeGbNew {
2306+
req.DiskSizeGb = 0
2307+
}
2308+
// if the new boot disk configuration size_gb field is not changing, nil it out to allow the API to fill it in.
2309+
bootDiskSizeGbOld, bootDiskSizeGbNew := d.GetChange("node_config.0.boot_disk.0.size_gb")
2310+
if bootDiskSizeGbOld == bootDiskSizeGbNew {
2311+
req.BootDisk.SizeGb = 0
2312+
}
2313+
}
2314+
21922315
updateF := func() error {
21932316
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(name), req)
21942317
if config.UserProjectOverride {
@@ -2203,14 +2326,14 @@ func nodePoolNodeConfigUpdate(d *schema.ResourceData, config *transport_tpg.Conf
22032326
return ContainerOperationWait(config, op,
22042327
nodePoolInfo.project,
22052328
nodePoolInfo.location,
2206-
"updating GKE node pool disk_size_gb/disk_type/machine_type/storage_pools", userAgent,
2329+
"updating GKE node pool disk_size_gb/disk_type/machine_type/storage_pools/boot_disk", userAgent,
22072330
timeout)
22082331
}
22092332

22102333
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
22112334
return err
22122335
}
2213-
log.Printf("[INFO] Updated disk disk_size_gb/disk_type/machine_type/storage_pools for Node Pool %s", d.Id())
2336+
log.Printf("[INFO] Updated disk disk_size_gb/disk_type/machine_type/storage_pools/boot_disk for Node Pool %s", d.Id())
22142337
}
22152338

22162339
if d.HasChange(prefix + "node_config.0.taint") {

0 commit comments

Comments
 (0)