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

refactor: use gcloud module for scripts, closes #401 #404

Merged
merged 12 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ Then perform the following commands on the root folder:
| enable\_resource\_consumption\_export | Whether to enable resource consumption metering on this cluster. When enabled, a table will be created in the resource export BigQuery dataset to store resource consumption data. The resulting table can be joined with the resource usage table or with BigQuery billing export. | bool | `"true"` | no |
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers | list(string) | `<list>` | no |
| firewall\_priority | Priority rule for firewall rules | number | `"1000"` | no |
| gcloud\_skip\_download | Whether to skip downloading gcloud (assumes gcloud is already available outside the module) | bool | `"true"` | no |
| gcloud\_upgrade | Whether to upgrade gcloud at runtime | bool | `"false"` | no |
| grant\_registry\_access | Grants created cluster-specific service account storage.objectViewer role. | bool | `"false"` | no |
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | bool | `"true"` | no |
| http\_load\_balancing | Enable httpload balancer addon | bool | `"true"` | no |
Expand Down
38 changes: 17 additions & 21 deletions autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -529,25 +529,21 @@ resource "google_container_node_pool" "pools" {
}
}

resource "null_resource" "wait_for_cluster" {
count = var.skip_provisioners ? 0 : 1

triggers = {
project_id = var.project_id
name = var.name
}

provisioner "local-exec" {
command = "${path.module}/scripts/wait-for-cluster.sh ${self.triggers.project_id} ${self.triggers.name}"
}

provisioner "local-exec" {
when = destroy
command = "${path.module}/scripts/wait-for-cluster.sh ${self.triggers.project_id} ${self.triggers.name}"
}

depends_on = [
google_container_cluster.primary,
google_container_node_pool.pools,
]
module "gcloud_wait_for_cluster" {
source = "terraform-google-modules/gcloud/google"
version = "~> 1.0.1"
enabled = var.skip_provisioners

upgrade = var.gcloud_upgrade
skip_download = var.gcloud_skip_download

create_cmd_entrypoint = "${path.module}/scripts/wait-for-cluster.sh"
create_cmd_body = "${var.project_id} ${var.name}"
destroy_cmd_entrypoint = "${path.module}/scripts/wait-for-cluster.sh"
destroy_cmd_body = "${var.project_id} ${var.name}"

module_depends_on = concat(
[google_container_cluster.primary.master_version],
[for pool in google_container_node_pool.pools : pool.name]
)
}
35 changes: 20 additions & 15 deletions autogen/main/dns.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@
/******************************************
Delete default kube-dns configmap
*****************************************/
resource "null_resource" "delete_default_kube_dns_configmap" {
count = (local.custom_kube_dns_config || local.upstream_nameservers_config) && ! var.skip_provisioners ? 1 : 0

provisioner "local-exec" {
command = "${path.module}/scripts/kubectl_wrapper.sh https://${local.cluster_endpoint} ${data.google_client_config.default.access_token} ${local.cluster_ca_certificate} ${path.module}/scripts/delete-default-resource.sh kube-system configmap kube-dns"
}

depends_on = [
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
]
module "gcloud_delete_default_kube_dns_configmap" {
source = "terraform-google-modules/gcloud/google"
version = "~> 1.0.1"
enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && ! var.skip_provisioners
additional_components = ["kubectl"]
marshallford marked this conversation as resolved.
Show resolved Hide resolved

upgrade = var.gcloud_upgrade
skip_download = var.gcloud_skip_download

create_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh"
create_cmd_body = "https://${local.cluster_endpoint} ${data.google_client_config.default.access_token} ${local.cluster_ca_certificate} ${path.module}/scripts/delete-default-resource.sh kube-system configmap kube-dns"

module_depends_on = concat(
[data.google_client_config.default.access_token],
[google_container_cluster.primary.master_version],
[for pool in google_container_node_pool.pools : pool.name]
)
}

/******************************************
Expand All @@ -55,7 +60,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand All @@ -82,7 +87,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand Down Expand Up @@ -112,7 +117,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand Down
2 changes: 1 addition & 1 deletion autogen/main/scripts/delete-default-resource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RESOURCE_LIST=$(kubectl -n "${RESOURCE_NAMESPACE}" get "${RESOURCE_TYPE}" || exi

# Delete requested resource
if [[ $RESOURCE_LIST = *"${RESOURCE_NAME}"* ]]; then
RESOURCE_MAINTAINED_LABEL=$(kubectl -n "${RESOURCE_NAMESPACE}" get "${RESOURCE_TYPE}" -o json "${RESOURCE_NAME}" | jq -r '.metadata.labels."maintained_by"')
RESOURCE_MAINTAINED_LABEL=$(kubectl -n "${RESOURCE_NAMESPACE}" get "${RESOURCE_TYPE}" "${RESOURCE_NAME}" -o=jsonpath='{.metadata.labels.maintained_by}')
if [[ $RESOURCE_MAINTAINED_LABEL = "terraform" ]]; then
echo "Terraform maintained ${RESOURCE_NAME} ${RESOURCE_TYPE} appears to have already been created in ${RESOURCE_NAMESPACE} namespace"
else
Expand Down
11 changes: 4 additions & 7 deletions autogen/main/scripts/wait-for-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ CLUSTER_NAME=$2

echo "Waiting for cluster $CLUSTER_NAME in project $PROJECT to reconcile..."

current_status=$(gcloud container clusters list --project="$PROJECT" --filter=name:"$CLUSTER_NAME" --format="value(status)")

while [[ "$current_status" == "RECONCILING" ]]; do
printf "."
sleep 5
current_status=$(gcloud container clusters list --project="$PROJECT" --filter=name:"$CLUSTER_NAME" --format="value(status)")
done
while
current_status=$(gcloud container clusters list --project="$PROJECT" --filter=name:"$CLUSTER_NAME" --format="value(status)")
[[ "${current_status}" == "RECONCILING" ]]
do printf ".";sleep 5; done

echo "Cluster is ready!"
12 changes: 12 additions & 0 deletions autogen/main/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,15 @@ variable "firewall_inbound_ports" {
description = "List of TCP ports for admission/webhook controllers"
default = ["8443", "9443", "15017"]
}

variable "gcloud_upgrade" {
type = bool
description = "Whether to upgrade gcloud at runtime"
default = false
}

variable "gcloud_skip_download" {
type = bool
description = "Whether to skip downloading gcloud (assumes gcloud is already available outside the module)"
default = true
}
38 changes: 17 additions & 21 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,21 @@ resource "google_container_node_pool" "pools" {
}
}

resource "null_resource" "wait_for_cluster" {
count = var.skip_provisioners ? 0 : 1

triggers = {
project_id = var.project_id
name = var.name
}

provisioner "local-exec" {
command = "${path.module}/scripts/wait-for-cluster.sh ${self.triggers.project_id} ${self.triggers.name}"
}

provisioner "local-exec" {
when = destroy
command = "${path.module}/scripts/wait-for-cluster.sh ${self.triggers.project_id} ${self.triggers.name}"
}

depends_on = [
google_container_cluster.primary,
google_container_node_pool.pools,
]
module "gcloud_wait_for_cluster" {
source = "terraform-google-modules/gcloud/google"
version = "~> 1.0.1"
enabled = var.skip_provisioners

upgrade = var.gcloud_upgrade
skip_download = var.gcloud_skip_download

create_cmd_entrypoint = "${path.module}/scripts/wait-for-cluster.sh"
create_cmd_body = "${var.project_id} ${var.name}"
destroy_cmd_entrypoint = "${path.module}/scripts/wait-for-cluster.sh"
destroy_cmd_body = "${var.project_id} ${var.name}"

module_depends_on = concat(
[google_container_cluster.primary.master_version],
[for pool in google_container_node_pool.pools : pool.name]
)
}
35 changes: 20 additions & 15 deletions dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@
/******************************************
Delete default kube-dns configmap
*****************************************/
resource "null_resource" "delete_default_kube_dns_configmap" {
count = (local.custom_kube_dns_config || local.upstream_nameservers_config) && ! var.skip_provisioners ? 1 : 0

provisioner "local-exec" {
command = "${path.module}/scripts/kubectl_wrapper.sh https://${local.cluster_endpoint} ${data.google_client_config.default.access_token} ${local.cluster_ca_certificate} ${path.module}/scripts/delete-default-resource.sh kube-system configmap kube-dns"
}

depends_on = [
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
]
module "gcloud_delete_default_kube_dns_configmap" {
source = "terraform-google-modules/gcloud/google"
version = "~> 1.0.1"
enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && ! var.skip_provisioners
additional_components = ["kubectl"]

upgrade = var.gcloud_upgrade
skip_download = var.gcloud_skip_download

create_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh"
create_cmd_body = "https://${local.cluster_endpoint} ${data.google_client_config.default.access_token} ${local.cluster_ca_certificate} ${path.module}/scripts/delete-default-resource.sh kube-system configmap kube-dns"

module_depends_on = concat(
[data.google_client_config.default.access_token],
[google_container_cluster.primary.master_version],
[for pool in google_container_node_pool.pools : pool.name]
)
}

/******************************************
Expand All @@ -55,7 +60,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand All @@ -82,7 +87,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand Down Expand Up @@ -112,7 +117,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand Down
2 changes: 2 additions & 0 deletions modules/beta-private-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ Then perform the following commands on the root folder:
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers | list(string) | `<list>` | no |
| firewall\_priority | Priority rule for firewall rules | number | `"1000"` | no |
| gce\_pd\_csi\_driver | (Beta) Whether this cluster should enable the Google Compute Engine Persistent Disk Container Storage Interface (CSI) Driver. | bool | `"false"` | no |
| gcloud\_skip\_download | Whether to skip downloading gcloud (assumes gcloud is already available outside the module) | bool | `"true"` | no |
| gcloud\_upgrade | Whether to upgrade gcloud at runtime | bool | `"false"` | no |
| grant\_registry\_access | Grants created cluster-specific service account storage.objectViewer role. | bool | `"false"` | no |
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | bool | `"true"` | no |
| http\_load\_balancing | Enable httpload balancer addon | bool | `"true"` | no |
Expand Down
38 changes: 17 additions & 21 deletions modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -481,25 +481,21 @@ resource "google_container_node_pool" "pools" {
}
}

resource "null_resource" "wait_for_cluster" {
count = var.skip_provisioners ? 0 : 1

triggers = {
project_id = var.project_id
name = var.name
}

provisioner "local-exec" {
command = "${path.module}/scripts/wait-for-cluster.sh ${self.triggers.project_id} ${self.triggers.name}"
}

provisioner "local-exec" {
when = destroy
command = "${path.module}/scripts/wait-for-cluster.sh ${self.triggers.project_id} ${self.triggers.name}"
}

depends_on = [
google_container_cluster.primary,
google_container_node_pool.pools,
]
module "gcloud_wait_for_cluster" {
source = "terraform-google-modules/gcloud/google"
version = "~> 1.0.1"
enabled = var.skip_provisioners

upgrade = var.gcloud_upgrade
skip_download = var.gcloud_skip_download

create_cmd_entrypoint = "${path.module}/scripts/wait-for-cluster.sh"
create_cmd_body = "${var.project_id} ${var.name}"
destroy_cmd_entrypoint = "${path.module}/scripts/wait-for-cluster.sh"
destroy_cmd_body = "${var.project_id} ${var.name}"

module_depends_on = concat(
[google_container_cluster.primary.master_version],
[for pool in google_container_node_pool.pools : pool.name]
)
}
35 changes: 20 additions & 15 deletions modules/beta-private-cluster-update-variant/dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@
/******************************************
Delete default kube-dns configmap
*****************************************/
resource "null_resource" "delete_default_kube_dns_configmap" {
count = (local.custom_kube_dns_config || local.upstream_nameservers_config) && ! var.skip_provisioners ? 1 : 0

provisioner "local-exec" {
command = "${path.module}/scripts/kubectl_wrapper.sh https://${local.cluster_endpoint} ${data.google_client_config.default.access_token} ${local.cluster_ca_certificate} ${path.module}/scripts/delete-default-resource.sh kube-system configmap kube-dns"
}

depends_on = [
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
]
module "gcloud_delete_default_kube_dns_configmap" {
source = "terraform-google-modules/gcloud/google"
version = "~> 1.0.1"
enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && ! var.skip_provisioners
additional_components = ["kubectl"]

upgrade = var.gcloud_upgrade
skip_download = var.gcloud_skip_download

create_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh"
create_cmd_body = "https://${local.cluster_endpoint} ${data.google_client_config.default.access_token} ${local.cluster_ca_certificate} ${path.module}/scripts/delete-default-resource.sh kube-system configmap kube-dns"

module_depends_on = concat(
[data.google_client_config.default.access_token],
[google_container_cluster.primary.master_version],
[for pool in google_container_node_pool.pools : pool.name]
)
}

/******************************************
Expand All @@ -55,7 +60,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand All @@ -82,7 +87,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand Down Expand Up @@ -112,7 +117,7 @@ EOF
}

depends_on = [
null_resource.delete_default_kube_dns_configmap,
module.gcloud_delete_default_kube_dns_configmap.wait,
data.google_client_config.default,
google_container_cluster.primary,
google_container_node_pool.pools,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RESOURCE_LIST=$(kubectl -n "${RESOURCE_NAMESPACE}" get "${RESOURCE_TYPE}" || exi

# Delete requested resource
if [[ $RESOURCE_LIST = *"${RESOURCE_NAME}"* ]]; then
RESOURCE_MAINTAINED_LABEL=$(kubectl -n "${RESOURCE_NAMESPACE}" get "${RESOURCE_TYPE}" -o json "${RESOURCE_NAME}" | jq -r '.metadata.labels."maintained_by"')
RESOURCE_MAINTAINED_LABEL=$(kubectl -n "${RESOURCE_NAMESPACE}" get "${RESOURCE_TYPE}" "${RESOURCE_NAME}" -o=jsonpath='{.metadata.labels.maintained_by}')
if [[ $RESOURCE_MAINTAINED_LABEL = "terraform" ]]; then
echo "Terraform maintained ${RESOURCE_NAME} ${RESOURCE_TYPE} appears to have already been created in ${RESOURCE_NAMESPACE} namespace"
else
Expand Down
Loading