-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Private Cluster Configuration #51
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
283c985
Migrate examples to google-beta provider
Jberlinsky 75648dc
Add support for private clusters
Jberlinsky a40e969
Add private cluster config block to private clusters
Jberlinsky 9e2593f
Backfill changes from non-private clusters
Jberlinsky e996de9
Backport changes to test fixtures into private cluster tests
Jberlinsky 13632b9
Backport horizontalPodAutoscaling test change to private cluster tests
Jberlinsky cc77bfb
Disable colored output on CI
Jberlinsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
/****************************************** | ||
Create regional cluster | ||
*****************************************/ | ||
resource "google_container_cluster" "primary_private" { | ||
provider = "google-beta" | ||
count = "${(local.cluster_deployment_type == "regional_private") ? 1 : 0}" | ||
name = "${var.name}" | ||
description = "${var.description}" | ||
project = "${var.project_id}" | ||
|
||
region = "${var.region}" | ||
additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"] | ||
|
||
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}" | ||
subnetwork = "${replace(data.google_compute_subnetwork.gke_subnetwork.self_link, "https://www.googleapis.com/compute/v1/", "")}" | ||
min_master_version = "${local.kubernetes_version}" | ||
|
||
logging_service = "${var.logging_service}" | ||
monitoring_service = "${var.monitoring_service}" | ||
|
||
master_authorized_networks_config = ["${var.master_authorized_networks_config}"] | ||
|
||
addons_config { | ||
http_load_balancing { | ||
disabled = "${var.http_load_balancing ? 0 : 1}" | ||
} | ||
|
||
horizontal_pod_autoscaling { | ||
disabled = "${var.horizontal_pod_autoscaling ? 0 : 1}" | ||
} | ||
|
||
kubernetes_dashboard { | ||
disabled = "${var.kubernetes_dashboard ? 0 : 1}" | ||
} | ||
|
||
network_policy_config { | ||
disabled = "${var.network_policy ? 0 : 1}" | ||
} | ||
} | ||
|
||
ip_allocation_policy { | ||
cluster_secondary_range_name = "${var.ip_range_pods}" | ||
services_secondary_range_name = "${var.ip_range_services}" | ||
} | ||
|
||
maintenance_policy { | ||
daily_maintenance_window { | ||
start_time = "${var.maintenance_start_time}" | ||
} | ||
} | ||
|
||
lifecycle { | ||
ignore_changes = ["node_pool"] | ||
} | ||
|
||
timeouts { | ||
create = "30m" | ||
update = "30m" | ||
delete = "30m" | ||
} | ||
|
||
node_pool { | ||
name = "default-pool" | ||
|
||
node_config { | ||
service_account = "${lookup(var.node_pools[0], "service_account", var.service_account)}" | ||
} | ||
} | ||
|
||
private_cluster_config { | ||
enable_private_endpoint = "${var.private_enable_private_endpoint}" | ||
enable_private_nodes = "${var.private_enable_private_nodes}" | ||
master_ipv4_cidr_block = "${var.private_master_ipv4_cidr_block}" | ||
} | ||
|
||
remove_default_node_pool = "${var.remove_default_node_pool}" | ||
} | ||
|
||
/****************************************** | ||
Create regional node pools | ||
*****************************************/ | ||
resource "google_container_node_pool" "pools_private" { | ||
provider = "google-beta" | ||
count = "${(local.cluster_deployment_type == "regional_private") ? length(var.node_pools) : 0}" | ||
name = "${lookup(var.node_pools[count.index], "name")}" | ||
project = "${var.project_id}" | ||
region = "${var.region}" | ||
cluster = "${var.name}" | ||
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version)}" | ||
initial_node_count = "${lookup(var.node_pools[count.index], "min_count", 1)}" | ||
|
||
autoscaling { | ||
min_node_count = "${lookup(var.node_pools[count.index], "min_count", 1)}" | ||
max_node_count = "${lookup(var.node_pools[count.index], "max_count", 100)}" | ||
} | ||
|
||
management { | ||
auto_repair = "${lookup(var.node_pools[count.index], "auto_repair", true)}" | ||
auto_upgrade = "${lookup(var.node_pools[count.index], "auto_upgrade", true)}" | ||
} | ||
|
||
node_config { | ||
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")])}" | ||
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")])}"] | ||
|
||
disk_size_gb = "${lookup(var.node_pools[count.index], "disk_size_gb", 100)}" | ||
disk_type = "${lookup(var.node_pools[count.index], "disk_type", "pd-standard")}" | ||
service_account = "${lookup(var.node_pools[count.index], "service_account", var.service_account)}" | ||
preemptible = "${lookup(var.node_pools[count.index], "preemptible", false)}" | ||
|
||
oauth_scopes = [ | ||
"https://www.googleapis.com/auth/cloud-platform", | ||
] | ||
} | ||
|
||
lifecycle { | ||
ignore_changes = ["initial_node_count"] | ||
} | ||
|
||
timeouts { | ||
create = "30m" | ||
update = "30m" | ||
delete = "30m" | ||
} | ||
|
||
depends_on = ["google_container_cluster.primary_private"] | ||
} | ||
|
||
resource "null_resource" "wait_for_private_regional_cluster" { | ||
count = "${(local.cluster_deployment_type == "regional_private") ? 1 : 0}" | ||
|
||
provisioner "local-exec" { | ||
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}" | ||
} | ||
|
||
provisioner "local-exec" { | ||
when = "destroy" | ||
command = "${path.module}/scripts/wait-for-cluster.sh ${var.project_id} ${var.name}" | ||
} | ||
|
||
depends_on = ["google_container_cluster.primary_private", "google_container_node_pool.pools_private"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for needing a separate cluster config for private clusters? Ideally we should minimize how many different
google_container_cluster
resources we have?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, a commit was missing from this. 719ee8b shows the actual configuration of the private cluster.
The issue here is that Terraform 0.11.x doesn't support conditionally adding this block. Hopefully Terraform 0.12 will make this less painful, but for now I'm not sure there's a better option than duplicating the resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, the
private_cluster_config
block itself doesn't force anything. If you set all its arguments to false, you would have a standard public cluster.it's the
enable_private_nodes
piece which is what is primarily meant by a private cluster usually.In terms of arguments, I'd actually like to add 3 new ones:
enable_private_endpoint
enable_private_nodes
master_ipv4_cidr_block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@morgante Unfortunately, the provider requires a
master_ipv4_cidr_block
to be provided as a valid CIDR whenever theprivate_cluster_config
block is specified, and overriding it from the default (unspecified) value can have hard-to-reason-about results. If we simply don't provide that attribute, things work, but we fall into the Terraform 0.11.x trap where an empty string is not considered the same as null, and we have no way to represent null when it should be so.I would suggest that we merge this as-is, understanding that there is additional complexity as a result of this, and file an upstream issue to make the validation on
master_ipv4_cidr_block
less stringent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should hold off as this is a change which will cause breakage later on if we walk it back and instead file an upstream provider issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's approach this by making a submodule as @aaron-lane suggested.