Skip to content

Commit cd4c063

Browse files
Fixes #180: Add tests for beta submodules/examples
#180 Added tests for the beta private cluster.
1 parent e3494d7 commit cd4c063

File tree

20 files changed

+546
-87
lines changed

20 files changed

+546
-87
lines changed

.kitchen.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ suites:
148148
systems:
149149
- name: workload_metadata_config
150150
backend: local
151+
- name: "beta_cluster"
152+
driver:
153+
root_module_directory: test/fixtures/beta_cluster
154+
verifier:
155+
systems:
156+
- name: gcloud
157+
backend: local
158+
controls:
159+
- gcloud
160+
- name: gcp
161+
backend: gcp
162+
controls:
163+
- gcp
151164
- name: "sandbox_enabled"
152165
driver:
153166
root_module_directory: test/fixtures/sandbox_enabled

build/int.cloudbuild.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,26 @@ steps:
241241
- verify workload-metadata-config-local
242242
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
243243
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy workload-metadata-config-local']
244+
- id: create beta-cluster-local
245+
waitFor:
246+
- prepare
247+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
248+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create beta-cluster-local']
249+
- id: converge beta-cluster-local
250+
waitFor:
251+
- create beta-cluster-local
252+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
253+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge beta-cluster-local']
254+
- id: verify beta-cluster-local
255+
waitFor:
256+
- converge beta-cluster-local
257+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
258+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify beta-cluster-local']
259+
- id: destroy beta-cluster-local
260+
waitFor:
261+
- verify beta-cluster-local
262+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
263+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy beta-cluster-local']
244264
- id: create sandbox-enabled-local
245265
waitFor:
246266
- prepare
@@ -264,6 +284,8 @@ steps:
264284
tags:
265285
- 'ci'
266286
- 'integration'
287+
options:
288+
machineType: 'N1_HIGHCPU_8'
267289
substitutions:
268290
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
269291
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.6'

modules/beta-private-cluster/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,9 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
174174
| master\_ipv4\_cidr\_block | (Beta) The IP range in CIDR notation to use for the hosted master network | string | `"10.0.0.0/28"` | no |
175175
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | string | `"monitoring.googleapis.com"` | no |
176176
| name | The name of the cluster (required) | string | n/a | yes |
177-
| network | The VPC network to host the cluster in (required) | string | n/a | yes |
177+
| network | The VPC network link to host the cluster in (required) | string | n/a | yes |
178178
| network\_policy | Enable network policy addon | bool | `"false"` | no |
179179
| network\_policy\_provider | The network policy provider. | string | `"CALICO"` | no |
180-
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | string | `""` | no |
181180
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | string | `"SECURE"` | no |
182181
| node\_pools | List of maps containing node pools | list(map(string)) | `<list>` | no |
183182
| node\_pools\_labels | Map of maps containing node labels by node-pool name | map(map(string)) | `<map>` | no |
@@ -199,7 +198,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
199198
| service\_account | The service account to run nodes as if not overridden in `node_pools`. The create_service_account variable default value (true) will cause a cluster-specific service account to be created. | string | `""` | no |
200199
| skip\_provisioners | Flag to skip all local-exec provisioners. It breaks `stub_domains` and `upstream_nameservers` variables functionality. | bool | `"false"` | no |
201200
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map(list(string)) | `<map>` | no |
202-
| subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes |
201+
| subnetwork | The subnetwork link to host the cluster in (required) | string | n/a | yes |
203202
| upstream\_nameservers | If specified, the values replace the nameservers taken by default from the node’s /etc/resolv.conf | list | `<list>` | no |
204203
| zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | list(string) | `<list>` | no |
205204

