Skip to content

Commit

Permalink
terraform, gcp: upgrade to google provider, cleanup use of google-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jul 10, 2024
1 parent ea9b707 commit 2f09cf8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 41 deletions.
77 changes: 49 additions & 28 deletions terraform/gcp/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ resource "google_project_iam_member" "cluster_sa_roles" {
member = "serviceAccount:${google_service_account.cluster_sa.email}"
}

# resource ref: https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/google_container_cluster
# resource ref: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_container_cluster
resource "google_container_cluster" "cluster" {
# Setting cluster autoscaling profile is in google-beta
provider = google-beta

name = "${var.prefix}-cluster"
location = var.regional_cluster ? var.region : var.zone
node_locations = var.regional_cluster ? [var.zone] : null
Expand Down Expand Up @@ -176,7 +173,7 @@ resource "google_container_cluster" "cluster" {
resource_labels = {}
}

# resource ref: https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/container_node_pool
# resource ref: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool
resource "google_container_node_pool" "core" {
name = "core-pool"
cluster = google_container_cluster.cluster.name
Expand Down Expand Up @@ -242,7 +239,7 @@ resource "google_container_node_pool" "core" {
}
}

# resource ref: https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/container_node_pool
# resource ref: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool
resource "google_container_node_pool" "notebook" {
for_each = var.notebook_nodes

Expand Down Expand Up @@ -315,20 +312,33 @@ resource "google_container_node_pool" "notebook" {
"k8s.dask.org/node-purpose" = "scheduler",
}, each.value.labels)

taint = concat([{
key = "hub.jupyter.org_dedicated"
value = "user"
effect = "NO_SCHEDULE"
}],
# Add extra taint explicitly if GPU is enabled, so non-GPU pods aren't scheduled here
# Terraform implicitly adds this taint anyway, and tries to recreate the nodepool if we re-apply
each.value.gpu.enabled ? [{
effect = "NO_SCHEDULE"
key = "nvidia.com/gpu"
value = "present"
}] : [],
each.value.taints
)
dynamic "taint" {
for_each = concat(
[
{
key = "hub.jupyter.org_dedicated"
value = "user"
effect = "NO_SCHEDULE"
}
],
# Add extra taint explicitly if GPU is enabled, so non-GPU pods aren't
# scheduled here Terraform implicitly adds this taint anyway, and tries
# to recreate the nodepool if we re-apply
each.value.gpu.enabled ? [{
effect = "NO_SCHEDULE"
key = "nvidia.com/gpu"
value = "present"
}] : [],
each.value.taints
)

content {
key = taint.value["key"]
value = taint.value["value"]
effect = taint.value["effect"]
}
}

machine_type = each.value.machine_type

# Our service account gets all OAuth scopes so it can access
Expand All @@ -349,7 +359,7 @@ resource "google_container_node_pool" "notebook" {
}
}

# resource ref: https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/container_node_pool
# resource ref: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool
resource "google_container_node_pool" "dask_worker" {
name = "dask-${each.key}"
cluster = google_container_cluster.cluster.name
Expand Down Expand Up @@ -400,13 +410,24 @@ resource "google_container_node_pool" "dask_worker" {
"k8s.dask.org/node-purpose" = "worker",
}, each.value.labels)

taint = concat([{
key = "k8s.dask.org_dedicated"
value = "worker"
effect = "NO_SCHEDULE"
}],
each.value.taints
)
dynamic "taint" {
for_each = concat(
[
{
key = "k8s.dask.org_dedicated"
value = "worker"
effect = "NO_SCHEDULE"
}
],
each.value.taints
)

content {
key = taint.value["key"]
value = taint.value["value"]
effect = taint.value["effect"]
}
}

machine_type = each.value.machine_type

Expand Down
12 changes: 1 addition & 11 deletions terraform/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,8 @@ terraform {
required_providers {
google = {
# ref: https://registry.terraform.io/providers/hashicorp/google/latest
#
# FIXME: v5 is out but we've not managed to migrate the config yet, we run
# into something about taints. See the upgrade guide at:
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/version_5_upgrade.
#
source = "google"
version = "~> 4.85"
}
google-beta = {
# ref: https://registry.terraform.io/providers/hashicorp/google-beta/latest
source = "google-beta"
version = "~> 4.85"
version = "~> 5.36"
}
kubernetes = {
# ref: https://registry.terraform.io/providers/hashicorp/kubernetes/latest
Expand Down
4 changes: 2 additions & 2 deletions terraform/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ variable "k8s_versions" {
description = <<-EOT
Configuration of the k8s cluster's version and node pools' versions. To specify these
- min_master_nodes is passthrough configuration of google_container_cluster's min_master_version, documented in https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/container_cluster#min_master_version
- [core|notebook|dask]_nodes_version is passthrough configuration of container_node_pool's version, documented in https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/container_node_pool#version
- min_master_nodes is passthrough configuration of google_container_cluster's min_master_version, documented in https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#min_master_version
- [core|notebook|dask]_nodes_version is passthrough configuration of container_node_pool's version, documented in https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool#version
EOT
}

Expand Down

0 comments on commit 2f09cf8

Please sign in to comment.