Skip to content

Commit 0f9e1ef

Browse files
Promote node system config to GA (#6975) (#13423)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 5b51259 commit 0f9e1ef

File tree

5 files changed

+365
-2
lines changed

5 files changed

+365
-2
lines changed

.changelog/6975.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: promoted node system config in `google_container_node_pool` to GA
3+
```

google/node_config.go

+122
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,51 @@ func schemaNodeConfig() *schema.Schema {
376376
ForceNew: true,
377377
Description: `The Customer Managed Encryption Key used to encrypt the boot disk attached to each node in the node pool.`,
378378
},
379+
// Note that AtLeastOneOf can't be set because this schema is reused by
380+
// two different resources.
381+
"kubelet_config": {
382+
Type: schema.TypeList,
383+
Optional: true,
384+
MaxItems: 1,
385+
Description: `Node kubelet configs.`,
386+
Elem: &schema.Resource{
387+
Schema: map[string]*schema.Schema{
388+
"cpu_manager_policy": {
389+
Type: schema.TypeString,
390+
Required: true,
391+
ValidateFunc: validation.StringInSlice([]string{"static", "none", ""}, false),
392+
Description: `Control the CPU management policy on the node.`,
393+
},
394+
"cpu_cfs_quota": {
395+
Type: schema.TypeBool,
396+
Optional: true,
397+
Description: `Enable CPU CFS quota enforcement for containers that specify CPU limits.`,
398+
},
399+
"cpu_cfs_quota_period": {
400+
Type: schema.TypeString,
401+
Optional: true,
402+
Description: `Set the CPU CFS quota period value 'cpu.cfs_period_us'.`,
403+
},
404+
},
405+
},
406+
},
407+
408+
"linux_node_config": {
409+
Type: schema.TypeList,
410+
Optional: true,
411+
MaxItems: 1,
412+
Description: `Parameters that can be configured on Linux nodes.`,
413+
Elem: &schema.Resource{
414+
Schema: map[string]*schema.Schema{
415+
"sysctls": {
416+
Type: schema.TypeMap,
417+
Required: true,
418+
Elem: &schema.Schema{Type: schema.TypeString},
419+
Description: `The Linux kernel parameters to be applied to the nodes and all pods running on the nodes.`,
420+
},
421+
},
422+
},
423+
},
379424
"node_group": {
380425
Type: schema.TypeString,
381426
Optional: true,
@@ -591,6 +636,14 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
591636
nc.BootDiskKmsKey = v.(string)
592637
}
593638

639+
if v, ok := nodeConfig["kubelet_config"]; ok {
640+
nc.KubeletConfig = expandKubeletConfig(v)
641+
}
642+
643+
if v, ok := nodeConfig["linux_node_config"]; ok {
644+
nc.LinuxNodeConfig = expandLinuxNodeConfig(v)
645+
}
646+
594647
if v, ok := nodeConfig["node_group"]; ok {
595648
nc.NodeGroup = v.(string)
596649
}
@@ -617,6 +670,51 @@ func expandWorkloadMetadataConfig(v interface{}) *container.WorkloadMetadataConf
617670
return wmc
618671
}
619672

673+
func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
674+
if v == nil {
675+
return nil
676+
}
677+
ls := v.([]interface{})
678+
if len(ls) == 0 {
679+
return nil
680+
}
681+
cfg := ls[0].(map[string]interface{})
682+
kConfig := &container.NodeKubeletConfig{}
683+
if cpuManagerPolicy, ok := cfg["cpu_manager_policy"]; ok {
684+
kConfig.CpuManagerPolicy = cpuManagerPolicy.(string)
685+
}
686+
if cpuCfsQuota, ok := cfg["cpu_cfs_quota"]; ok {
687+
kConfig.CpuCfsQuota = cpuCfsQuota.(bool)
688+
kConfig.ForceSendFields = append(kConfig.ForceSendFields, "CpuCfsQuota")
689+
}
690+
if cpuCfsQuotaPeriod, ok := cfg["cpu_cfs_quota_period"]; ok {
691+
kConfig.CpuCfsQuotaPeriod = cpuCfsQuotaPeriod.(string)
692+
}
693+
return kConfig
694+
}
695+
696+
func expandLinuxNodeConfig(v interface{}) *container.LinuxNodeConfig {
697+
if v == nil {
698+
return nil
699+
}
700+
ls := v.([]interface{})
701+
if len(ls) == 0 {
702+
return nil
703+
}
704+
cfg := ls[0].(map[string]interface{})
705+
sysCfgRaw, ok := cfg["sysctls"]
706+
if !ok {
707+
return nil
708+
}
709+
m := make(map[string]string)
710+
for k, v := range sysCfgRaw.(map[string]interface{}) {
711+
m[k] = v.(string)
712+
}
713+
return &container.LinuxNodeConfig{
714+
Sysctls: m,
715+
}
716+
}
717+
620718
func flattenNodeConfigDefaults(c *container.NodeConfigDefaults) []map[string]interface{} {
621719
result := make([]map[string]interface{}, 0, 1)
622720

@@ -661,6 +759,8 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
661759
"taint": flattenTaints(c.Taints),
662760
"workload_metadata_config": flattenWorkloadMetadataConfig(c.WorkloadMetadataConfig),
663761
"boot_disk_kms_key": c.BootDiskKmsKey,
762+
"kubelet_config": flattenKubeletConfig(c.KubeletConfig),
763+
"linux_node_config": flattenLinuxNodeConfig(c.LinuxNodeConfig),
664764
"node_group": c.NodeGroup,
665765
})
666766

@@ -764,3 +864,25 @@ func flattenWorkloadMetadataConfig(c *container.WorkloadMetadataConfig) []map[st
764864
}
765865
return result
766866
}
867+
868+
func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface{} {
869+
result := []map[string]interface{}{}
870+
if c != nil {
871+
result = append(result, map[string]interface{}{
872+
"cpu_cfs_quota": c.CpuCfsQuota,
873+
"cpu_cfs_quota_period": c.CpuCfsQuotaPeriod,
874+
"cpu_manager_policy": c.CpuManagerPolicy,
875+
})
876+
}
877+
return result
878+
}
879+
880+
func flattenLinuxNodeConfig(c *container.LinuxNodeConfig) []map[string]interface{} {
881+
result := []map[string]interface{}{}
882+
if c != nil {
883+
result = append(result, map[string]interface{}{
884+
"sysctls": c.Sysctls,
885+
})
886+
}
887+
return result
888+
}

google/resource_container_node_pool.go

+67
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,73 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, nodePoolInfo *Node
14041404
log.Printf("[INFO] Updated workload_metadata_config for node pool %s", name)
14051405
}
14061406

1407+
if d.HasChange(prefix + "node_config.0.kubelet_config") {
1408+
req := &container.UpdateNodePoolRequest{
1409+
NodePoolId: name,
1410+
KubeletConfig: expandKubeletConfig(
1411+
d.Get(prefix + "node_config.0.kubelet_config")),
1412+
}
1413+
if req.KubeletConfig == nil {
1414+
req.ForceSendFields = []string{"KubeletConfig"}
1415+
}
1416+
updateF := func() error {
1417+
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(name), req)
1418+
if config.UserProjectOverride {
1419+
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
1420+
}
1421+
op, err := clusterNodePoolsUpdateCall.Do()
1422+
if err != nil {
1423+
return err
1424+
}
1425+
1426+
// Wait until it's updated
1427+
return containerOperationWait(config, op,
1428+
nodePoolInfo.project,
1429+
nodePoolInfo.location,
1430+
"updating GKE node pool kubelet_config", userAgent,
1431+
timeout)
1432+
}
1433+
1434+
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
1435+
return err
1436+
}
1437+
1438+
log.Printf("[INFO] Updated kubelet_config for node pool %s", name)
1439+
}
1440+
if d.HasChange(prefix + "node_config.0.linux_node_config") {
1441+
req := &container.UpdateNodePoolRequest{
1442+
NodePoolId: name,
1443+
LinuxNodeConfig: expandLinuxNodeConfig(
1444+
d.Get(prefix + "node_config.0.linux_node_config")),
1445+
}
1446+
if req.LinuxNodeConfig == nil {
1447+
req.ForceSendFields = []string{"LinuxNodeConfig"}
1448+
}
1449+
updateF := func() error {
1450+
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(name), req)
1451+
if config.UserProjectOverride {
1452+
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
1453+
}
1454+
op, err := clusterNodePoolsUpdateCall.Do()
1455+
if err != nil {
1456+
return err
1457+
}
1458+
1459+
// Wait until it's updated
1460+
return containerOperationWait(config, op,
1461+
nodePoolInfo.project,
1462+
nodePoolInfo.location,
1463+
"updating GKE node pool linux_node_config", userAgent,
1464+
timeout)
1465+
}
1466+
1467+
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
1468+
return err
1469+
}
1470+
1471+
log.Printf("[INFO] Updated linux_node_config for node pool %s", name)
1472+
}
1473+
14071474
}
14081475

14091476
if d.HasChange(prefix + "node_count") {

0 commit comments

Comments
 (0)