modules/beta-private-cluster/cluster.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ resource "google_container_cluster" "primary" {
3030
location = local.location
3131
node_locations = local.node_locations
3232
cluster_ipv4_cidr = var.cluster_ipv4_cidr
33-
network = data.google_compute_network.gke_network.self_link
33+
network = var.network
3434

3535
dynamic "network_policy" {
3636
for_each = local.cluster_network_policy
@@ -49,7 +49,7 @@ resource "google_container_cluster" "primary" {
4949
}
5050
}
5151

52-
subnetwork = data.google_compute_subnetwork.gke_subnetwork.self_link
52+
subnetwork = var.subnetwork
5353
min_master_version = local.master_version
5454

5555
logging_service = var.logging_service

modules/beta-private-cluster/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ locals {
4949

5050
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
5151
upstream_nameservers_config = length(var.upstream_nameservers) > 0
52-
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id
5352
zone_count = length(var.zones)
5453
cluster_type = var.regional ? "regional" : "zonal"
5554
// auto upgrade by defaults only for regional cluster as long it has multiple masters versus zonal clusters have only have a single master so upgrades are more dangerous.

modules/beta-private-cluster/networks.tf

Lines changed: 0 additions & 32 deletions
This file was deleted.

modules/beta-private-cluster/variables.tf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,12 @@ variable "zones" {
5252

5353
variable "network" {
5454
type = string
55-
description = "The VPC network to host the cluster in (required)"
56-
}
57-
58-
variable "network_project_id" {
59-
type = string
60-
description = "The project ID of the shared VPC's host (for shared vpc support)"
61-
default = ""
55+
description = "The VPC network link to host the cluster in (required)"
6256
}
6357

6458
variable "subnetwork" {
6559
type = string
66-
description = "The subnetwork to host the cluster in (required)"
60+
description = "The subnetwork link to host the cluster in (required)"
6761
}
6862

6963
variable "kubernetes_version" {

modules/beta-public-cluster/cluster.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ resource "google_container_cluster" "primary" {
3030
location = local.location
3131
node_locations = local.node_locations
3232
cluster_ipv4_cidr = var.cluster_ipv4_cidr
33-
network = data.google_compute_network.gke_network.self_link
33+
network = var.network
3434

3535
dynamic "network_policy" {
3636
for_each = local.cluster_network_policy
@@ -49,7 +49,7 @@ resource "google_container_cluster" "primary" {
4949
}
5050
}
5151

52-
subnetwork = data.google_compute_subnetwork.gke_subnetwork.self_link
52+
subnetwork = var.subnetwork
5353
min_master_version = local.master_version
5454

5555
logging_service = var.logging_service

modules/beta-public-cluster/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ locals {
4949

5050
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
5151
upstream_nameservers_config = length(var.upstream_nameservers) > 0
52-
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id
5352
zone_count = length(var.zones)
5453
cluster_type = var.regional ? "regional" : "zonal"
5554
// auto upgrade by defaults only for regional cluster as long it has multiple masters versus zonal clusters have only have a single master so upgrades are more dangerous.

modules/beta-public-cluster/networks.tf

Lines changed: 0 additions & 32 deletions
This file was deleted.

modules/beta-public-cluster/variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ variable "network" {
5555
description = "The VPC network to host the cluster in (required)"
5656
}
5757

58-
variable "network_project_id" {
59-
type = string
60-
description = "The project ID of the shared VPC's host (for shared vpc support)"
61-
default = ""
62-
}
63-
6458
variable "subnetwork" {
6559
type = string
6660
description = "The subnetwork to host the cluster in (required)"

test/ci/beta-cluster.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
3+
platform: linux
4+
5+
inputs:
6+
- name: pull-request
7+
path: terraform-google-kubernetes-engine
8+
9+
run:
10+
path: make
11+
args: ['test_integration']
12+
dir: terraform-google-kubernetes-engine
13+
14+
params:
15+
SUITE: "beta-cluster-local"
16+
COMPUTE_ENGINE_SERVICE_ACCOUNT: ""
17+
REGION: "us-east4"
18+
ZONES: '["us-east4-a", "us-east4-b", "us-east4-c"]'

test/fixtures/beta_cluster/main.tf

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
18+
provider "google" {
19+
version = "~> 2.18.0"
20+
project = var.project_id
21+
region = var.region
22+
}
23+
24+
provider "google-beta" {
25+
version = "~> 2.18.0"
26+
project = var.project_id
27+
region = var.region
28+
}
29+
30+
locals {
31+
name = "beta-cluster-${random_string.suffix.result}"
32+
}
33+
34+
resource "google_kms_key_ring" "db" {
35+
location = var.region
36+
name = "${local.name}-db"
37+
}
38+
39+
resource "google_kms_crypto_key" "db" {
40+
name = local.name
41+
key_ring = google_kms_key_ring.db.self_link
42+
}
43+
44+
module "this" {
45+
source = "../../../modules/beta-public-cluster"
46+
47+
name = local.name
48+
project_id = var.project_id
49+
regional = false
50+
region = var.region
51+
zones = slice(var.zones, 0, 1)
52+
network = google_compute_network.main.self_link
53+
subnetwork = google_compute_subnetwork.main.self_link
54+
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
55+
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
56+
service_account = "create"
57+
58+
// Beta features
59+
istio = true
60+
61+
database_encryption = [{
62+
state = "ENCRYPTED"
63+
key_name = google_kms_crypto_key.db.self_link
64+
}]
65+
66+
cloudrun = true
67+
68+
enable_binary_authorization = true
69+
70+
pod_security_policy_config = [{
71+
enabled = true
72+
}]
73+
74+
node_metadata = "EXPOSE"
75+
}
76+
77+
data "google_client_config" "default" {
78+
}

test/fixtures/beta_cluster/network.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
resource "random_string" "suffix" {
18+
length = 4
19+
special = false
20+
upper = false
21+
}
22+
23+
resource "google_compute_network" "main" {
24+
name = "cft-gke-test-${random_string.suffix.result}"
25+
auto_create_subnetworks = false
26+
}
27+
28+
resource "google_compute_subnetwork" "main" {
29+
name = "cft-gke-test-${random_string.suffix.result}"
30+
ip_cidr_range = "10.0.0.0/17"
31+
region = var.region
32+
network = google_compute_network.main.self_link
33+
34+
secondary_ip_range {
35+
range_name = "cft-gke-test-pods-${random_string.suffix.result}"
36+
ip_cidr_range = "192.168.0.0/18"
37+
}
38+
39+
secondary_ip_range {
40+
range_name = "cft-gke-test-services-${random_string.suffix.result}"
41+
ip_cidr_range = "192.168.64.0/18"
42+
}
43+
}
44+

0 commit comments

Comments
 (0)