Skip to content

Commit 4181276

Browse files
tuunitericyz
andauthored
feat!: support for gateway api (#1510)
Co-authored-by: Eric Zhao <[email protected]>
1 parent bcd5e03 commit 4181276

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+820
-34
lines changed

.kitchen.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ suites:
8080
systems:
8181
- name: simple_regional_private
8282
backend: local
83+
- name: "simple_regional_with_gateway_api"
84+
driver:
85+
root_module_directory: test/fixtures/simple_regional_with_gateway_api
86+
verifier:
87+
systems:
88+
- name: simple_regional_with_gateway_api
89+
backend: local
8390
- name: "simple_regional_with_kubeconfig"
8491
driver:
8592
root_module_directory: test/fixtures/simple_regional_with_kubeconfig

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Then perform the following commands on the root folder:
155155
| filestore\_csi\_driver | The status of the Filestore CSI driver addon, which allows the usage of filestore instance as volumes | `bool` | `false` | no |
156156
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers. Either flag `add_master_webhook_firewall_rules` or `add_cluster_firewall_rules` (also adds egress rules) must be set to `true` for inbound-ports firewall rules to be applied. | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
157157
| firewall\_priority | Priority rule for firewall rules | `number` | `1000` | no |
158+
| gateway\_api\_channel | The gateway api channel of this cluster. Accepted values are `CHANNEL_STANDARD` and `CHANNEL_DISABLED`. | `string` | `null` | no |
158159
| gce\_pd\_csi\_driver | Whether this cluster should enable the Google Compute Engine Persistent Disk Container Storage Interface (CSI) Driver. | `bool` | `true` | no |
159160
| grant\_registry\_access | Grants created cluster-specific service account storage.objectViewer and artifactregistry.reader roles. | `bool` | `false` | no |
160161
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | `bool` | `true` | no |
@@ -215,6 +216,7 @@ Then perform the following commands on the root folder:
215216
| ca\_certificate | Cluster ca certificate (base64 encoded) |
216217
| cluster\_id | Cluster ID |
217218
| endpoint | Cluster endpoint |
219+
| gateway\_api\_channel | The gateway api channel of this cluster. |
218220
| horizontal\_pod\_autoscaling\_enabled | Whether horizontal pod autoscaling enabled |
219221
| http\_load\_balancing\_enabled | Whether http load balancing enabled |
220222
| identity\_namespace | Workload Identity pool |
@@ -302,8 +304,8 @@ The [project factory](https://github.com/terraform-google-modules/terraform-goog
302304
#### Kubectl
303305
- [kubectl](https://github.com/kubernetes/kubernetes/releases) 1.9.x
304306
#### Terraform and Plugins
305-
- [Terraform](https://www.terraform.io/downloads.html) 0.12
306-
- [Terraform Provider for GCP][terraform-provider-google] v3.41
307+
- [Terraform](https://www.terraform.io/downloads.html) 0.13+
308+
- [Terraform Provider for GCP][terraform-provider-google] v4.47
307309
#### gcloud
308310
Some submodules use the [terraform-google-gcloud](https://github.com/terraform-google-modules/terraform-google-gcloud) module. By default, this module assumes you already have gcloud installed in your $PATH.
309311
See the [module](https://github.com/terraform-google-modules/terraform-google-gcloud#downloading) documentation for more information.

autogen/main/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ The [project factory](https://github.com/terraform-google-modules/terraform-goog
254254
#### Kubectl
255255
- [kubectl](https://github.com/kubernetes/kubernetes/releases) 1.9.x
256256
#### Terraform and Plugins
257-
- [Terraform](https://www.terraform.io/downloads.html) 0.12
257+
- [Terraform](https://www.terraform.io/downloads.html) 0.13+
258258
{% if beta_cluster %}
259-
- [Terraform Provider for GCP Beta][terraform-provider-google-beta] v3.41
259+
- [Terraform Provider for GCP Beta][terraform-provider-google-beta] v4.47
260260
{% else %}
261-
- [Terraform Provider for GCP][terraform-provider-google] v3.41
261+
- [Terraform Provider for GCP][terraform-provider-google] v4.47
262262
{% endif %}
263263
#### gcloud
264264
Some submodules use the [terraform-google-gcloud](https://github.com/terraform-google-modules/terraform-google-gcloud) module. By default, this module assumes you already have gcloud installed in your $PATH.

autogen/main/cluster.tf.tmpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ resource "google_container_cluster" "primary" {
5353
channel = release_channel.value.channel
5454
}
5555
}
56+
57+
dynamic "gateway_api_config" {
58+
for_each = local.gateway_api_config
59+
60+
content {
61+
channel = gateway_api_config.value.channel
62+
}
63+
}
64+
5665
dynamic "cost_management_config" {
5766
for_each = var.enable_cost_allocation ? [1] : []
5867
content {

autogen/main/main.tf.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ locals {
5757
{% endif %}
5858

5959
release_channel = var.release_channel != null ? [{ channel : var.release_channel }] : []
60+
gateway_api_config = var.gateway_api_channel != null ? [{ channel : var.gateway_api_channel }] : []
6061

6162
{% if autopilot_cluster != true %}
6263
autoscaling_resource_limits = var.cluster_autoscaling.enabled ? concat([{

autogen/main/outputs.tf.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ output "release_channel" {
158158
value = var.release_channel
159159
}
160160

161+
output "gateway_api_channel" {
162+
description = "The gateway api channel of this cluster."
163+
value = var.gateway_api_channel
164+
}
165+
161166
output "identity_namespace" {
162167
description = "Workload Identity pool"
163168
value = length(local.cluster_workload_identity_config) > 0 ? local.cluster_workload_identity_config[0].workload_pool : null

autogen/main/variables.tf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ variable "release_channel" {
454454
default = null
455455
}
456456

457+
variable "gateway_api_channel" {
458+
type = string
459+
description = "The gateway api channel of this cluster. Accepted values are `CHANNEL_STANDARD` and `CHANNEL_DISABLED`."
460+
default = null
461+
}
462+
457463
variable "add_cluster_firewall_rules" {
458464
type = bool
459465
description = "Create additional firewall rules"

autogen/main/versions.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ terraform {
3838
required_providers {
3939
google = {
4040
source = "hashicorp/google"
41-
version = ">= 4.45.0, < 5.0"
41+
version = ">= 4.47.0, < 5.0"
4242
}
4343
kubernetes = {
4444
source = "hashicorp/kubernetes"

build/int.cloudbuild.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ steps:
121121
- verify simple-regional-with-kubeconfig-local
122122
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
123123
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy simple-regional-with-kubeconfig-local']
124+
- id: converge simple-regional-with-gateway-api-local
125+
waitFor:
126+
- create all
127+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
128+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge simple-regional-with-gateway-api-local']
129+
- id: verify simple-regional-with-gateway-api-local
130+
waitFor:
131+
- converge simple-regional-with-gateway-api-local
132+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
133+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify simple-regional-with-gateway-api-local']
134+
- id: destroy simple-regional-with-gateway-api-local
135+
waitFor:
136+
- verify simple-regional-with-gateway-api-local
137+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
138+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy simple-regional-with-gateway-api-local']
124139
- id: converge simple-regional-with-networking-local
125140
waitFor:
126141
- create all

cluster.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ resource "google_container_cluster" "primary" {
4747
channel = release_channel.value.channel
4848
}
4949
}
50+
51+
dynamic "gateway_api_config" {
52+
for_each = local.gateway_api_config
53+
54+
content {
55+
channel = gateway_api_config.value.channel
56+
}
57+
}
58+
5059
dynamic "cost_management_config" {
5160
for_each = var.enable_cost_allocation ? [1] : []
5261
content {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Simple Regional Cluster
2+
3+
This example illustrates how to create a simple cluster.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|------|---------|:--------:|
10+
| cluster\_name\_suffix | A suffix to append to the default cluster name | `string` | `""` | no |
11+
| compute\_engine\_service\_account | Service account to associate to the nodes in the cluster | `any` | n/a | yes |
12+
| enable\_binary\_authorization | Enable BinAuthZ Admission controller | `bool` | `false` | no |
13+
| gateway\_api\_channel | The gateway api channel of this cluster. Accepted values are `CHANNEL_STANDARD` and `CHANNEL_DISABLED`. | `string` | `null` | no |
14+
| ip\_range\_pods | The secondary ip range to use for pods | `any` | n/a | yes |
15+
| ip\_range\_services | The secondary ip range to use for services | `any` | n/a | yes |
16+
| network | The VPC network to host the cluster in | `any` | n/a | yes |
17+
| project\_id | The project ID to host the cluster in | `any` | n/a | yes |
18+
| region | The region to host the cluster in | `any` | n/a | yes |
19+
| skip\_provisioners | Flag to skip local-exec provisioners | `bool` | `false` | no |
20+
| subnetwork | The subnetwork to host the cluster in | `any` | n/a | yes |
21+
22+
## Outputs
23+
24+
| Name | Description |
25+
|------|-------------|
26+
| ca\_certificate | n/a |
27+
| client\_token | n/a |
28+
| cluster\_name | Cluster name |
29+
| ip\_range\_pods | The secondary IP range used for pods |
30+
| ip\_range\_services | The secondary IP range used for services |
31+
| kubernetes\_endpoint | n/a |
32+
| location | n/a |
33+
| master\_kubernetes\_version | The master Kubernetes version |
34+
| network | n/a |
35+
| project\_id | n/a |
36+
| region | n/a |
37+
| service\_account | The default service account used for running nodes. |
38+
| subnetwork | n/a |
39+
| zones | List of zones in which the cluster resides |
40+
41+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
42+
43+
To provision this example, run the following from within this directory:
44+
- `terraform init` to get the plugins
45+
- `terraform plan` to see the infrastructure plan
46+
- `terraform apply` to apply the infrastructure build
47+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
locals {
18+
cluster_type = "simple-regional-gatewayapi"
19+
}
20+
21+
data "google_client_config" "default" {}
22+
23+
provider "kubernetes" {
24+
host = "https://${module.gke.endpoint}"
25+
token = data.google_client_config.default.access_token
26+
cluster_ca_certificate = base64decode(module.gke.ca_certificate)
27+
}
28+
29+
module "gke" {
30+
source = "../../"
31+
project_id = var.project_id
32+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
33+
regional = true
34+
region = var.region
35+
network = var.network
36+
subnetwork = var.subnetwork
37+
ip_range_pods = var.ip_range_pods
38+
ip_range_services = var.ip_range_services
39+
create_service_account = false
40+
service_account = var.compute_engine_service_account
41+
enable_cost_allocation = true
42+
enable_binary_authorization = var.enable_binary_authorization
43+
skip_provisioners = var.skip_provisioners
44+
gateway_api_channel = var.gateway_api_channel
45+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "kubernetes_endpoint" {
18+
sensitive = true
19+
value = module.gke.endpoint
20+
}
21+
22+
output "client_token" {
23+
sensitive = true
24+
value = base64encode(data.google_client_config.default.access_token)
25+
}
26+
27+
output "ca_certificate" {
28+
value = module.gke.ca_certificate
29+
}
30+
31+
output "service_account" {
32+
description = "The default service account used for running nodes."
33+
value = module.gke.service_account
34+
}
35+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../test/fixtures/all_examples/test_outputs.tf
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The project ID to host the cluster in"
19+
}
20+
21+
variable "cluster_name_suffix" {
22+
description = "A suffix to append to the default cluster name"
23+
default = ""
24+
}
25+
26+
variable "region" {
27+
description = "The region to host the cluster in"
28+
}
29+
30+
variable "network" {
31+
description = "The VPC network to host the cluster in"
32+
}
33+
34+
variable "subnetwork" {
35+
description = "The subnetwork to host the cluster in"
36+
}
37+
38+
variable "ip_range_pods" {
39+
description = "The secondary ip range to use for pods"
40+
}
41+
42+
variable "ip_range_services" {
43+
description = "The secondary ip range to use for services"
44+
}
45+
46+
variable "compute_engine_service_account" {
47+
description = "Service account to associate to the nodes in the cluster"
48+
}
49+
50+
variable "skip_provisioners" {
51+
type = bool
52+
description = "Flag to skip local-exec provisioners"
53+
default = false
54+
}
55+
56+
variable "enable_binary_authorization" {
57+
description = "Enable BinAuthZ Admission controller"
58+
default = false
59+
}
60+
61+
variable "gateway_api_channel" {
62+
type = string
63+
description = "The gateway api channel of this cluster. Accepted values are `CHANNEL_STANDARD` and `CHANNEL_DISABLED`."
64+
default = null
65+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_providers {
19+
google = {
20+
source = "hashicorp/google"
21+
version = "~> 4.0"
22+
}
23+
kubernetes = {
24+
source = "hashicorp/kubernetes"
25+
}
26+
}
27+
required_version = ">= 0.13"
28+
}

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ locals {
5050
windows_node_pool_names = [for np in toset(var.windows_node_pools) : np.name]
5151
windows_node_pools = zipmap(local.windows_node_pool_names, tolist(toset(var.windows_node_pools)))
5252

53-
release_channel = var.release_channel != null ? [{ channel : var.release_channel }] : []
53+
release_channel = var.release_channel != null ? [{ channel : var.release_channel }] : []
54+
gateway_api_config = var.gateway_api_channel != null ? [{ channel : var.gateway_api_channel }] : []
5455

5556
autoscaling_resource_limits = var.cluster_autoscaling.enabled ? concat([{
5657
resource_type = "cpu"

0 commit comments

Comments
 (0)