Skip to content

Commit 7f91489

Browse files
authored
Merge branch 'master' into 37-disable-client-cert
2 parents 5c8f0cb + 6bba988 commit 7f91489

File tree

31 files changed

+1091
-88
lines changed

31 files changed

+1091
-88
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1414
* Add `basic_auth_username` set to `""` by default #40
1515
* Add `basic_auth_password` set to `""` by default #40
1616
* Add `issue_client_certificate` set to `false` by default #40
17+
* Add `initial_node_count` parameter to node_pool block. #60
1718

1819
## [v0.4.0] - 2018-12-19
1920
### Added

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ test_integration:
8585
generate_docs:
8686
@source test/make.sh && generate_docs
8787

88+
.PHONY: generate
89+
generate:
90+
@pip install --user -r ./helpers/generate_modules/requirements.txt
91+
@./helpers/generate_modules/generate_modules.py
92+
8893
# Versioning
8994
.PHONY: version
9095
version:

README.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ module "gke" {
3030
3131
node_pools = [
3232
{
33-
name = "default-node-pool"
34-
machine_type = "n1-standard-2"
35-
min_count = 1
36-
max_count = 100
37-
disk_size_gb = 100
38-
disk_type = "pd-standard"
39-
image_type = "COS"
40-
auto_repair = true
41-
auto_upgrade = true
42-
service_account = "project-service-account@<PROJECT ID>.iam.gserviceaccount.com"
43-
preemptible = false
33+
name = "default-node-pool"
34+
machine_type = "n1-standard-2"
35+
min_count = 1
36+
max_count = 100
37+
disk_size_gb = 100
38+
disk_type = "pd-standard"
39+
image_type = "COS"
40+
auto_repair = true
41+
auto_upgrade = true
42+
service_account = "project-service-account@<PROJECT ID>.iam.gserviceaccount.com"
43+
preemptible = false
44+
initial_node_count = 80
4445
},
4546
]
4647
@@ -201,13 +202,20 @@ The project has the following folders and files:
201202

202203
- /: root folder
203204
- /examples: examples for using this module
205+
- /helpers: Helper scripts
204206
- /scripts: Scripts for specific tasks on module (see Infrastructure section on this file)
205207
- /test: Folders with files for testing the module (see Testing section on this file)
206208
- /main.tf: main file for this module, contains all the resources to create
207209
- /variables.tf: all the variables for the module
208210
- /output.tf: the outputs of the module
209211
- /readme.MD: this file
210212

213+
## Templating
214+
215+
To more cleanly handle cases where desired functionality would require complex duplication of Terraform resources (i.e. [PR 51](https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/51)), this repository is largely generated from the [`autogen`](./autogen) directory.
216+
217+
The root module is generated by running `make generate`. Changes to this repository should be made in the [`autogen`](./autogen) directory where appropriate.
218+
211219
## Testing
212220

213221
### Requirements
@@ -227,23 +235,22 @@ Integration tests are run though [test-kitchen](https://github.com/test-kitchen/
227235

228236
Six test-kitchen instances are defined:
229237

230-
- `deploy_service`
231-
- `node_pool`
232-
- `shared_vpc`
233-
- `simple_regional`
234-
- `simple_zonal`
235-
- `stub_domains`
238+
- `deploy-service`
239+
- `node-pool`
240+
- `shared-vpc`
241+
- `simple-regional`
242+
- `simple-zonal`
243+
- `stub-domains`
236244

237245
The test-kitchen instances in `test/fixtures/` wrap identically-named examples in the `examples/` directory.
238246

239247
#### Setup
240248

241249
1. Configure the [test fixtures](#test-configuration)
242250
2. Download a Service Account key with the necessary permissions and put it in the module's root directory with the name `credentials.json`.
243-
3. Build the Docker containers for testing:
251+
3. Build the Docker container for testing:
244252

245253
```
246-
make docker_build_terraform
247254
make docker_build_kitchen_terraform
248255
```
249256
4. Run the testing container in interactive mode:
@@ -252,7 +259,7 @@ The test-kitchen instances in `test/fixtures/` wrap identically-named examples i
252259
make docker_run
253260
```
254261

255-
The module root directory will be loaded into the Docker container at `/cftk/workdir/`.
262+
The module root directory will be loaded into the Docker container at `/cft/workdir/`.
256263
5. Run kitchen-terraform to test the infrastructure:
257264

258265
1. `kitchen create` creates Terraform state and downloads modules, if applicable.

auth.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
// This file was automatically generated from a template in ./autogen
18+
1719
/******************************************
1820
Retrieve authentication token
1921
*****************************************/
@@ -27,4 +29,4 @@ provider "kubernetes" {
2729
host = "https://${local.cluster_endpoint}"
2830
token = "${data.google_client_config.default.access_token}"
2931
cluster_ca_certificate = "${base64decode(local.cluster_ca_certificate)}"
30-
}
32+
}

autogen/auth.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
{{ autogeneration_note }}
18+
19+
/******************************************
20+
Retrieve authentication token
21+
*****************************************/
22+
data "google_client_config" "default" {}
23+
24+
/******************************************
25+
Configure provider
26+
*****************************************/
27+
provider "kubernetes" {
28+
load_config_file = false
29+
host = "https://${local.cluster_endpoint}"
30+
token = "${data.google_client_config.default.access_token}"
31+
cluster_ca_certificate = "${base64decode(local.cluster_ca_certificate)}"
32+
}

autogen/cluster_regional.tf

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
{{ autogeneration_note }}
18+
19+
/******************************************
20+
Create regional cluster
21+
*****************************************/
22+
resource "google_container_cluster" "primary" {
23+
count = "${var.regional ? 1 : 0}"
24+
name = "${var.name}"
25+
description = "${var.description}"
26+
project = "${var.project_id}"
27+
28+
region = "${var.region}"
29+
additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
30+
31+
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
32+
subnetwork = "${replace(data.google_compute_subnetwork.gke_subnetwork.self_link, "https://www.googleapis.com/compute/v1/", "")}"
33+
min_master_version = "${local.kubernetes_version}"
34+
35+
logging_service = "${var.logging_service}"
36+
monitoring_service = "${var.monitoring_service}"
37+
38+
master_authorized_networks_config = "${var.master_authorized_networks_config}"
39+
40+
addons_config {
41+
http_load_balancing {
42+
disabled = "${var.http_load_balancing ? 0 : 1}"
43+
}
44+
45+
horizontal_pod_autoscaling {
46+
disabled = "${var.horizontal_pod_autoscaling ? 0 : 1}"
47+
}
48+
49+
kubernetes_dashboard {
50+
disabled = "${var.kubernetes_dashboard ? 0 : 1}"
51+
}
52+
53+
network_policy_config {
54+
disabled = "${var.network_policy ? 0 : 1}"
55+
}
56+
}
57+
58+
ip_allocation_policy {
59+
cluster_secondary_range_name = "${var.ip_range_pods}"
60+
services_secondary_range_name = "${var.ip_range_services}"
61+
}
62+
63+
maintenance_policy {
64+
daily_maintenance_window {
65+
start_time = "${var.maintenance_start_time}"
66+
}
67+
}
68+
69+
lifecycle {
70+
ignore_changes = ["node_pool"]
71+
}
72+
73+
timeouts {
74+
create = "30m"
75+
update = "30m"
76+
delete = "30m"
77+
}
78+
79+
node_pool {
80+
name = "default-pool"
81+
82+
node_config {
83+
service_account = "${lookup(var.node_pools[0], "service_account", var.service_account)}"
84+
}
85+
}
86+
87+
remove_default_node_pool = "${var.remove_default_node_pool}"
88+
}
89+
90+
/******************************************
91+
Create regional node pools
92+
*****************************************/
93+
resource "google_container_node_pool" "pools" {
94+
count = "${var.regional ? length(var.node_pools) : 0}"
95+
name = "${lookup(var.node_pools[count.index], "name")}"
96+
project = "${var.project_id}"
97+
region = "${var.region}"
98+
cluster = "${var.name}"
99+
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version)}"
100+
initial_node_count = "${lookup(var.node_pools[count.index], "initial_node_count", lookup(var.node_pools[count.index], "min_count", 1))}"
101+
102+
autoscaling {
103+
min_node_count = "${lookup(var.node_pools[count.index], "min_count", 1)}"
104+
max_node_count = "${lookup(var.node_pools[count.index], "max_count", 100)}"
105+
}
106+
107+
management {
108+
auto_repair = "${lookup(var.node_pools[count.index], "auto_repair", true)}"
109+
auto_upgrade = "${lookup(var.node_pools[count.index], "auto_upgrade", true)}"
110+
}
111+
112+
node_config {
113+
image_type = "${lookup(var.node_pools[count.index], "image_type", "COS")}"
114+
machine_type = "${lookup(var.node_pools[count.index], "machine_type", "n1-standard-2")}"
115+
labels = "${merge(map("cluster_name", var.name), map("node_pool", lookup(var.node_pools[count.index], "name")), var.node_pools_labels["all"], var.node_pools_labels[lookup(var.node_pools[count.index], "name")])}"
116+
metadata = "${merge(map("cluster_name", var.name), map("node_pool", lookup(var.node_pools[count.index], "name")), var.node_pools_metadata["all"], var.node_pools_metadata[lookup(var.node_pools[count.index], "name")])}"
117+
taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}"
118+
tags = ["${concat(list("gke-${var.name}"), list("gke-${var.name}-${lookup(var.node_pools[count.index], "name")}"), var.node_pools_tags["all"], var.node_pools_tags[lookup(var.node_pools[count.index], "name")])}"]
119+
120+
disk_size_gb = "${lookup(var.node_pools[count.index], "disk_size_gb", 100)}"
121+
disk_type = "${lookup(var.node_pools[count.index], "disk_type", "pd-standard")}"
122+
service_account = "${lookup(var.node_pools[count.index], "service_account", var.service_account)}"
123+
preemptible = "${lookup(var.node_pools[count.index], "preemptible", false)}"
124+
125+
oauth_scopes = [
126+
"https://www.googleapis.com/auth/cloud-platform",
127+
]
128+
}
129+
130+
lifecycle {
131+
ignore_changes = ["initial_node_count"]
132+
}
133+
134+
timeouts {
135+
create = "30m"
136+
update = "30m"
137+
delete = "30m"
138+
}
139+
140+
depends_on = ["google_container_cluster.primary"]
141+
}
142+
143+
resource "null_resource" "wait_for_regional_cluster" {
144+
count = "${var.regional ? 1 : 0}"
145+
146+
provisioner "local-exec" {
147+
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
148+
}
149+
150+
provisioner "local-exec" {
151+
when = "destroy"
152+
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}"
153+
}
154+
155+
depends_on = ["google_container_cluster.primary", "google_container_node_pool.pools"]
156+
}

0 commit comments

Comments
 (0)