Skip to content

Commit c920b8f

Browse files
wyardleymelinath
andauthored
container: make cpu_manager_policy optional in kubelet_config (#11572)
Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent 3084e72 commit c920b8f

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,9 @@ func schemaNodeConfig() *schema.Schema {
601601
Schema: map[string]*schema.Schema{
602602
"cpu_manager_policy": {
603603
Type: schema.TypeString,
604-
Required: true,
604+
Optional: true,
605605
ValidateFunc: validation.StringInSlice([]string{"static", "none", ""}, false),
606-
Description: `Control the CPU management policy on the node.`,
606+
Description: `Control the CPU management policy on the node.`,
607607
},
608608
"cpu_cfs_quota": {
609609
Type: schema.TypeBool,

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

+56-3
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,40 @@ func TestAccContainerCluster_withNodeConfig(t *testing.T) {
15361536
})
15371537
}
15381538

1539+
// Note: Updates for these are currently known to be broken (b/361634104), and
1540+
// so are not tested here.
1541+
// They can probably be made similar to, or consolidated with,
1542+
// TestAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfigUpdates
1543+
// after that's resolved.
1544+
func TestAccContainerCluster_withNodeConfigKubeletConfigSettings(t *testing.T) {
1545+
t.Parallel()
1546+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
1547+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
1548+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
1549+
1550+
acctest.VcrTest(t, resource.TestCase{
1551+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1552+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1553+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
1554+
Steps: []resource.TestStep{
1555+
{
1556+
Config: testAccContainerCluster_withNodeConfigKubeletConfigSettings(clusterName, networkName, subnetworkName),
1557+
ConfigPlanChecks: resource.ConfigPlanChecks{
1558+
PreApply: []plancheck.PlanCheck{
1559+
acctest.ExpectNoDelete(),
1560+
},
1561+
},
1562+
},
1563+
{
1564+
ResourceName: "google_container_cluster.with_node_config_kubelet_config_settings",
1565+
ImportState: true,
1566+
ImportStateVerify: true,
1567+
ImportStateVerifyIgnore: []string{"deletion_protection"},
1568+
},
1569+
},
1570+
})
1571+
}
1572+
15391573
// This is for node_config.kubelet_config, which affects the default node-pool
15401574
// (default-pool) when created via the google_container_cluster resource
15411575
func TestAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfigUpdates(t *testing.T) {
@@ -6659,6 +6693,28 @@ resource "google_container_cluster" "with_node_config" {
66596693
`, clusterName, networkName, subnetworkName)
66606694
}
66616695

6696+
func testAccContainerCluster_withNodeConfigKubeletConfigSettings(clusterName, networkName, subnetworkName string) string {
6697+
return fmt.Sprintf(`
6698+
resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
6699+
name = "%s"
6700+
location = "us-central1-f"
6701+
initial_node_count = 1
6702+
6703+
node_config {
6704+
kubelet_config {
6705+
cpu_manager_policy = "static"
6706+
cpu_cfs_quota = true
6707+
cpu_cfs_quota_period = "100ms"
6708+
pod_pids_limit = 2048
6709+
}
6710+
}
6711+
deletion_protection = false
6712+
network = "%s"
6713+
subnetwork = "%s"
6714+
}
6715+
`, clusterName, networkName, subnetworkName)
6716+
}
6717+
66626718
func testAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfig(clusterName, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled string) string {
66636719
return fmt.Sprintf(`
66646720
resource "google_container_cluster" "with_insecure_kubelet_readonly_port_enabled_in_node_config" {
@@ -6668,9 +6724,6 @@ resource "google_container_cluster" "with_insecure_kubelet_readonly_port_enabled
66686724

66696725
node_config {
66706726
kubelet_config {
6671-
# Must be set when kubelet_config is, but causes permadrift unless set to
6672-
# undocumented empty value
6673-
cpu_manager_policy = ""
66746727
insecure_kubelet_readonly_port_enabled = "%s"
66756728
}
66766729
}

mmv1/third_party/terraform/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)