Skip to content

Commit 436acda

Browse files
modular-magicianc2thorn
authored andcommitted
container: add support for kubelet read only port (#11272) (#8071)
[upstream:fcc529c34fcf793400595d5ad3df8924915a5976] Signed-off-by: Modular Magician <[email protected]>
1 parent 7f33c5a commit 436acda

File tree

6 files changed

+378
-16
lines changed

6 files changed

+378
-16
lines changed

.changelog/11272.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
container: added `insecure_kubelet_readonly_port_enabled` to `node_pool.node_config.kubelet_config` and `node_config.kubelet_config` in `google_container_node_pool` resource.
3+
```
4+
```release-note:enhancement
5+
container: added `insecure_kubelet_readonly_port_enabled` to `node_pool_defaults.node_config_defaults`, `node_pool.node_config.kubelet_config`, and `node_config.kubelet_config` in `google_container_cluster` resource.
6+
```

google-beta/services/container/node_config.go

+45-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ func schemaContainerdConfig() *schema.Schema {
7373
}
7474
}
7575

76+
// Note: this is a bool internally, but implementing as an enum internally to
77+
// make it easier to accept API level defaults.
78+
func schemaInsecureKubeletReadonlyPortEnabled() *schema.Schema {
79+
return &schema.Schema{
80+
Type: schema.TypeString,
81+
Optional: true,
82+
Computed: true,
83+
Description: "Controls whether the kubelet read-only port is enabled. It is strongly recommended to set this to `FALSE`. Possible values: `TRUE`, `FALSE`.",
84+
ValidateFunc: validation.StringInSlice([]string{"FALSE", "TRUE"}, false),
85+
}
86+
}
87+
7688
func schemaLoggingVariant() *schema.Schema {
7789
return &schema.Schema{
7890
Type: schema.TypeString,
@@ -591,6 +603,7 @@ func schemaNodeConfig() *schema.Schema {
591603
Optional: true,
592604
Description: `Set the CPU CFS quota period value 'cpu.cfs_period_us'.`,
593605
},
606+
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
594607
"pod_pids_limit": {
595608
Type: schema.TypeInt,
596609
Optional: true,
@@ -771,6 +784,12 @@ func expandNodeConfigDefaults(configured interface{}) *container.NodeConfigDefau
771784

772785
nodeConfigDefaults := &container.NodeConfigDefaults{}
773786
nodeConfigDefaults.ContainerdConfig = expandContainerdConfig(config["containerd_config"])
787+
if v, ok := config["insecure_kubelet_readonly_port_enabled"]; ok {
788+
nodeConfigDefaults.NodeKubeletConfig = &container.NodeKubeletConfig{
789+
InsecureKubeletReadonlyPortEnabled: expandInsecureKubeletReadonlyPortEnabled(v),
790+
ForceSendFields: []string{"InsecureKubeletReadonlyPortEnabled"},
791+
}
792+
}
774793
if variant, ok := config["logging_variant"]; ok {
775794
nodeConfigDefaults.LoggingConfig = &container.NodePoolLoggingConfig{
776795
VariantConfig: &container.LoggingVariantConfig{
@@ -1116,6 +1135,13 @@ func expandWorkloadMetadataConfig(v interface{}) *container.WorkloadMetadataConf
11161135
return wmc
11171136
}
11181137

1138+
func expandInsecureKubeletReadonlyPortEnabled(v interface{}) bool {
1139+
if v == "TRUE" {
1140+
return true
1141+
}
1142+
return false
1143+
}
1144+
11191145
func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
11201146
if v == nil {
11211147
return nil
@@ -1136,6 +1162,10 @@ func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
11361162
if cpuCfsQuotaPeriod, ok := cfg["cpu_cfs_quota_period"]; ok {
11371163
kConfig.CpuCfsQuotaPeriod = cpuCfsQuotaPeriod.(string)
11381164
}
1165+
if insecureKubeletReadonlyPortEnabled, ok := cfg["insecure_kubelet_readonly_port_enabled"]; ok {
1166+
kConfig.InsecureKubeletReadonlyPortEnabled = expandInsecureKubeletReadonlyPortEnabled(insecureKubeletReadonlyPortEnabled)
1167+
kConfig.ForceSendFields = append(kConfig.ForceSendFields, "InsecureKubeletReadonlyPortEnabled")
1168+
}
11391169
if podPidsLimit, ok := cfg["pod_pids_limit"]; ok {
11401170
kConfig.PodPidsLimit = int64(podPidsLimit.(int))
11411171
}
@@ -1342,6 +1372,8 @@ func flattenNodeConfigDefaults(c *container.NodeConfigDefaults) []map[string]int
13421372

13431373
result[0]["containerd_config"] = flattenContainerdConfig(c.ContainerdConfig)
13441374

1375+
result[0]["insecure_kubelet_readonly_port_enabled"] = flattenInsecureKubeletReadonlyPortEnabled(c.NodeKubeletConfig)
1376+
13451377
result[0]["logging_variant"] = flattenLoggingVariant(c.LoggingConfig)
13461378

13471379
result[0]["gcfs_config"] = flattenGcfsConfig(c.GcfsConfig)
@@ -1521,6 +1553,14 @@ func flattenSecondaryBootDisks(c []*container.SecondaryBootDisk) []map[string]in
15211553
return result
15221554
}
15231555

1556+
func flattenInsecureKubeletReadonlyPortEnabled(c *container.NodeKubeletConfig) string {
1557+
// Convert bool from the API to the enum values used internally
1558+
if c != nil && c.InsecureKubeletReadonlyPortEnabled {
1559+
return "TRUE"
1560+
}
1561+
return "FALSE"
1562+
}
1563+
15241564
func flattenLoggingVariant(c *container.NodePoolLoggingConfig) string {
15251565
variant := "DEFAULT"
15261566
if c != nil && c.VariantConfig != nil && c.VariantConfig.Variant != "" {
@@ -1668,10 +1708,11 @@ func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface
16681708
result := []map[string]interface{}{}
16691709
if c != nil {
16701710
result = append(result, map[string]interface{}{
1671-
"cpu_cfs_quota": c.CpuCfsQuota,
1672-
"cpu_cfs_quota_period": c.CpuCfsQuotaPeriod,
1673-
"cpu_manager_policy": c.CpuManagerPolicy,
1674-
"pod_pids_limit": c.PodPidsLimit,
1711+
"cpu_cfs_quota": c.CpuCfsQuota,
1712+
"cpu_cfs_quota_period": c.CpuCfsQuotaPeriod,
1713+
"cpu_manager_policy": c.CpuManagerPolicy,
1714+
"insecure_kubelet_readonly_port_enabled": flattenInsecureKubeletReadonlyPortEnabled(c),
1715+
"pod_pids_limit": c.PodPidsLimit,
16751716
})
16761717
}
16771718
return result

google-beta/services/container/resource_container_cluster.go

+80-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ func clusterSchemaNodePoolDefaults() *schema.Schema {
153153
MaxItems: 1,
154154
Elem: &schema.Resource{
155155
Schema: map[string]*schema.Schema{
156-
"containerd_config": schemaContainerdConfig(),
157-
"gcfs_config": schemaGcfsConfig(false),
158-
"logging_variant": schemaLoggingVariant(),
156+
"containerd_config": schemaContainerdConfig(),
157+
"gcfs_config": schemaGcfsConfig(false),
158+
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
159+
"logging_variant": schemaLoggingVariant(),
159160
},
160161
},
161162
},
@@ -3767,6 +3768,60 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
37673768

37683769
log.Printf("[INFO] GKE cluster %s: image type has been updated to %s", d.Id(), it)
37693770
}
3771+
3772+
if d.HasChange("node_config.0.kubelet_config") {
3773+
3774+
defaultPool := "default-pool"
3775+
3776+
timeout := d.Timeout(schema.TimeoutCreate)
3777+
3778+
nodePoolInfo, err := extractNodePoolInformationFromCluster(d, config, clusterName)
3779+
if err != nil {
3780+
return err
3781+
}
3782+
3783+
// Acquire write-lock on nodepool.
3784+
npLockKey := nodePoolInfo.nodePoolLockKey(defaultPool)
3785+
3786+
// Note: probably long term this should be handled broadly for all the
3787+
// items in kubelet_config in a simpler / DRYer way.
3788+
// See b/361634104
3789+
if d.HasChange("node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled") {
3790+
it := d.Get("node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled").(string)
3791+
3792+
// While we're getting the value from the drepcated field in
3793+
// node_config.kubelet_config, the actual setting that needs to be updated
3794+
// is on the default nodepool.
3795+
req := &container.UpdateNodePoolRequest{
3796+
Name: defaultPool,
3797+
KubeletConfig: &container.NodeKubeletConfig{
3798+
InsecureKubeletReadonlyPortEnabled: expandInsecureKubeletReadonlyPortEnabled(it),
3799+
ForceSendFields: []string{"InsecureKubeletReadonlyPortEnabled"},
3800+
},
3801+
}
3802+
3803+
updateF := func() error {
3804+
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(defaultPool), req)
3805+
if config.UserProjectOverride {
3806+
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
3807+
}
3808+
op, err := clusterNodePoolsUpdateCall.Do()
3809+
if err != nil {
3810+
return err
3811+
}
3812+
3813+
// Wait until it's updated
3814+
return ContainerOperationWait(config, op, nodePoolInfo.project, nodePoolInfo.location,
3815+
"updating GKE node pool insecure_kubelet_readonly_port_enabled", userAgent, timeout)
3816+
}
3817+
3818+
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
3819+
return err
3820+
}
3821+
3822+
log.Printf("[INFO] GKE cluster %s: default-pool setting for insecure_kubelet_readonly_port_enabled updated to %s", d.Id(), it)
3823+
}
3824+
}
37703825
}
37713826

37723827
if d.HasChange("notification_config") {
@@ -4189,6 +4244,28 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
41894244
}
41904245
}
41914246

4247+
if d.HasChange("node_pool_defaults") && d.HasChange("node_pool_defaults.0.node_config_defaults.0.insecure_kubelet_readonly_port_enabled") {
4248+
if v, ok := d.GetOk("node_pool_defaults.0.node_config_defaults.0.insecure_kubelet_readonly_port_enabled"); ok {
4249+
insecureKubeletReadonlyPortEnabled := v.(string)
4250+
req := &container.UpdateClusterRequest{
4251+
Update: &container.ClusterUpdate{
4252+
DesiredNodeKubeletConfig: &container.NodeKubeletConfig{
4253+
InsecureKubeletReadonlyPortEnabled: expandInsecureKubeletReadonlyPortEnabled(insecureKubeletReadonlyPortEnabled),
4254+
ForceSendFields: []string{"InsecureKubeletReadonlyPortEnabled"},
4255+
},
4256+
},
4257+
}
4258+
4259+
updateF := updateFunc(req, "updating GKE cluster desired node pool insecure kubelet readonly port configuration defaults.")
4260+
// Call update serially.
4261+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
4262+
return err
4263+
}
4264+
4265+
log.Printf("[INFO] GKE cluster %s node pool insecure_kubelet_readonly_port_enabled default has been updated", d.Id())
4266+
}
4267+
}
4268+
41924269
if d.HasChange("node_pool_defaults") && d.HasChange("node_pool_defaults.0.node_config_defaults.0.logging_variant") {
41934270
if v, ok := d.GetOk("node_pool_defaults.0.node_config_defaults.0.logging_variant"); ok {
41944271
loggingVariant := v.(string)

0 commit comments

Comments
 (0)