Skip to content

Commit 92d7c67

Browse files
authored
feat:add support for provisioning windows node pools
1 parent 6472909 commit 92d7c67

Some content is hidden

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

65 files changed

+2415
-34
lines changed

.kitchen.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,19 @@ suites:
201201
backend: gcp
202202
controls:
203203
- gcp
204+
- name: "simple_windows_node_pool"
205+
driver:
206+
root_module_directory: test/fixtures/simple_windows_node_pool
207+
verifier:
208+
systems:
209+
- name: gcloud
210+
backend: local
211+
controls:
212+
- gcloud
213+
- name: gcp
214+
backend: gcp
215+
controls:
216+
- gcp
204217
- name: "deploy_service"
205218
driver:
206219
root_module_directory: test/fixtures/deploy_service

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ Then perform the following commands on the root folder:
200200
| subnetwork | The subnetwork to host the cluster in (required) | `string` | n/a | yes |
201201
| timeouts | Timeout for cluster operations. | `map(string)` | `{}` | no |
202202
| upstream\_nameservers | If specified, the values replace the nameservers taken by default from the node’s /etc/resolv.conf | `list(string)` | `[]` | no |
203+
| windows\_node\_pools | List of maps containing Windows node pools | `list(map(string))` | `[]` | no |
203204
| zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | `list(string)` | `[]` | no |
204205

205206
## Outputs
@@ -232,6 +233,9 @@ Then perform the following commands on the root folder:
232233
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
233234

