Skip to content

Commit 846050f

Browse files
authored
container: fix node_config.kubelet_config updates in google_container_cluster (#11697)
1 parent 9c53391 commit 846050f

File tree

2 files changed

+47
-69
lines changed

2 files changed

+47
-69
lines changed

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

+25-31
Original file line numberDiff line numberDiff line change
@@ -3844,44 +3844,38 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
38443844
// Acquire write-lock on nodepool.
38453845
npLockKey := nodePoolInfo.nodePoolLockKey(defaultPool)
38463846

3847-
// Note: probably long term this should be handled broadly for all the
3848-
// items in kubelet_config in a simpler / DRYer way.
3847+
// Still should be further consolidated / DRYed up
38493848
// See b/361634104
3850-
if d.HasChange("node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled") {
3851-
it := d.Get("node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled").(string)
3852-
3853-
// While we're getting the value from the drepcated field in
3854-
// node_config.kubelet_config, the actual setting that needs to be updated
3855-
// is on the default nodepool.
3856-
req := &container.UpdateNodePoolRequest{
3857-
Name: defaultPool,
3858-
KubeletConfig: &container.NodeKubeletConfig{
3859-
InsecureKubeletReadonlyPortEnabled: expandInsecureKubeletReadonlyPortEnabled(it),
3860-
ForceSendFields: []string{"InsecureKubeletReadonlyPortEnabled"},
3861-
},
3862-
}
3849+
it := d.Get("node_config.0.kubelet_config")
38633850

3864-
updateF := func() error {
3865-
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(defaultPool), req)
3866-
if config.UserProjectOverride {
3867-
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
3868-
}
3869-
op, err := clusterNodePoolsUpdateCall.Do()
3870-
if err != nil {
3871-
return err
3872-
}
3851+
// While we're getting the value from fields in
3852+
// node_config.kubelet_config, the actual setting that needs to be
3853+
// updated is on the default nodepool.
3854+
req := &container.UpdateNodePoolRequest{
3855+
Name: defaultPool,
3856+
KubeletConfig: expandKubeletConfig(it),
3857+
}
38733858

3874-
// Wait until it's updated
3875-
return ContainerOperationWait(config, op, nodePoolInfo.project, nodePoolInfo.location,
3876-
"updating GKE node pool insecure_kubelet_readonly_port_enabled", userAgent, timeout)
3859+
updateF := func() error {
3860+
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(defaultPool), req)
3861+
if config.UserProjectOverride {
3862+
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
38773863
}
3878-
3879-
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
3864+
op, err := clusterNodePoolsUpdateCall.Do()
3865+
if err != nil {
38803866
return err
38813867
}
38823868

3883-
log.Printf("[INFO] GKE cluster %s: default-pool setting for insecure_kubelet_readonly_port_enabled updated to %s", d.Id(), it)
3884-
}
3869+
// Wait until it's updated
3870+
return ContainerOperationWait(config, op, nodePoolInfo.project, nodePoolInfo.location,
3871+
"updating GKE node pool kubelet_config", userAgent, timeout)
3872+
}
3873+
3874+
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
3875+
return err
3876+
}
3877+
3878+
log.Printf("[INFO] GKE cluster %s: kubelet_config updated", d.Id())
38853879
}
38863880

38873881
if d.HasChange("node_config.0.gcfs_config") {

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

+22-38
Original file line numberDiff line numberDiff line change
@@ -1579,12 +1579,7 @@ func TestAccContainerCluster_withNodeConfigGcfsConfig(t *testing.T) {
15791579
})
15801580
}
15811581

