Skip to content

Commit 7249061

Browse files
committed
container: add support for kubelet read only port
- Add `no_enable_insecure_kubelet_readonly_port` to google_container_cluster - Allow setting `insecure_kubelet_readonly_port_enabled` for `container_node_pool` https://cloud.google.com/kubernetes-engine/docs/how-to/disable-kubelet-readonly-port Fixes hashicorp/terraform-provider-google#15208
1 parent 2079ba5 commit 7249061

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

mmv1/third_party/terraform/services/container/go/node_config.go.tmpl

+8
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,11 @@ func schemaNodeConfig() *schema.Schema {
600600
Optional: true,
601601
Description: `Set the CPU CFS quota period value 'cpu.cfs_period_us'.`,
602602
},
603+
"insecure_kubelet_readonly_port_enabled": {
604+
Type: schema.TypeBool,
605+
Optional: true,
606+
Description: `Enable or disable Kubelet read only port.`,
607+
},
603608
"pod_pids_limit": {
604609
Type: schema.TypeInt,
605610
Optional: true,
@@ -1153,6 +1158,9 @@ func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
11531158
if cpuCfsQuotaPeriod, ok := cfg["cpu_cfs_quota_period"]; ok {
11541159
kConfig.CpuCfsQuotaPeriod = cpuCfsQuotaPeriod.(string)
11551160
}
1161+
if insecureKubeletReadonlyPortEnabled, ok := cfg["insecure_kubelet_readonly_port_enabled"]; ok {
1162+
kConfig.insecureKubeletReadonlyPortEnabled = insecureKubeletReadonlyPortEnabled.(bool)
1163+
}
11561164
if podPidsLimit, ok := cfg["pod_pids_limit"]; ok {
11571165
kConfig.PodPidsLimit = int64(podPidsLimit.(int))
11581166
}

mmv1/third_party/terraform/services/container/node_config.go.erb

+5
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,11 @@ func schemaNodeConfig() *schema.Schema {
602602
Optional: true,
603603
Description: `Set the CPU CFS quota period value 'cpu.cfs_period_us'.`,
604604
},
605+
"insecure_kubelet_readonly_port_enabled": {
606+
Type: schema.TypeBool,
607+
Optional: true,
608+
Description: `Enable or disable Kubelet read only port.`,
609+
},
605610
"pod_pids_limit": {
606611
Type: schema.TypeInt,
607612
Optional: true,

mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb

+13-8
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,12 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) {
527527
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
528528
Steps: []resource.TestStep{
529529
{
530-
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "static", "100ms", networkName, subnetworkName, true, 2048),
530+
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "static", "100ms", networkName, subnetworkName, true, false, 2048),
531531
Check: resource.ComposeTestCheckFunc(
532532
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
533533
"node_config.0.kubelet_config.0.cpu_cfs_quota", "true"),
534+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
535+
"node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled", "false"),
534536
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
535537
"node_config.0.kubelet_config.0.pod_pids_limit", "2048"),
536538
),
@@ -541,10 +543,12 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) {
541543
ImportStateVerify: true,
542544
},
543545
{
544-
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "", "", networkName, subnetworkName, false, 1024),
546+
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "", "", networkName, subnetworkName, false, true, 1024),
545547
Check: resource.ComposeTestCheckFunc(
546548
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
547549
"node_config.0.kubelet_config.0.cpu_cfs_quota", "false"),
550+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
551+
"node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled", "true"),
548552
),
549553
},
550554
{
@@ -3137,7 +3141,7 @@ resource "google_container_node_pool" "with_sandbox_config" {
31373141
}
31383142
<% end -%>
31393143

3140-
func testAccContainerNodePool_withKubeletConfig(cluster, np, policy, period, networkName, subnetworkName string, quota bool, podPidsLimit int) string {
3144+
func testAccContainerNodePool_withKubeletConfig(cluster, np, policy, period, networkName, subnetworkName string, quota bool, insecureKubeletReadonlyPortEnabled bool, podPidsLimit int) string {
31413145
return fmt.Sprintf(`
31423146
data "google_container_engine_versions" "central1a" {
31433147
location = "us-central1-a"
@@ -3163,10 +3167,11 @@ resource "google_container_node_pool" "with_kubelet_config" {
31633167
node_config {
31643168
image_type = "COS_CONTAINERD"
31653169
kubelet_config {
3166-
cpu_manager_policy = %q
3167-
cpu_cfs_quota = %v
3168-
cpu_cfs_quota_period = %q
3169-
pod_pids_limit = %d
3170+
cpu_manager_policy = %q
3171+
cpu_cfs_quota = %v
3172+
cpu_cfs_quota_period = %q
3173+
insecure_kubelet_readonly_port_enabled = %v
3174+
pod_pids_limit = %d
31703175
}
31713176
oauth_scopes = [
31723177
"https://www.googleapis.com/auth/logging.write",
@@ -4929,4 +4934,4 @@ resource "google_container_node_pool" "np" {
49294934
}
49304935
}
49314936
`, cluster, np)
4932-
}
4937+
}

mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,10 @@ value and accepts an invalid `default` value instead. While this remains true,
12751275
not specifying the `kubelet_config` block should be the equivalent of specifying
12761276
`none`.
12771277

1278+
* `insecure_kubelet_readonly_port_enabled` - (Optional) Controls whether the
1279+
kubelet read-only port is disabled. It is strongly recommended to set this to
1280+
`false`.
1281+
12781282
* `pod_pids_limit` - (Optional) Controls the maximum number of processes allowed to run in a pod. The value must be greater than or equal to 1024 and less than 4194304.
12791283

12801284
<a name="nested_linux_node_config"></a>The `linux_node_config` block supports:

0 commit comments

Comments
 (0)