Skip to content

Commit

Permalink
Merge pull request terraform-google-modules#52 from terraform-google-…
Browse files Browse the repository at this point in the history
…modules/feature/czka-node-pool-metadata-key-value-pairs

Node pool metadata key value pairs
  • Loading branch information
morgante committed Jan 8, 2019
2 parents 2b8f4ad + 5892d35 commit 3b6af0e
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
Session.vim
.netrwhist

# IntelliJ IDEA files:
.idea/

### https://raw.github.com/github/gitignore/90f149de451a5433aebd94d02d11b0e28843a1af/Terraform.gitignore

# Local .terraform directories
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 | `<list>` | no |
| node_pools_labels | Map of maps containing node labels by node-pool name | map | `<map>` | no |
| node_pools_metadata | Map of maps containing node metadata by node-pool name | map | `<map>` | no |
| node_pools_tags | Map of lists containing node network tags by node-pool name | map | `<map>` | no |
| node_pools_taints | Map of lists containing node taints by node-pool name | map | `<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 |
Expand Down
1 change: 1 addition & 0 deletions cluster_regional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")])}"]

Expand Down
1 change: 1 addition & 0 deletions cluster_zonal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")])}"]

Expand Down
17 changes: 17 additions & 0 deletions examples/node_pool/data/shutdown-script.sh
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions test/integration/node_pool/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3b6af0e

Please sign in to comment.