Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a node pool to be created before it is destroyed #256

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
90fc509
Allow a node pool to be created before it is destroyed
Sep 4, 2019
0832ba0
simplify count for random_id.name since random_id is a safe op
Sep 5, 2019
ecfb001
Track all resources in keepers which are specified by ForceNew in nod…
Sep 5, 2019
5ea28b5
templatize lifecycle block since interpolations are not allowed
Sep 6, 2019
9b28164
Merge branch 'master' into create-before-destroy-nodepools
Sep 6, 2019
3879942
rename terraform resource names to more appropriate and descriptive …
Sep 6, 2019
445f1e3
enable random_id names when create_before_destroy is desired
Sep 7, 2019
3a9533f
if a metadata_all tag is moved to a specific node pool, it should not…
Sep 9, 2019
1f95dfb
Create new templated submodule for create_before_destroy lifecycle va…
Sep 9, 2019
4890bc2
add breadcrumb back to schemaNodeConfig for keepers list
Sep 9, 2019
d537448
s/lifecycle-variant/update-variant/
Sep 10, 2019
7208e4e
Merge remote-tracking branch 'upstream/master' into create-before-des…
Sep 10, 2019
f5ce4e4
lookup names in a hash table similar to master
Sep 10, 2019
1854e04
sort keeper values so that re-ordering has not effect
Sep 11, 2019
99a179d
Add two examples for the update_variant and test of a private zonal c…
Sep 11, 2019
2e0f788
Merge branch 'master' into create-before-destroy-nodepools
asproul Sep 12, 2019
86ad23c
generate docs after a master merge
Sep 16, 2019
82e668a
Merge branch 'master' into create-before-destroy-nodepools
Sep 27, 2019
07ccb6f
Merge branch 'master' into create-before-destroy-nodepools
Oct 3, 2019
1109742
Merge branch 'master' into create-before-destroy-nodepools
Oct 11, 2019
e80b9c2
Staying up to date to ensure lint tests pass locally
Oct 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion autogen/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,75 @@ resource "google_container_cluster" "primary" {
/******************************************
Create Container Cluster node pools
*****************************************/
{% if lifecycle_variant %}
locals {
force_node_pool_recreation_resources = [
"disk_size_gb",
"disk_type",
"accelerator_count",
"accelerator_type",
"local_ssd_count",
"machine_type",
"preemptible",
"service_account",
]
}

# This keepers list is based on the terraform google provider schemaNodeConfig
# resources where "ForceNew" is "true"
asproul marked this conversation as resolved.
Show resolved Hide resolved
resource "random_id" "name" {
count = length(var.node_pools)
byte_length = 2
prefix = format("%s-", lookup(var.node_pools[count.index], "name"))
keepers = merge(
zipmap(
local.force_node_pool_recreation_resources,
[for keeper in local.force_node_pool_recreation_resources : lookup(var.node_pools[count.index], keeper, "")]
),
{
labels = join(",",
asproul marked this conversation as resolved.
Show resolved Hide resolved
keys(var.node_pools_labels["all"]),
keys(var.node_pools_labels[var.node_pools[count.index]["name"]]),
values(var.node_pools_labels["all"]),
values(var.node_pools_labels[var.node_pools[count.index]["name"]])
)
},
{
metadata = join(",",
keys(var.node_pools_metadata["all"]),
keys(var.node_pools_metadata[var.node_pools[count.index]["name"]]),
values(var.node_pools_metadata["all"]),
values(var.node_pools_metadata[var.node_pools[count.index]["name"]])
)
},
{
oauth_scopes = join(",",
var.node_pools_oauth_scopes["all"],
var.node_pools_oauth_scopes[var.node_pools[count.index]["name"]]
)
},
{
tags = join(",",
var.node_pools_tags["all"],
var.node_pools_tags[var.node_pools[count.index]["name"]]
)
}
)
}

{% endif %}
resource "google_container_node_pool" "pools" {
{% if beta_cluster %}
provider = google-beta
{% else %}
provider = google
{% endif %}
count = length(var.node_pools)
name = var.node_pools[count.index]["name"]
{% if lifecycle_variant %}
name = random_id.name.*.hex[count.index]
{% else %}
name = lookup(var.node_pools[count.index], "name")
{% endif %}
project = var.project_id
location = local.location
cluster = google_container_cluster.primary.name
Expand Down Expand Up @@ -342,6 +403,9 @@ resource "google_container_node_pool" "pools" {

lifecycle {
ignore_changes = [initial_node_count]
{% if lifecycle_variant %}
create_before_destroy = true
{% endif %}
}

timeouts {
Expand Down
2 changes: 1 addition & 1 deletion cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ resource "google_container_cluster" "primary" {
resource "google_container_node_pool" "pools" {
provider = google
count = length(var.node_pools)
name = var.node_pools[count.index]["name"]
name = lookup(var.node_pools[count.index], "name")
project = var.project_id
location = local.location
cluster = google_container_cluster.primary.name
Expand Down
5 changes: 5 additions & 0 deletions helpers/generate_modules/generate_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def template_options(self, base):
'private_cluster': True,
'beta_cluster': True,
}),
Module("./modules/private-cluster-lifecycle-variant", {
'module_path': '//modules/private-cluster-lifecycle-variant',
'private_cluster': True,
'lifecycle_variant': True,
}),
Module("./modules/beta-public-cluster", {
'module_path': '//modules/beta-public-cluster',
'private_cluster': False,
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ resource "google_container_cluster" "primary" {
resource "google_container_node_pool" "pools" {
provider = google-beta
count = length(var.node_pools)
name = var.node_pools[count.index]["name"]
name = lookup(var.node_pools[count.index], "name")
project = var.project_id
location = local.location
cluster = google_container_cluster.primary.name
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ resource "google_container_cluster" "primary" {
resource "google_container_node_pool" "pools" {
provider = google-beta
count = length(var.node_pools)
name = var.node_pools[count.index]["name"]
name = lookup(var.node_pools[count.index], "name")
project = var.project_id
location = local.location
cluster = google_container_cluster.primary.name
Expand Down
400 changes: 400 additions & 0 deletions modules/private-cluster-lifecycle-variant/README.md

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions modules/private-cluster-lifecycle-variant/auth.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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.
*/

// This file was automatically generated from a template in ./autogen

/******************************************
Retrieve authentication token
*****************************************/
data "google_client_config" "default" {
provider = google
}

/******************************************
Configure provider
*****************************************/
provider "kubernetes" {
load_config_file = false
host = "https://${local.cluster_endpoint}"
token = data.google_client_config.default.access_token
cluster_ca_certificate = base64decode(local.cluster_ca_certificate)
}
Loading