Skip to content

Commit 4f1f2b6

Browse files
container: make cpu_manager_policy optional in kubelet_config (#11572)
Co-authored-by: Stephen Lewis (Burrows) <[email protected]> [upstream:c920b8fc0cd06c1450c7da57434418b1fa307ebc] Signed-off-by: Modular Magician <[email protected]>
1 parent e9efc46 commit 4f1f2b6

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

.changelog/11572.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: make `cpu_manager_policy` optional in `kubelet_config`
3+
```

google-beta/services/container/node_config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func schemaNodeConfig() *schema.Schema {
590590
Schema: map[string]*schema.Schema{
591591
"cpu_manager_policy": {
592592
Type: schema.TypeString,
593-
Required: true,
593+
Optional: true,
594594
ValidateFunc: validation.StringInSlice([]string{"static", "none", ""}, false),
595595
Description: `Control the CPU management policy on the node.`,
596596
},

google-beta/services/container/resource_container_cluster_test.go

+56-3
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,40 @@ func TestAccContainerCluster_withNodeConfig(t *testing.T) {
15251525
})
15261526
}
15271527

1528+
// Note: Updates for these are currently known to be broken (b/361634104), and
1529+
// so are not tested here.
1530+
// They can probably be made similar to, or consolidated with,
1531+
// TestAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfigUpdates
1532+
// after that's resolved.
1533+
func TestAccContainerCluster_withNodeConfigKubeletConfigSettings(t *testing.T) {
1534+
t.Parallel()
1535+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
1536+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
1537+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
1538+
1539+
acctest.VcrTest(t, resource.TestCase{
1540+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1541+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1542+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
1543+
Steps: []resource.TestStep{
1544+
{
1545+
Config: testAccContainerCluster_withNodeConfigKubeletConfigSettings(clusterName, networkName, subnetworkName),
1546+
ConfigPlanChecks: resource.ConfigPlanChecks{
1547+
PreApply: []plancheck.PlanCheck{
1548+
acctest.ExpectNoDelete(),
1549+
},
1550+
},
1551+
},
1552+
{
1553+
ResourceName: "google_container_cluster.with_node_config_kubelet_config_settings",
1554+
ImportState: true,
1555+
ImportStateVerify: true,
1556+
ImportStateVerifyIgnore: []string{"deletion_protection"},
1557+
},
1558+
},
1559+
})
1560+
}
1561+
15281562
// This is for node_config.kubelet_config, which affects the default node-pool
15291563
// (default-pool) when created via the google_container_cluster resource
15301564
func TestAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfigUpdates(t *testing.T) {
@@ -6620,6 +6654,28 @@ resource "google_container_cluster" "with_node_config" {
66206654
`, clusterName, networkName, subnetworkName)
66216655
}
66226656

6657+
func testAccContainerCluster_withNodeConfigKubeletConfigSettings(clusterName, networkName, subnetworkName string) string {
6658+
return fmt.Sprintf(`
6659+
resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
6660+
name = "%s"
6661+
location = "us-central1-f"
6662+
initial_node_count = 1
6663+
6664+
node_config {
6665+
kubelet_config {
6666+
cpu_manager_policy = "static"
6667+
cpu_cfs_quota = true
6668+
cpu_cfs_quota_period = "100ms"
6669+
pod_pids_limit = 2048
6670+
}
6671+
}
6672+
deletion_protection = false
6673+
network = "%s"
6674+
subnetwork = "%s"
6675+
}
6676+
`, clusterName, networkName, subnetworkName)
6677+
}
6678+
66236679
func testAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfig(clusterName, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled string) string {
66246680
return fmt.Sprintf(`
66256681
resource "google_container_cluster" "with_insecure_kubelet_readonly_port_enabled_in_node_config" {
@@ -6629,9 +6685,6 @@ resource "google_container_cluster" "with_insecure_kubelet_readonly_port_enabled
66296685
66306686
node_config {
66316687
kubelet_config {
6632-
# Must be set when kubelet_config is, but causes permadrift unless set to
6633-
# undocumented empty value
6634-
cpu_manager_policy = ""
66356688
insecure_kubelet_readonly_port_enabled = "%s"
66366689
}
66376690
}

website/docs/r/container_cluster.html.markdown

+2-7
Original file line numberDiff line numberDiff line change
@@ -1290,9 +1290,9 @@ Enables monitoring and attestation of the boot integrity of the instance. The at
12901290

12911291
<a name="nested_kubelet_config"></a>The `kubelet_config` block supports:
12921292

1293-
* `cpu_manager_policy` - (Required) The CPU management policy on the node. See
1293+
* `cpu_manager_policy` - (Optional) The CPU management policy on the node. See
12941294
[K8S CPU Management Policies](https://kubernetes.io/docs/tasks/administer-cluster/cpu-management-policies/).
1295-
One of `"none"` or `"static"`. Defaults to `none` when `kubelet_config` is unset.
1295+
One of `"none"` or `"static"`. If unset (or set to the empty string `""`), the API will treat the field as if set to "none".
12961296

12971297
* `cpu_cfs_quota` - (Optional) If true, enables CPU CFS quota enforcement for
12981298
containers that specify CPU limits.
@@ -1302,11 +1302,6 @@ as a sequence of decimal numbers, each with optional fraction and a unit suffix,
13021302
such as `"300ms"`. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m",
13031303
"h". The value must be a positive duration.
13041304

1305-
-> Note: At the time of writing (2020/08/18) the GKE API rejects the `none`
1306-
value and accepts an invalid `default` value instead. While this remains true,
1307-
not specifying the `kubelet_config` block should be the equivalent of specifying
1308-
`none`.
1309-
13101305
* `insecure_kubelet_readonly_port_enabled` - (Optional) Controls whether the kubelet read-only port is enabled. It is strongly recommended to set this to `FALSE`. Possible values: `TRUE`, `FALSE`.
13111306

13121307
* `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.

0 commit comments

Comments
 (0)