Skip to content

Commit 4a61921

Browse files
committed
container: fix node_config.kubelet_config updates
- Fix updates for fields within `node_config.kubelet_config` where updates didn't function properly (basically all except for `insecure_kubelet_readonly_port_enabled`. - Consolidate test cases for items under `node_config.kubelet_config` with the one for `node_config.kubelet_config.insecure_kubelet_readonly_port_enabled` Part of hashicorp/terraform-provider-google#19225
1 parent 20ac9f9 commit 4a61921

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"},
@@ -6756,7 +6739,7 @@ resource "google_container_cluster" "with_node_config_gcfs_config" {
67566739
`, clusterName, enabled, networkName, subnetworkName)
67576740
}
67586741

6759-
func testAccContainerCluster_withNodeConfigKubeletConfigSettings(clusterName, networkName, subnetworkName string) string {
6742+
func testAccContainerCluster_withNodeConfigKubeletConfigSettingsBaseline(clusterName, networkName, subnetworkName string) string {
67606743
return fmt.Sprintf(`
67616744
resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
67626745
name = "%s"
@@ -6765,10 +6748,7 @@ resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
67656748

67666749
node_config {
67676750
kubelet_config {
6768-
cpu_manager_policy = "static"
6769-
cpu_cfs_quota = true
6770-
cpu_cfs_quota_period = "100ms"
6771-
pod_pids_limit = 2048
6751+
pod_pids_limit = 1024
67726752
}
67736753
}
67746754
deletion_protection = false
@@ -6778,23 +6758,27 @@ resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
67786758
`, clusterName, networkName, subnetworkName)
67796759
}
67806760

6781-
func testAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodeConfig(clusterName, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled string) string {
6761+
func testAccContainerCluster_withNodeConfigKubeletConfigSettingsUpdates(clusterName, cpuManagerPolicy, cpuCfsQuotaPeriod, insecureKubeletReadonlyPortEnabled, networkName, subnetworkName string, podPidsLimit int, cpuCfsQuota bool) string {
67826762
return fmt.Sprintf(`
6783-
resource "google_container_cluster" "with_insecure_kubelet_readonly_port_enabled_in_node_config" {
6763+
resource "google_container_cluster" "with_node_config_kubelet_config_settings" {
67846764
name = "%s"
67856765
location = "us-central1-f"
67866766
initial_node_count = 1
67876767

67886768
node_config {
67896769
kubelet_config {
6770+
cpu_manager_policy = "%s"
6771+
cpu_cfs_quota = %v
6772+
cpu_cfs_quota_period = "%s"
67906773
insecure_kubelet_readonly_port_enabled = "%s"
6774+
pod_pids_limit = %v
67916775
}
67926776
}
67936777
deletion_protection = false
6794-
network = "%s"
6795-
subnetwork = "%s"
6778+
network = "%s"
6779+
subnetwork = "%s"
67966780
}
6797-
`, clusterName, insecureKubeletReadonlyPortEnabled, networkName, subnetworkName)
6781+
`, clusterName, cpuManagerPolicy, cpuCfsQuota, cpuCfsQuotaPeriod, insecureKubeletReadonlyPortEnabled, podPidsLimit, networkName, subnetworkName)
67986782
}
67996783

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

0 commit comments

Comments
 (0)