234235
## node_pools variable
236+
237+
> Use this variable for provisioning linux based node pools. For Windows based node pools use [windows_node_pools](#windows\_node\_pools-variable)
238+
235239
The node_pools variable takes the following parameters:
236240

237241
| Name | Description | Default | Requirement |
@@ -270,6 +274,11 @@ The node_pools variable takes the following parameters:
270274
| tags | The list of instance tags applied to all nodes | | Required |
271275
| value | The value for the taint | | Required |
272276
| version | The Kubernetes version for the nodes in this pool. Should only be set if auto_upgrade is false | " " | Optional |
277+
278+
## windows_node_pools variable
279+
The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created.
280+
281+
273282
## Requirements
274283

275284
Before this module can be used on a project, you must ensure that the following pre-requisites are fulfilled:

autogen/main/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ Then perform the following commands on the root folder:
174174

175175
{% if autopilot_cluster != true %}
176176
## node_pools variable
177+
178+
> Use this variable for provisioning linux based node pools. For Windows based node pools use [windows_node_pools](#windows\_node\_pools-variable)
179+
177180
The node_pools variable takes the following parameters:
178181

179182
| Name | Description | Default | Requirement |
@@ -228,7 +231,12 @@ The node_pools variable takes the following parameters:
228231
| tags | The list of instance tags applied to all nodes | | Required |
229232
| value | The value for the taint | | Required |
230233
| version | The Kubernetes version for the nodes in this pool. Should only be set if auto_upgrade is false | " " | Optional |
234+
235+
## windows_node_pools variable
236+
The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created.
237+
231238
{% endif %}
239+
232240
## Requirements
233241

234242
Before this module can be used on a project, you must ensure that the following pre-requisites are fulfilled:

autogen/main/cluster.tf.tmpl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ locals {
500500
# resources where "ForceNew" is "true". schemaNodeConfig can be found in node_config.go at
501501
# https://github.com/terraform-providers/terraform-provider-google/blob/master/google/node_config.go#L22
502502
resource "random_id" "name" {
503-
for_each = local.node_pools
503+
for_each = merge(local.node_pools, local.windows_node_pools)
504504
byte_length = 2
505505
prefix = format("%s-", lookup(each.value, "name"))
506506
keepers = merge(
@@ -569,13 +569,22 @@ resource "random_id" "name" {
569569

570570
{% endif %}
571571
{% if autopilot_cluster != true %}
572+
{% for i in range(2) %}
573+
{% if i == 0 %}
572574
resource "google_container_node_pool" "pools" {
575+
{% else %}
576+
resource "google_container_node_pool" "windows_pools" {
577+
{% endif %}
573578
{% if beta_cluster %}
574579
provider = google-beta
575580
{% else %}
576581
provider = google
577582
{% endif %}
583+
{% if i == 0 %}
578584
for_each = local.node_pools
585+
{% else %}
586+
for_each = local.windows_node_pools
587+
{% endif %}
579588
{% if update_variant %}
580589
name = { for k, v in random_id.name : k => v.hex }[each.key]
581590
{% else %}
@@ -756,6 +765,7 @@ resource "google_container_node_pool" "pools" {
756765
}
757766
}
758767

768+
{% if i == 0 %}
759769
dynamic "linux_node_config" {
760770
for_each = length(merge(
761771
local.node_pools_linux_node_configs_sysctls["all"],
@@ -770,6 +780,7 @@ resource "google_container_node_pool" "pools" {
770780
}
771781
}
772782
{% endif %}
783+
{% endif %}
773784

774785
shielded_instance_config {
775786
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
@@ -790,5 +801,10 @@ resource "google_container_node_pool" "pools" {
790801
update = lookup(var.timeouts, "update", "45m")
791802
delete = lookup(var.timeouts, "delete", "45m")
792803
}
804+
805+
{% if i == 1 %}
806+
depends_on = [google_container_node_pool.pools[0]]
807+
{% endif %}
793808
}
809+
{% endfor %}
794810
{% endif %}

autogen/main/main.tf.tmpl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ locals {
5252
// Build a map of maps of node pools from a list of objects
5353
node_pool_names = [for np in toset(var.node_pools) : np.name]
5454
node_pools = zipmap(local.node_pool_names, tolist(toset(var.node_pools)))
55+
windows_node_pool_names = [for np in toset(var.windows_node_pools) : np.name]
56+
windows_node_pools = zipmap(local.windows_node_pool_names, tolist(toset(var.windows_node_pools)))
5557
{% endif %}
5658

5759
release_channel = var.release_channel != null ? [{ channel : var.release_channel }] : []
@@ -164,8 +166,15 @@ locals {
164166
}]
165167

166168
{% if autopilot_cluster != true %}
167-
cluster_output_node_pools_names = concat([for np in google_container_node_pool.pools : np.name], [""])
168-
cluster_output_node_pools_versions = { for np in google_container_node_pool.pools : np.name => np.version }
169+
cluster_output_node_pools_names = concat(
170+
[for np in google_container_node_pool.pools : np.name], [""],
171+
[for np in google_container_node_pool.windows_pools : np.name], [""]
172+
)
173+
174+
cluster_output_node_pools_versions = merge(
175+
{ for np in google_container_node_pool.pools : np.name => np.version },
176+
{ for np in google_container_node_pool.windows_pools : np.name => np.version },
177+
)
169178
{% endif %}
170179

171180
cluster_master_auth_list_layer1 = local.cluster_output_master_auth

autogen/main/variables.tf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ variable "node_pools" {
148148
]
149149
}
150150

151+
variable "windows_node_pools" {
152+
type = list(map(string))
153+
description = "List of maps containing Windows node pools"
154+
default = []
155+
}
156+
151157
variable "node_pools_labels" {
152158
type = map(map(string))
153159
description = "Map of maps containing node labels by node-pool name"

autogen/main/variables_defaults.tf.tmpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ locals {
2828
[for node_pool in var.node_pools : node_pool["name"]],
2929
[for node_pool in var.node_pools : {}]
3030
),
31+
zipmap(
32+
[for node_pool in var.windows_node_pools : node_pool["name"]],
33+
[for node_pool in var.windows_node_pools : {}]
34+
),
3135
var.node_pools_labels
3236
)
3337

@@ -38,6 +42,10 @@ locals {
3842
[for node_pool in var.node_pools : node_pool["name"]],
3943
[for node_pool in var.node_pools : {}]
4044
),
45+
zipmap(
46+
[for node_pool in var.windows_node_pools : node_pool["name"]],
47+
[for node_pool in var.windows_node_pools : {}]
48+
),
4149
var.node_pools_metadata
4250
)
4351

@@ -48,6 +56,10 @@ locals {
4856
[for node_pool in var.node_pools : node_pool["name"]],
4957
[for node_pool in var.node_pools : []]
5058
),
59+
zipmap(
60+
[for node_pool in var.windows_node_pools : node_pool["name"]],
61+
[for node_pool in var.windows_node_pools : []]
62+
),
5163
var.node_pools_taints
5264
)
5365

@@ -58,6 +70,10 @@ locals {
5870
[for node_pool in var.node_pools : node_pool["name"]],
5971
[for node_pool in var.node_pools : []]
6072
),
73+
zipmap(
74+
[for node_pool in var.windows_node_pools : node_pool["name"]],
75+
[for node_pool in var.windows_node_pools : []]
76+
),
6177
var.node_pools_tags
6278
)
6379

@@ -68,6 +84,10 @@ locals {
6884
[for node_pool in var.node_pools : node_pool["name"]],
6985
[for node_pool in var.node_pools : []]
7086
),
87+
zipmap(
88+
[for node_pool in var.windows_node_pools : node_pool["name"]],
89+
[for node_pool in var.windows_node_pools : []]
90+
),
7191
var.node_pools_oauth_scopes
7292
)
7393
{% if beta_cluster %}

autogen/safer-cluster/main.tf.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ module "gke" {
8787
initial_node_count = (var.initial_node_count == 0) ? 1 : var.initial_node_count
8888

8989
node_pools = var.node_pools
90+
windows_node_pools = var.windows_node_pools
9091
node_pools_labels = var.node_pools_labels
9192
node_pools_metadata = var.node_pools_metadata
9293
node_pools_taints = var.node_pools_taints

autogen/safer-cluster/variables.tf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ variable "node_pools" {
152152
]
153153
}
154154

155+
variable "windows_node_pools" {
156+
type = list(map(string))
157+
description = "List of maps containing node pools"
158+
default = []
159+
}
160+
155161
variable "node_pools_labels" {
156162
type = map(map(string))
157163
description = "Map of maps containing node labels by node-pool name"

build/int.cloudbuild.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ steps:
236236
- verify beta-cluster-local
237237
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
238238
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy beta-cluster-local']
239+
- id: converge simple-windows-node-pool-local
240+
waitFor:
241+
- create all
242+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
243+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge simple-windows-node-pool-local']
244+
- id: verify simple-windows-node-pool-local
245+
waitFor:
246+
- converge simple-windows-node-pool-local
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 verify simple-windows-node-pool-local']
249+
- id: destroy simple-windows-node-pool-local
250+
waitFor:
251+
- verify simple-windows-node-pool-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 destroy simple-windows-node-pool-local']
239254
- id: converge deploy-service-local
240255
waitFor:
241256
- create all

0 commit comments

Comments
 (0)