Skip to content

Commit a7122c3

Browse files
authored
Merge pull request #52 from terraform-google-modules/feature/czka-node-pool-metadata-key-value-pairs
Node pool metadata key value pairs
2 parents eeca20a + f146c9d commit a7122c3

File tree

9 files changed

+65
-0
lines changed

9 files changed

+65
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
Session.vim
2020
.netrwhist
2121

22+
# IntelliJ IDEA files:
23+
.idea/
24+
2225
### https://raw.github.com/github/gitignore/90f149de451a5433aebd94d02d11b0e28843a1af/Terraform.gitignore
2326

2427
# Local .terraform directories

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
99
### Changed
1010
* Set `horizontal_pod_autoscaling` to `true` by default. #42
1111
* Add `remove_default_node_pool` set to `false` by default #15
12+
* Allow arbitrary key-value pairs to be set on node pool metadata. #52
1213

1314
## [v0.4.0] - 2018-12-19
1415
### Added

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ module "gke" {
5252
}
5353
}
5454
55+
node_pools_metadata = {
56+
all = {}
57+
58+
default-node-pool = {
59+
node-pool-metadata-custom-value = "my-node-pool"
60+
}
61+
}
62+
5563
node_pools_taints = {
5664
all = []
5765
@@ -109,6 +117,7 @@ Then perform the following commands on the root folder:
109117
| remove_default_node_pool | Boolean value determining removal of default node pool | bool | false | no |
110118
| node_pools | List of maps containing node pools | list | `<list>` | no |
111119
| node_pools_labels | Map of maps containing node labels by node-pool name | map | `<map>` | no |
120+
| node_pools_metadata | Map of maps containing node metadata by node-pool name | map | `<map>` | no |
112121
| node_pools_tags | Map of lists containing node network tags by node-pool name | map | `<map>` | no |
113122
| node_pools_taints | Map of lists containing node taints by node-pool name | map | `<map>` | no |
114123
| node_version | The Kubernetes version of the node pools. Defaults kubernetes_version (master) variable and can be overridden for individual node pools by setting the `version` key on them. Must be empyty or set the same as master at cluster creation. | string | `` | no |

cluster_regional.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ resource "google_container_node_pool" "pools" {
111111
image_type = "${lookup(var.node_pools[count.index], "image_type", "COS")}"
112112
machine_type = "${lookup(var.node_pools[count.index], "machine_type", "n1-standard-2")}"
113113
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")])}"
114+
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")])}"
114115
taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}"
115116
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")])}"]
116117

cluster_zonal.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ resource "google_container_node_pool" "zonal_pools" {
111111
image_type = "${lookup(var.node_pools[count.index], "image_type", "COS")}"
112112
machine_type = "${lookup(var.node_pools[count.index], "machine_type", "n1-standard-2")}"
113113
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")])}"
114+
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")])}"
114115
taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}"
115116
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")])}"]
116117

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash -e
2+
3+
# Copyright 2018 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
kubectl --kubeconfig=/var/lib/kubelet/kubeconfig drain --force=true --ignore-daemonsets=true --delete-local-data "$HOSTNAME"

examples/node_pool/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ module "gke" {
5555
},
5656
]
5757

58+
node_pools_metadata = {
59+
all = {}
60+
61+
pool-01 = {
62+
shutdown-script = "${file("${path.module}/data/shutdown-script.sh")}"
63+
}
64+
65+
pool-02 = {}
66+
}
67+
5868
node_pools_labels = {
5969
all = {
6070
all-pools-example = "true"

test/integration/node_pool/controls/gcloud.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@
104104
)
105105
end
106106

107+
it "has the expected metadata" do
108+
expect(data['nodePools']).to include(
109+
including(
110+
"name" => "pool-01",
111+
"config" => including(
112+
"metadata" => including(
113+
"shutdown-script" => File.open("examples/node_pool/data/shutdown-script.sh").read,
114+
),
115+
),
116+
)
117+
)
118+
end
119+
107120
it "has the expected labels" do
108121
expect(data['nodePools']).to include(
109122
including(

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ variable "node_pools_labels" {
143143
}
144144
}
145145

146+
variable "node_pools_metadata" {
147+
type = "map"
148+
description = "Map of maps containing node metadata by node-pool name"
149+
150+
default = {
151+
all = {}
152+
default-node-pool = {}
153+
}
154+
}
155+
146156
variable "node_pools_taints" {
147157
type = "map"
148158
description = "Map of lists containing node taints by node-pool name"

0 commit comments

Comments
 (0)