Skip to content

Commit e3ea42c

Browse files
google_container_cluster: add support for new GKE Gateway API controller (#6875) (#4976)
* add support for gateway api flag * fix test by adding proper release channel; add missing functions * add update cluster handling for gateway api config; extend test cases for gateway api config * remove problematic / unrecognized channels from gateway api; these channels are mentioned in the actual code base but are not recognized by the gcloud api Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent fada168 commit e3ea42c

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

.changelog/6875.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added `gateway_api_config` block to `google_container_cluster` resource for supporting the gke gateway api controller
3+
```

google-beta/resource_container_cluster.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,22 @@ func resourceContainerCluster() *schema.Resource {
17891789
},
17901790
},
17911791
},
1792+
"gateway_api_config": {
1793+
Type: schema.TypeList,
1794+
Optional: true,
1795+
MaxItems: 1,
1796+
Description: `Configuration for GKE Gateway API controller.`,
1797+
Elem: &schema.Resource{
1798+
Schema: map[string]*schema.Schema{
1799+
"channel": {
1800+
Type: schema.TypeString,
1801+
Required: true,
1802+
ValidateFunc: validation.StringInSlice([]string{"CHANNEL_DISABLED", "CHANNEL_STANDARD"}, false),
1803+
Description: `The Gateway API release channel to use for Gateway API.`,
1804+
},
1805+
},
1806+
},
1807+
},
17921808
},
17931809
}
17941810
}
@@ -1909,6 +1925,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
19091925
PrivateIpv6GoogleAccess: d.Get("private_ipv6_google_access").(string),
19101926
EnableL4ilbSubsetting: d.Get("enable_l4_ilb_subsetting").(bool),
19111927
DnsConfig: expandDnsConfig(d.Get("dns_config")),
1928+
GatewayApiConfig: expandGatewayApiConfig(d.Get("gateway_api_config")),
19121929
},
19131930
MasterAuth: expandMasterAuth(d.Get("master_auth")),
19141931
NotificationConfig: expandNotificationConfig(d.Get("notification_config")),
@@ -2403,6 +2420,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
24032420
if err := d.Set("dns_config", flattenDnsConfig(cluster.NetworkConfig.DnsConfig)); err != nil {
24042421
return err
24052422
}
2423+
if err := d.Set("gateway_api_config", flattenGatewayApiConfig(cluster.NetworkConfig.GatewayApiConfig)); err != nil {
2424+
return err
2425+
}
24062426
if err := d.Set("logging_config", flattenContainerClusterLoggingConfig(cluster.LoggingConfig)); err != nil {
24072427
return err
24082428
}
@@ -3388,6 +3408,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
33883408
log.Printf("[INFO] GKE cluster %s resource usage export config has been updated", d.Id())
33893409
}
33903410

3411+
if d.HasChange("gateway_api_config") {
3412+
if gac, ok := d.GetOk("gateway_api_config"); ok {
3413+
req := &container.UpdateClusterRequest{
3414+
Update: &container.ClusterUpdate{
3415+
DesiredGatewayApiConfig: expandGatewayApiConfig(gac),
3416+
},
3417+
}
3418+
3419+
updateF := updateFunc(req, "updating GKE Gateway API")
3420+
// Call update serially.
3421+
if err := lockedCall(lockKey, updateF); err != nil {
3422+
return err
3423+
}
3424+
3425+
log.Printf("[INFO] GKE cluster %s Gateway API has been updated", d.Id())
3426+
}
3427+
}
3428+
33913429
if d.HasChange("node_pool_defaults") && d.HasChange("node_pool_defaults.0.node_config_defaults.0.logging_variant") {
33923430
if v, ok := d.GetOk("node_pool_defaults.0.node_config_defaults.0.logging_variant"); ok {
33933431
loggingVariant := v.(string)
@@ -4404,6 +4442,18 @@ func expandDnsConfig(configured interface{}) *container.DNSConfig {
44044442
}
44054443
}
44064444

4445+
func expandGatewayApiConfig(configured interface{}) *container.GatewayAPIConfig {
4446+
l := configured.([]interface{})
4447+
if len(l) == 0 || l[0] == nil {
4448+
return nil
4449+
}
4450+
4451+
config := l[0].(map[string]interface{})
4452+
return &container.GatewayAPIConfig{
4453+
Channel: config["channel"].(string),
4454+
}
4455+
}
4456+
44074457
func expandContainerClusterLoggingConfig(configured interface{}) *container.LoggingConfig {
44084458
l := configured.([]interface{})
44094459
if len(l) == 0 {
@@ -5153,6 +5203,17 @@ func flattenDnsConfig(c *container.DNSConfig) []map[string]interface{} {
51535203
}
51545204
}
51555205

5206+
func flattenGatewayApiConfig(c *container.GatewayAPIConfig) []map[string]interface{} {
5207+
if c == nil {
5208+
return nil
5209+
}
5210+
return []map[string]interface{}{
5211+
{
5212+
"channel": c.Channel,
5213+
},
5214+
}
5215+
}
5216+
51565217
func flattenContainerClusterLoggingConfig(c *container.LoggingConfig) []map[string]interface{} {
51575218
if c == nil {
51585219
return nil

google-beta/resource_container_cluster_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,6 +3403,52 @@ func TestAccContainerCluster_withDNSConfig(t *testing.T) {
34033403
})
34043404
}
34053405

3406+
func TestAccContainerCluster_withGatewayApiConfig(t *testing.T) {
3407+
t.Parallel()
3408+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
3409+
vcrTest(t, resource.TestCase{
3410+
PreCheck: func() { testAccPreCheck(t) },
3411+
Providers: testAccProviders,
3412+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
3413+
Steps: []resource.TestStep{
3414+
{
3415+
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CHANNEL_DISABLED"),
3416+
},
3417+
{
3418+
ResourceName: "google_container_cluster.primary",
3419+
ImportState: true,
3420+
ImportStateVerify: true,
3421+
ImportStateVerifyIgnore: []string{"min_master_version"},
3422+
},
3423+
{
3424+
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CHANNEL_STANDARD"),
3425+
},
3426+
{
3427+
ResourceName: "google_container_cluster.primary",
3428+
ImportState: true,
3429+
ImportStateVerify: true,
3430+
ImportStateVerifyIgnore: []string{"min_master_version"},
3431+
},
3432+
},
3433+
})
3434+
}
3435+
3436+
func TestAccContainerCluster_withInvalidGatewayApiConfigChannel(t *testing.T) {
3437+
t.Parallel()
3438+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
3439+
vcrTest(t, resource.TestCase{
3440+
PreCheck: func() { testAccPreCheck(t) },
3441+
Providers: testAccProviders,
3442+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
3443+
Steps: []resource.TestStep{
3444+
{
3445+
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CANARY"),
3446+
ExpectError: regexp.MustCompile(`expected gateway_api_config\.0\.channel to be one of \[CHANNEL_DISABLED CHANNEL_STANDARD\], got CANARY`),
3447+
},
3448+
},
3449+
})
3450+
}
3451+
34063452
func TestAccContainerCluster_withTPUConfig(t *testing.T) {
34073453
t.Parallel()
34083454

@@ -6863,6 +6909,20 @@ resource "google_container_cluster" "with_dns_config" {
68636909
`, clusterName, clusterDns, clusterDnsDomain, clusterDnsScope)
68646910
}
68656911

