Skip to content

Commit 79a50e6

Browse files
hoskerianoopkverma-google
authored andcommitted
Fix nodeConfigDefaults on cluster create. (GoogleCloudPlatform#12664)
1 parent bc8a9e2 commit 79a50e6

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ func expandNodeConfigDefaults(configured interface{}) *container.NodeConfigDefau
870870
if v, ok := config["insecure_kubelet_readonly_port_enabled"]; ok {
871871
nodeConfigDefaults.NodeKubeletConfig = &container.NodeKubeletConfig{
872872
InsecureKubeletReadonlyPortEnabled: expandInsecureKubeletReadonlyPortEnabled(v),
873+
ForceSendFields: []string{"InsecureKubeletReadonlyPortEnabled"},
873874
}
874875
}
875876
if variant, ok := config["logging_variant"]; ok {

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

+76-5
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,7 @@ func TestAccContainerCluster_withInsecureKubeletReadonlyPortEnabledInNodePool(t
18611861
})
18621862
}
18631863

1864+
18641865
// This is for `node_pool_defaults.node_config_defaults` - the default settings
18651866
// for newly created nodepools
18661867
func TestAccContainerCluster_withInsecureKubeletReadonlyPortEnabledDefaultsUpdates(t *testing.T) {
@@ -3574,7 +3575,36 @@ func TestAccContainerCluster_withAutopilotKubeletConfig(t *testing.T) {
35743575
})
35753576
}
35763577

3577-
func TestAccContainerCluster_withAutopilot_withNodePoolDefaults(t *testing.T) {
3578+
// func TestAccContainerCluster_withAutopilot_withNodePoolDefaults(t *testing.T) {
3579+
// nodePoolDefaults is not allowed on GKE Autopilot clusters, error from GKE is:
3580+
// `Setting node_pool_defaults.node_config_defaults.node_kubelet_config is not allowed on GKE Autopilot clusters.`
3581+
func TestAccContainerCluster_withAutopilot_withNodePoolAutoConfig(t *testing.T) {
3582+
t.Parallel()
3583+
3584+
randomSuffix := acctest.RandString(t, 10)
3585+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randomSuffix)
3586+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
3587+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
3588+
3589+
acctest.VcrTest(t, resource.TestCase{
3590+
PreCheck: func() { acctest.AccTestPreCheck(t) },
3591+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
3592+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
3593+
Steps: []resource.TestStep{
3594+
{
3595+
Config: testAccContainerCluster_withAutopilot_withNodePoolAutoConfig(clusterName, networkName, subnetworkName, "FALSE"),
3596+
},
3597+
{
3598+
ResourceName: "google_container_cluster.primary",
3599+
ImportState: true,
3600+
ImportStateVerify: true,
3601+
ImportStateVerifyIgnore: []string{"deletion_protection"},
3602+
},
3603+
},
3604+
})
3605+
}
3606+
3607+
func TestAccContainerCluster_withStandard_withNodePoolDefaults(t *testing.T) {
35783608
t.Parallel()
35793609

35803610
randomSuffix := acctest.RandString(t, 10)
@@ -3588,7 +3618,7 @@ func TestAccContainerCluster_withAutopilot_withNodePoolDefaults(t *testing.T) {
35883618
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
35893619
Steps: []resource.TestStep{
35903620
{
3591-
Config: testAccContainerCluster_withAutopilot_withNodePoolDefaults(clusterName, networkName, subnetworkName),
3621+
Config: testAccContainerCluster_withStandard_withNodePoolDefaults(clusterName, networkName, subnetworkName, "FALSE"),
35923622
},
35933623
{
35943624
ResourceName: "google_container_cluster.primary",
@@ -3601,6 +3631,7 @@ func TestAccContainerCluster_withAutopilot_withNodePoolDefaults(t *testing.T) {
36013631
}
36023632

36033633

3634+
36043635
func TestAccContainerCluster_withAutopilotResourceManagerTags(t *testing.T) {
36053636
t.Parallel()
36063637

@@ -11480,16 +11511,57 @@ resource "google_container_cluster" "primary" {
1148011511
location = "us-central1"
1148111512
enable_autopilot = true
1148211513

11514+
node_pool_defaults {
11515+
node_kubelet_config {
11516+
}
11517+
}
11518+
11519+
deletion_protection = false
11520+
network = "%s"
11521+
subnetwork = "%s"
11522+
}
11523+
`, name, networkName, subnetworkName)
11524+
}
11525+
11526+
11527+
func testAccContainerCluster_withAutopilot_withNodePoolAutoConfig(name, networkName, subnetworkName string, insecureKubeletReadonlyPortEnabled string) string {
11528+
return fmt.Sprintf(`
11529+
resource "google_container_cluster" "primary" {
11530+
name = "%s"
11531+
location = "us-central1"
11532+
enable_autopilot = true
11533+
11534+
node_pool_auto_config {
11535+
node_kubelet_config {
11536+
insecure_kubelet_readonly_port_enabled = "%s"
11537+
}
11538+
}
11539+
11540+
deletion_protection = false
11541+
network = "%s"
11542+
subnetwork = "%s"
11543+
}
11544+
`, name, insecureKubeletReadonlyPortEnabled, networkName, subnetworkName)
11545+
}
11546+
11547+
func testAccContainerCluster_withStandard_withNodePoolDefaults(name, networkName, subnetworkName string, insecureKubeletReadonlyPortEnabled string) string {
11548+
return fmt.Sprintf(`
11549+
resource "google_container_cluster" "primary" {
11550+
name = "%s"
11551+
location = "us-central1-a"
11552+
initial_node_count = 1
11553+
1148311554
node_pool_defaults {
1148411555
node_config_defaults {
11556+
insecure_kubelet_readonly_port_enabled = "%s"
1148511557
}
1148611558
}
1148711559

1148811560
deletion_protection = false
1148911561
network = "%s"
1149011562
subnetwork = "%s"
1149111563
}
11492-
`, name, networkName, subnetworkName)
11564+
`, name, insecureKubeletReadonlyPortEnabled, networkName, subnetworkName)
1149311565
}
1149411566

1149511567
func testAccContainerCluster_resourceManagerTags(projectID, clusterName, networkName, subnetworkName, randomSuffix string, tagResourceNumber int) string {
@@ -12880,5 +12952,4 @@ resource "google_container_cluster" "with_enterprise_config" {
1288012952
deletion_protection = false
1288112953
}
1288212954
`, projectID, clusterName, networkName, subnetworkName)
12883-
}
12884-
12955+
}

0 commit comments

Comments
 (0)