Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container: add support for kubelet read only port #8071

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/11272.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
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.
```
```release-note:enhancement
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.
```
49 changes: 45 additions & 4 deletions google-beta/services/container/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ func schemaContainerdConfig() *schema.Schema {
}
}

// Note: this is a bool internally, but implementing as an enum internally to
// make it easier to accept API level defaults.
func schemaInsecureKubeletReadonlyPortEnabled() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Controls whether the kubelet read-only port is enabled. It is strongly recommended to set this to `FALSE`. Possible values: `TRUE`, `FALSE`.",
ValidateFunc: validation.StringInSlice([]string{"FALSE", "TRUE"}, false),
}
}

func schemaLoggingVariant() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -586,6 +598,7 @@ func schemaNodeConfig() *schema.Schema {
Optional: true,
Description: `Set the CPU CFS quota period value 'cpu.cfs_period_us'.`,
},
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
"pod_pids_limit": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -766,6 +779,12 @@ func expandNodeConfigDefaults(configured interface{}) *container.NodeConfigDefau

nodeConfigDefaults := &container.NodeConfigDefaults{}
nodeConfigDefaults.ContainerdConfig = expandContainerdConfig(config["containerd_config"])
if v, ok := config["insecure_kubelet_readonly_port_enabled"]; ok {
nodeConfigDefaults.NodeKubeletConfig = &container.NodeKubeletConfig{
InsecureKubeletReadonlyPortEnabled: expandInsecureKubeletReadonlyPortEnabled(v),
ForceSendFields: []string{"InsecureKubeletReadonlyPortEnabled"},
}
}
if variant, ok := config["logging_variant"]; ok {
nodeConfigDefaults.LoggingConfig = &container.NodePoolLoggingConfig{
VariantConfig: &container.LoggingVariantConfig{
Expand Down Expand Up @@ -1115,6 +1134,13 @@ func expandWorkloadMetadataConfig(v interface{}) *container.WorkloadMetadataConf
return wmc
}

func expandInsecureKubeletReadonlyPortEnabled(v interface{}) bool {
if v == "TRUE" {
return true
}
return false
}

func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
if v == nil {
return nil
Expand All @@ -1135,6 +1161,10 @@ func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
if cpuCfsQuotaPeriod, ok := cfg["cpu_cfs_quota_period"]; ok {
kConfig.CpuCfsQuotaPeriod = cpuCfsQuotaPeriod.(string)
}
if insecureKubeletReadonlyPortEnabled, ok := cfg["insecure_kubelet_readonly_port_enabled"]; ok {
kConfig.InsecureKubeletReadonlyPortEnabled = expandInsecureKubeletReadonlyPortEnabled(insecureKubeletReadonlyPortEnabled)
kConfig.ForceSendFields = append(kConfig.ForceSendFields, "InsecureKubeletReadonlyPortEnabled")
}
if podPidsLimit, ok := cfg["pod_pids_limit"]; ok {
kConfig.PodPidsLimit = int64(podPidsLimit.(int))
}
Expand Down Expand Up @@ -1341,6 +1371,8 @@ func flattenNodeConfigDefaults(c *container.NodeConfigDefaults) []map[string]int

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

result[0]["insecure_kubelet_readonly_port_enabled"] = flattenInsecureKubeletReadonlyPortEnabled(c.NodeKubeletConfig)

result[0]["logging_variant"] = flattenLoggingVariant(c.LoggingConfig)

result[0]["gcfs_config"] = flattenGcfsConfig(c.GcfsConfig)
Expand Down Expand Up @@ -1524,6 +1556,14 @@ func flattenSecondaryBootDisks(c []*container.SecondaryBootDisk) []map[string]in
return result
}

func flattenInsecureKubeletReadonlyPortEnabled(c *container.NodeKubeletConfig) string {
// Convert bool from the API to the enum values used internally
if c != nil && c.InsecureKubeletReadonlyPortEnabled {
return "TRUE"
}
return "FALSE"
}

func flattenLoggingVariant(c *container.NodePoolLoggingConfig) string {
variant := "DEFAULT"
if c != nil && c.VariantConfig != nil && c.VariantConfig.Variant != "" {
Expand Down Expand Up @@ -1671,10 +1711,11 @@ func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface
result := []map[string]interface{}{}
if c != nil {
result = append(result, map[string]interface{}{
"cpu_cfs_quota": c.CpuCfsQuota,
"cpu_cfs_quota_period": c.CpuCfsQuotaPeriod,
"cpu_manager_policy": c.CpuManagerPolicy,
"pod_pids_limit": c.PodPidsLimit,
"cpu_cfs_quota": c.CpuCfsQuota,
"cpu_cfs_quota_period": c.CpuCfsQuotaPeriod,
"cpu_manager_policy": c.CpuManagerPolicy,
"insecure_kubelet_readonly_port_enabled": flattenInsecureKubeletReadonlyPortEnabled(c),
"pod_pids_limit": c.PodPidsLimit,
})
}
return result
Expand Down
83 changes: 80 additions & 3 deletions google-beta/services/container/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ func clusterSchemaNodePoolDefaults() *schema.Schema {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"containerd_config": schemaContainerdConfig(),
"gcfs_config": schemaGcfsConfig(false),
"logging_variant": schemaLoggingVariant(),
"containerd_config": schemaContainerdConfig(),
"gcfs_config": schemaGcfsConfig(false),
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
"logging_variant": schemaLoggingVariant(),
},
},
},
Expand Down Expand Up @@ -3772,6 +3773,60 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er

log.Printf("[INFO] GKE cluster %s: image type has been updated to %s", d.Id(), it)
}

if d.HasChange("node_config.0.kubelet_config") {

defaultPool := "default-pool"

timeout := d.Timeout(schema.TimeoutCreate)

nodePoolInfo, err := extractNodePoolInformationFromCluster(d, config, clusterName)
if err != nil {
return err
}

// Acquire write-lock on nodepool.
npLockKey := nodePoolInfo.nodePoolLockKey(defaultPool)

// Note: probably long term this should be handled broadly for all the
// items in kubelet_config in a simpler / DRYer way.
// See b/361634104
if d.HasChange("node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled") {
it := d.Get("node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled").(string)

// While we're getting the value from the drepcated field in
// node_config.kubelet_config, the actual setting that needs to be updated
// is on the default nodepool.
req := &container.UpdateNodePoolRequest{
Name: defaultPool,
KubeletConfig: &container.NodeKubeletConfig{
InsecureKubeletReadonlyPortEnabled: expandInsecureKubeletReadonlyPortEnabled(it),
ForceSendFields: []string{"InsecureKubeletReadonlyPortEnabled"},
},
}

updateF := func() error {
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(defaultPool), req)
if config.UserProjectOverride {
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
}
op, err := clusterNodePoolsUpdateCall.Do()
if err != nil {
return err
}

// Wait until it's updated
return ContainerOperationWait(config, op, nodePoolInfo.project, nodePoolInfo.location,
"updating GKE node pool insecure_kubelet_readonly_port_enabled", userAgent, timeout)
}

if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s: default-pool setting for insecure_kubelet_readonly_port_enabled updated to %s", d.Id(), it)
}
}
}

if d.HasChange("notification_config") {
Expand Down Expand Up @@ -4194,6 +4249,28 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if d.HasChange("node_pool_defaults") && d.HasChange("node_pool_defaults.0.node_config_defaults.0.insecure_kubelet_readonly_port_enabled") {
if v, ok := d.GetOk("node_pool_defaults.0.node_config_defaults.0.insecure_kubelet_readonly_port_enabled"); ok {
insecureKubeletReadonlyPortEnabled := v.(string)
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredNodeKubeletConfig: &container.NodeKubeletConfig{
InsecureKubeletReadonlyPortEnabled: expandInsecureKubeletReadonlyPortEnabled(insecureKubeletReadonlyPortEnabled),
ForceSendFields: []string{"InsecureKubeletReadonlyPortEnabled"},
},
},
}

updateF := updateFunc(req, "updating GKE cluster desired node pool insecure kubelet readonly port configuration defaults.")
// Call update serially.
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s node pool insecure_kubelet_readonly_port_enabled default has been updated", d.Id())
}
}

if d.HasChange("node_pool_defaults") && d.HasChange("node_pool_defaults.0.node_config_defaults.0.logging_variant") {
if v, ok := d.GetOk("node_pool_defaults.0.node_config_defaults.0.logging_variant"); ok {
loggingVariant := v.(string)
Expand Down
Loading