Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google_container_cluster: add support for new GKE Gateway API controller #6875

Merged
merged 4 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,22 @@ func resourceContainerCluster() *schema.Resource {
},
},
},
"gateway_api_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `Configuration for GKE Gateway API controller.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"channel": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"CHANNEL_DISABLED", "CHANNEL_STANDARD"}, false),
Description: `The Gateway API release channel to use for Gateway API.`,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -1837,6 +1853,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
PrivateIpv6GoogleAccess: d.Get("private_ipv6_google_access").(string),
EnableL4ilbSubsetting: d.Get("enable_l4_ilb_subsetting").(bool),
DnsConfig: expandDnsConfig(d.Get("dns_config")),
GatewayApiConfig: expandGatewayApiConfig(d.Get("gateway_api_config")),
},
MasterAuth: expandMasterAuth(d.Get("master_auth")),
NotificationConfig: expandNotificationConfig(d.Get("notification_config")),
Expand Down Expand Up @@ -2341,6 +2358,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("dns_config", flattenDnsConfig(cluster.NetworkConfig.DnsConfig)); err != nil {
return err
}
if err := d.Set("gateway_api_config", flattenGatewayApiConfig(cluster.NetworkConfig.GatewayApiConfig)); err != nil {
return err
}
if err := d.Set("logging_config", flattenContainerClusterLoggingConfig(cluster.LoggingConfig)); err != nil {
return err
}
Expand Down Expand Up @@ -3314,6 +3334,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[INFO] GKE cluster %s resource usage export config has been updated", d.Id())
}

if d.HasChange("gateway_api_config") {
if gac, ok := d.GetOk("gateway_api_config"); ok {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredGatewayApiConfig: expandGatewayApiConfig(gac),
},
}

updateF := updateFunc(req, "updating GKE Gateway API")
// Call update serially.
if err := lockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s Gateway API has been updated", d.Id())
}
}

if d.HasChange("node_pool_defaults") && d.HasChange("node_pool_defaults.0.node_config_defaults.0.logging_variant") {
if v, ok := d.GetOk("node_pool_defaults.0.node_config_defaults.0.logging_variant"); ok {
loggingVariant := v.(string)
Expand Down Expand Up @@ -4294,6 +4332,18 @@ func expandDnsConfig(configured interface{}) *container.DNSConfig {
}
}

func expandGatewayApiConfig(configured interface{}) *container.GatewayAPIConfig {
l := configured.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil
}

config := l[0].(map[string]interface{})
return &container.GatewayAPIConfig{
Channel: config["channel"].(string),
}
}

func expandContainerClusterLoggingConfig(configured interface{}) *container.LoggingConfig {
l := configured.([]interface{})
if len(l) == 0 {
Expand Down Expand Up @@ -5025,6 +5075,17 @@ func flattenDnsConfig(c *container.DNSConfig) []map[string]interface{} {
}
}

func flattenGatewayApiConfig(c *container.GatewayAPIConfig) []map[string]interface{} {
if c == nil {
return nil
}
return []map[string]interface{}{
{
"channel": c.Channel,
},
}
}

func flattenContainerClusterLoggingConfig(c *container.LoggingConfig) []map[string]interface{} {
if c == nil {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3330,6 +3330,52 @@ func TestAccContainerCluster_withDNSConfig(t *testing.T) {
})
}

func TestAccContainerCluster_withGatewayApiConfig(t *testing.T) {
t.Parallel()
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CHANNEL_DISABLED"),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version"},
},
{
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CHANNEL_STANDARD"),
melinath marked this conversation as resolved.
Show resolved Hide resolved
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version"},
},
},
})
}

func TestAccContainerCluster_withInvalidGatewayApiConfigChannel(t *testing.T) {
t.Parallel()
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CANARY"),
ExpectError: regexp.MustCompile(`expected gateway_api_config\.0\.channel to be one of \[CHANNEL_DISABLED CHANNEL_STANDARD\], got CANARY`),
},
},
})
}

<% unless version == 'ga' -%>
func TestAccContainerCluster_withTPUConfig(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -6584,6 +6630,20 @@ resource "google_container_cluster" "with_dns_config" {
`, clusterName, clusterDns, clusterDnsDomain, clusterDnsScope)
}

func testAccContainerCluster_withGatewayApiConfig(clusterName string, gatewayApiChannel string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-f"
initial_node_count = 1
min_master_version = "1.24"
gateway_api_config {
channel = "%s"
}
}
`, clusterName, gatewayApiChannel)
}

<% unless version == 'ga' -%>
func testAccContainerCluster_withIdentityServiceConfigEnabled(name string) string {
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ subnetwork in which the cluster's instances are launched.
* `dns_config` - (Optional)
Configuration for [Using Cloud DNS for GKE](https://cloud.google.com/kubernetes-engine/docs/how-to/cloud-dns). Structure is [documented below](#nested_dns_config).

* `gateway_api_config` - (Optional)
Configuration for [GKE Gateway API controller](https://cloud.google.com/kubernetes-engine/docs/concepts/gateway-api). Structure is [documented below](#nested_gateway_api_config).

<a name="nested_default_snat_status"></a>The `default_snat_status` block supports

* `disabled` - (Required) Whether the cluster disables default in-node sNAT rules. In-node sNAT rules will be disabled when defaultSnatStatus is disabled.When disabled is set to false, default IP masquerade rules will be applied to the nodes to prevent sNAT on cluster internal traffic
Expand Down Expand Up @@ -1111,6 +1114,10 @@ and all pods running on the nodes. Specified as a map from the key, such as

* `cluster_dns_domain` - (Optional) The suffix used for all cluster service records.

<a name="nested_gateway_api_config"></a>The `gateway_api_config` block supports:

* `channel` - (Required) Which Gateway Api channel should be used. `CHANNEL_DISABLED` or `CHANNEL_STANDARD`.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are
Expand Down