Skip to content

Commit

Permalink
Promote release_channel to GA for GKE (#3834)
Browse files Browse the repository at this point in the history
  • Loading branch information
upodroid authored Aug 6, 2020
1 parent 19272c3 commit 1f18256
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
67 changes: 34 additions & 33 deletions third_party/terraform/resources/resource_container_cluster.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1775,28 +1774,23 @@ 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 {
return err
}

// 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
}

Expand All @@ -1805,28 +1799,33 @@ 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 {
return err
}

// 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
}

Expand All @@ -1835,28 +1834,28 @@ 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 {
return err
}

// 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
}

Expand All @@ -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{
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 1f18256

Please sign in to comment.