diff --git a/.gitignore b/.gitignore index c1eaf75695..7fab33f949 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,9 @@ Session.vim .netrwhist +# IntelliJ IDEA files: +.idea/ + ### https://raw.github.com/github/gitignore/90f149de451a5433aebd94d02d11b0e28843a1af/Terraform.gitignore # Local .terraform directories diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f51ba12fb..460a863df9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed * Set `horizontal_pod_autoscaling` to `true` by default. #42 * Add `remove_default_node_pool` set to `false` by default #15 +* Allow arbitrary key-value pairs to be set on node pool metadata. #52 ## [v0.4.0] - 2018-12-19 ### Added diff --git a/README.md b/README.md index affa9f9184..ec686e4464 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,14 @@ module "gke" { } } + node_pools_metadata = { + all = {} + + default-node-pool = { + node-pool-metadata-custom-value = "my-node-pool" + } + } + node_pools_taints = { all = [] @@ -109,6 +117,7 @@ Then perform the following commands on the root folder: | remove_default_node_pool | Boolean value determining removal of default node pool | bool | false | no | | node_pools | List of maps containing node pools | list | `` | no | | node_pools_labels | Map of maps containing node labels by node-pool name | map | `` | no | +| node_pools_metadata | Map of maps containing node metadata by node-pool name | map | `` | no | | node_pools_tags | Map of lists containing node network tags by node-pool name | map | `` | no | | node_pools_taints | Map of lists containing node taints by node-pool name | map | `` | no | | 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 | diff --git a/cluster_regional.tf b/cluster_regional.tf index 1774b38bd6..057afc44dc 100644 --- a/cluster_regional.tf +++ b/cluster_regional.tf @@ -111,6 +111,7 @@ resource "google_container_node_pool" "pools" { image_type = "${lookup(var.node_pools[count.index], "image_type", "COS")}" machine_type = "${lookup(var.node_pools[count.index], "machine_type", "n1-standard-2")}" 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")])}" + 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")])}" taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}" 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")])}"] diff --git a/cluster_zonal.tf b/cluster_zonal.tf index 209712a985..fb4be3ff85 100644 --- a/cluster_zonal.tf +++ b/cluster_zonal.tf @@ -111,6 +111,7 @@ resource "google_container_node_pool" "zonal_pools" { image_type = "${lookup(var.node_pools[count.index], "image_type", "COS")}" machine_type = "${lookup(var.node_pools[count.index], "machine_type", "n1-standard-2")}" 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")])}" + 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")])}" taint = "${concat(var.node_pools_taints["all"], var.node_pools_taints[lookup(var.node_pools[count.index], "name")])}" 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")])}"] diff --git a/examples/node_pool/data/shutdown-script.sh b/examples/node_pool/data/shutdown-script.sh new file mode 100644 index 0000000000..f1ff19c353 --- /dev/null +++ b/examples/node_pool/data/shutdown-script.sh @@ -0,0 +1,17 @@ +#!/bin/bash -e + +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +kubectl --kubeconfig=/var/lib/kubelet/kubeconfig drain --force=true --ignore-daemonsets=true --delete-local-data "$HOSTNAME" diff --git a/examples/node_pool/main.tf b/examples/node_pool/main.tf index b6a970205e..df399e4256 100644 --- a/examples/node_pool/main.tf +++ b/examples/node_pool/main.tf @@ -55,6 +55,16 @@ module "gke" { }, ] + node_pools_metadata = { + all = {} + + pool-01 = { + shutdown-script = "${file("${path.module}/data/shutdown-script.sh")}" + } + + pool-02 = {} + } + node_pools_labels = { all = { all-pools-example = "true" diff --git a/test/integration/node_pool/controls/gcloud.rb b/test/integration/node_pool/controls/gcloud.rb index a38d59e29a..578c5d98ab 100644 --- a/test/integration/node_pool/controls/gcloud.rb +++ b/test/integration/node_pool/controls/gcloud.rb @@ -104,6 +104,19 @@ ) end + it "has the expected metadata" do + expect(data['nodePools']).to include( + including( + "name" => "pool-01", + "config" => including( + "metadata" => including( + "shutdown-script" => File.open("examples/node_pool/data/shutdown-script.sh").read, + ), + ), + ) + ) + end + it "has the expected labels" do expect(data['nodePools']).to include( including( diff --git a/variables.tf b/variables.tf index 143bb5dceb..1c9c30caea 100644 --- a/variables.tf +++ b/variables.tf @@ -143,6 +143,16 @@ variable "node_pools_labels" { } } +variable "node_pools_metadata" { + type = "map" + description = "Map of maps containing node metadata by node-pool name" + + default = { + all = {} + default-node-pool = {} + } +} + variable "node_pools_taints" { type = "map" description = "Map of lists containing node taints by node-pool name"