From 1f18256978cb7323f9d4fd7097edd4506966a614 Mon Sep 17 00:00:00 2001 From: Upo Date: Thu, 6 Aug 2020 17:22:51 +0100 Subject: [PATCH] Promote release_channel to GA for GKE (#3834) --- .../resource_container_cluster.go.erb | 67 ++++++++++--------- .../resource_container_cluster_test.go.erb | 6 +- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 2e88c9559016..f3134071c91e 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -1293,8 +1293,8 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er Enabled: d.Get("enable_shielded_nodes").(bool), ForceSendFields: []string{"Enabled"}, }, -<% unless version == 'ga' -%> ReleaseChannel: expandReleaseChannel(d.Get("release_channel")), +<% unless version == 'ga' -%> ClusterTelemetry: expandClusterTelemetry(d.Get("cluster_telemetry")), EnableTpu: d.Get("enable_tpu").(bool), NetworkConfig: &containerBeta.NetworkConfig{ @@ -1556,13 +1556,12 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro if cluster.ShieldedNodes != nil { d.Set("enable_shielded_nodes", cluster.ShieldedNodes.Enabled) } -<% unless version == 'ga' -%> - d.Set("enable_tpu", cluster.EnableTpu) - d.Set("tpu_ipv4_cidr_block", cluster.TpuIpv4CidrBlock) - if err := d.Set("release_channel", flattenReleaseChannel(cluster.ReleaseChannel)); err != nil { return err } +<% unless version == 'ga' -%> + d.Set("enable_tpu", cluster.EnableTpu) + d.Set("tpu_ipv4_cidr_block", cluster.TpuIpv4CidrBlock) if err := d.Set("default_snat_status", flattenDefaultSnatStatus(cluster.NetworkConfig.DefaultSnatStatus)); err != nil { return err @@ -1775,19 +1774,14 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er d.SetPartial("enable_shielded_nodes") } -<% unless version == 'ga' -%> - if d.HasChange("enable_intranode_visibility") { - enabled := d.Get("enable_intranode_visibility").(bool) + if d.HasChange("release_channel") { req := &containerBeta.UpdateClusterRequest{ Update: &containerBeta.ClusterUpdate{ - DesiredIntraNodeVisibilityConfig: &containerBeta.IntraNodeVisibilityConfig{ - Enabled: enabled, - ForceSendFields: []string{"Enabled"}, - }, + DesiredReleaseChannel: expandReleaseChannel(d.Get("release_channel")), }, } updateF := func() error { - log.Println("[DEBUG] updating enable_intranode_visibility") + log.Println("[DEBUG] updating release_channel") name := containerClusterFullName(project, location, clusterName) op, err := config.clientContainerBeta.Projects.Locations.Clusters.Update(name, req).Do() if err != nil { @@ -1795,8 +1789,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er } // Wait until it's updated - err = containerOperationWait(config, op, project, location, "updating GKE Intra Node Visibility", d.Timeout(schema.TimeoutUpdate)) - log.Println("[DEBUG] done updating enable_intranode_visibility") + err = containerOperationWait(config, op, project, location, "updating Release Channel", d.Timeout(schema.TimeoutUpdate)) + log.Println("[DEBUG] done updating release_channel") return err } @@ -1805,19 +1799,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er return err } - log.Printf("[INFO] GKE cluster %s Intra Node Visibility has been updated to %v", d.Id(), enabled) + log.Printf("[INFO] GKE cluster %s Release Channel has been updated to %#v", d.Id(), req.Update.DesiredReleaseChannel) - d.SetPartial("enable_intranode_visibility") + d.SetPartial("release_channel") } - if d.HasChange("default_snat_status") { +<% unless version == 'ga' -%> + if d.HasChange("enable_intranode_visibility") { + enabled := d.Get("enable_intranode_visibility").(bool) req := &containerBeta.UpdateClusterRequest{ Update: &containerBeta.ClusterUpdate{ - DesiredDefaultSnatStatus: expandDefaultSnatStatus(d.Get("default_snat_status")), + DesiredIntraNodeVisibilityConfig: &containerBeta.IntraNodeVisibilityConfig{ + Enabled: enabled, + ForceSendFields: []string{"Enabled"}, + }, }, } updateF := func() error { - log.Println("[DEBUG] updating default_snat_status") + log.Println("[DEBUG] updating enable_intranode_visibility") name := containerClusterFullName(project, location, clusterName) op, err := config.clientContainerBeta.Projects.Locations.Clusters.Update(name, req).Do() if err != nil { @@ -1825,8 +1824,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er } // Wait until it's updated - err = containerOperationWait(config, op, project, location, "updating GKE Default SNAT status", d.Timeout(schema.TimeoutUpdate)) - log.Println("[DEBUG] done updating default_snat_status") + err = containerOperationWait(config, op, project, location, "updating GKE Intra Node Visibility", d.Timeout(schema.TimeoutUpdate)) + log.Println("[DEBUG] done updating enable_intranode_visibility") return err } @@ -1835,19 +1834,19 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er return err } - log.Printf("[INFO] GKE cluster %s Default SNAT status has been updated", d.Id()) + log.Printf("[INFO] GKE cluster %s Intra Node Visibility has been updated to %v", d.Id(), enabled) - d.SetPartial("default_snat_status") + d.SetPartial("enable_intranode_visibility") } - if d.HasChange("release_channel") { + if d.HasChange("default_snat_status") { req := &containerBeta.UpdateClusterRequest{ Update: &containerBeta.ClusterUpdate{ - DesiredReleaseChannel: expandReleaseChannel(d.Get("release_channel")), + DesiredDefaultSnatStatus: expandDefaultSnatStatus(d.Get("default_snat_status")), }, } updateF := func() error { - log.Println("[DEBUG] updating release_channel") + log.Println("[DEBUG] updating default_snat_status") name := containerClusterFullName(project, location, clusterName) op, err := config.clientContainerBeta.Projects.Locations.Clusters.Update(name, req).Do() if err != nil { @@ -1855,8 +1854,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er } // Wait until it's updated - err = containerOperationWait(config, op, project, location, "updating Release Channel", d.Timeout(schema.TimeoutUpdate)) - log.Println("[DEBUG] done updating release_channel") + err = containerOperationWait(config, op, project, location, "updating GKE Default SNAT status", d.Timeout(schema.TimeoutUpdate)) + log.Println("[DEBUG] done updating default_snat_status") return err } @@ -1865,10 +1864,11 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er return err } - log.Printf("[INFO] GKE cluster %s Release Channel has been updated to %#v", d.Id(), req.Update.DesiredReleaseChannel) + log.Printf("[INFO] GKE cluster %s Default SNAT status has been updated", d.Id()) - d.SetPartial("release_channel") + d.SetPartial("default_snat_status") } + <% end -%> if d.HasChange("maintenance_policy") { req := &containerBeta.SetMaintenancePolicyRequest{ @@ -2939,7 +2939,6 @@ func expandDatabaseEncryption(configured interface{}) *containerBeta.DatabaseEnc } } -<% unless version == 'ga' -%> func expandReleaseChannel(configured interface{}) *containerBeta.ReleaseChannel { l := configured.([]interface{}) if len(l) == 0 || l[0] == nil { @@ -2951,6 +2950,7 @@ func expandReleaseChannel(configured interface{}) *containerBeta.ReleaseChannel } } +<% unless version == 'ga' -%> func expandClusterTelemetry(configured interface{}) *containerBeta.ClusterTelemetry { l := configured.([]interface{}) if len(l) == 0 || l[0] == nil { @@ -3210,7 +3210,6 @@ func flattenVerticalPodAutoscaling(c *containerBeta.VerticalPodAutoscaling) []ma } } -<% unless version == 'ga' -%> func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interface{} { result := []map[string]interface{}{} if c != nil { @@ -3226,6 +3225,8 @@ func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interfa return result } +<% unless version == 'ga' -%> + func flattenClusterTelemetry(c *containerBeta.ClusterTelemetry) []map[string]interface{} { result := []map[string]interface{}{} if c != nil { diff --git a/third_party/terraform/tests/resource_container_cluster_test.go.erb b/third_party/terraform/tests/resource_container_cluster_test.go.erb index dde5579f6471..a0edfe09af4e 100644 --- a/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -338,7 +338,7 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) { }) } -<% unless version == 'ga' -%> + func TestAccContainerCluster_withReleaseChannelEnabled(t *testing.T) { t.Parallel() clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10)) @@ -429,6 +429,7 @@ func TestAccContainerCluster_withInvalidReleaseChannel(t *testing.T) { }) } +<% unless version == 'ga' -%> func TestAccContainerCluster_withTelemetryEnabled(t *testing.T) { t.Parallel() clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10)) @@ -2282,7 +2283,7 @@ resource "google_container_cluster" "with_network_policy_enabled" { `, clusterName) } -<% unless version == 'ga' -%> + func testAccContainerCluster_withReleaseChannelEnabled(clusterName string, channel string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_release_channel" { @@ -2313,6 +2314,7 @@ resource "google_container_cluster" "with_release_channel" { `, clusterName, channel) } +<% unless version == 'ga' -%> func testAccContainerCluster_withTelemetryEnabled(clusterName string, telemetryType string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_cluster_telemetry" {