6912+
func testAccContainerCluster_withGatewayApiConfig(clusterName string, gatewayApiChannel string) string {
6913+
return fmt.Sprintf(`
6914+
resource "google_container_cluster" "primary" {
6915+
name = "%s"
6916+
location = "us-central1-f"
6917+
initial_node_count = 1
6918+
min_master_version = "1.24"
6919+
gateway_api_config {
6920+
channel = "%s"
6921+
}
6922+
}
6923+
`, clusterName, gatewayApiChannel)
6924+
}
6925+
68666926
func testAccContainerCluster_withIdentityServiceConfigEnabled(name string) string {
68676927
return fmt.Sprintf(`
68686928
resource "google_container_cluster" "primary" {

website/docs/r/container_cluster.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ subnetwork in which the cluster's instances are launched.
355355
* `dns_config` - (Optional)
356356
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).
357357

358+
* `gateway_api_config` - (Optional)
359+
Configuration for [GKE Gateway API controller](https://cloud.google.com/kubernetes-engine/docs/concepts/gateway-api). Structure is [documented below](#nested_gateway_api_config).
360+
358361
<a name="nested_default_snat_status"></a>The `default_snat_status` block supports
359362

360363
* `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
@@ -1132,6 +1135,10 @@ and all pods running on the nodes. Specified as a map from the key, such as
11321135

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

1138+
<a name="nested_gateway_api_config"></a>The `gateway_api_config` block supports:
1139+
1140+
* `channel` - (Required) Which Gateway Api channel should be used. `CHANNEL_DISABLED` or `CHANNEL_STANDARD`.
1141+
11351142
## Attributes Reference
11361143

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

0 commit comments

Comments
 (0)