1582-
// Note: Updates for these are currently known to be broken (b/361634104), and
1583-
// so are not tested here.
1584-
// They can probably be made similar to, or consolidated with,
1585-
// TestAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfigUpdates
1586-
// after that's resolved.
1587-
func TestAccContainerCluster_withNodeConfigKubeletConfigSettings(t *testing.T) {
1582+
func TestAccContainerCluster_withNodeConfigKubeletConfigSettingsUpdates(t *testing.T) {
15881583
t.Parallel()
15891584
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
15901585
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
@@ -1596,7 +1591,7 @@ func TestAccContainerCluster_withNodeConfigKubeletConfigSettings(t *testing.T) {
15961591
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
15971592
Steps: []resource.TestStep{
15981593
{
1599-
Config: testAccContainerCluster_withNodeConfigKubeletConfigSettings(clusterName, networkName, subnetworkName),
1594+
Config: testAccContainerCluster_withNodeConfigKubeletConfigSettingsBaseline(clusterName, networkName, subnetworkName),
16001595
ConfigPlanChecks: resource.ConfigPlanChecks{
16011596
PreApply: []plancheck.PlanCheck{
16021597
acctest.ExpectNoDelete(),
@@ -1609,42 +1604,30 @@ func TestAccContainerCluster_withNodeConfigKubeletConfigSettings(t *testing.T) {
16091604
ImportStateVerify: true,
16101605
ImportStateVerifyIgnore: []string{"deletion_protection"},
16111606
},
1612-
},
1613-
})
1614-
}
1615-
1616-
// This is for node_config.kubelet_config, which affects the default node-pool
1617-
// (default-pool) when created via the google_container_cluster resource
1618-
func TestAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfigUpdates(t *testing.T) {
1619-
t.Parallel()
1620-
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
1621-
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
1622-
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
1623-
1624-
acctest.VcrTest(t, resource.TestCase{
1625-
PreCheck: func() { acctest.AccTestPreCheck(t) },
1626-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1627-
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
1628-
Steps: []resource.TestStep{
16291607
{
1630-
Config: testAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfig(clusterName, networkName, subnetworkName, "TRUE"),
1608+
Config: testAccContainerCluster_withNodeConfigKubeletConfigSettingsUpdates(clusterName, "none", "100ms", "TRUE", networkName, subnetworkName, 2048, true),
16311609
ConfigPlanChecks: resource.ConfigPlanChecks{
16321610
PreApply: []plancheck.PlanCheck{
16331611
acctest.ExpectNoDelete(),
16341612
},
16351613
},
16361614
},
16371615
{
1638-
ResourceName: "google_container_cluster.with_insecure_kubelet_readonly_port_enabled_in_node_config",
1616+
ResourceName: "google_container_cluster.with_node_config_kubelet_config_settings",
16391617
ImportState: true,
16401618
ImportStateVerify: true,
16411619
ImportStateVerifyIgnore: []string{"deletion_protection"},
16421620
},
16431621
{
1644-
Config: testAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfig(clusterName, networkName, subnetworkName, "FALSE"),
1622+
Config: testAccContainerCluster_withNodeConfigKubeletConfigSettingsUpdates(clusterName, "static", "", "FALSE", networkName, subnetworkName, 1024, true),
1623+
ConfigPlanChecks: resource.ConfigPlanChecks{
1624+
PreApply: []plancheck.PlanCheck{
1625+
acctest.ExpectNoDelete(),
1626+
},
1627+
},
16451628
},
16461629
{
1647-
ResourceName: "google_container_cluster.with_insecure_kubelet_readonly_port_enabled_in_node_config",
1630+
ResourceName: "google_container_cluster.with_node_config_kubelet_config_settings",
16481631
ImportState: true,
16491632
ImportStateVerify: true,
16501633
ImportStateVerifyIgnore: []string{"deletion_protection"},
@@ -6782,7 +6765,7 @@ resource "google_container_cluster" "with_node_config_gcfs_config" {
67826765
`, clusterName, enabled, networkName, subnetworkName)
67836766
}
67846767

6785-
func testAccContainerCluster_withNodeConfigKubeletConfigSettings(clusterName, networkName, subnetworkName string) string {
6768+
func testAccContainerCluster_withNodeConfigKubeletConfigSettingsBaseline(clusterName, networkName, subnetworkName string) string {
67866769
return fmt.Sprintf(`
67876770
resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
67886771
name = "%s"
@@ -6791,10 +6774,7 @@ resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
67916774

67926775
node_config {
67936776
kubelet_config {
6794-
cpu_manager_policy = "static"
6795-
cpu_cfs_quota = true
6796-
cpu_cfs_quota_period = "100ms"
6797-
pod_pids_limit = 2048
6777+
pod_pids_limit = 1024
67986778
}
67996779
}
68006780
deletion_protection = false
@@ -6804,23 +6784,27 @@ resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
68046784
`, clusterName, networkName, subnetworkName)
68056785
}
68066786

6807-
func testAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfig(clusterName, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled string) string {
6787+
func testAccContainerCluster_withNodeConfigKubeletConfigSettingsUpdates(clusterName, cpuManagerPolicy, cpuCfsQuotaPeriod, insecureKubeletReadonlyPortEnabled, networkName, subnetworkName string, podPidsLimit int, cpuCfsQuota bool) string {
68086788
return fmt.Sprintf(`
6809-
resource "google_container_cluster" "with_insecure_kubelet_readonly_port_enabled_in_node_config" {
6789+
resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
68106790
name = "%s"
68116791
location = "us-central1-f"
68126792
initial_node_count = 1
68136793

68146794
node_config {
68156795
kubelet_config {
6796+
cpu_manager_policy = "%s"
6797+
cpu_cfs_quota = %v
6798+
cpu_cfs_quota_period = "%s"
68166799
insecure_kubelet_readonly_port_enabled = "%s"
6800+
pod_pids_limit = %v
68176801
}
68186802
}
68196803
deletion_protection = false
6820-
network = "%s"
6821-
subnetwork = "%s"
6804+
network = "%s"
6805+
subnetwork = "%s"
68226806
}
6823-
`, clusterName, insecureKubeletReadonlyPortEnabled, networkName, subnetworkName)
6807+
`, clusterName, cpuManagerPolicy, cpuCfsQuota, cpuCfsQuotaPeriod, insecureKubeletReadonlyPortEnabled, podPidsLimit, networkName, subnetworkName)
68246808
}
68256809

68266810
func testAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodePool(clusterName, nodePoolName, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled string) string {

0 commit comments

Comments
 (0)