Skip to content

feat: add new scaletest infrastructure #15573

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

Merged
merged 24 commits into from
Dec 12, 2024
Prev Previous commit
Next Next commit
baseline with iter
  • Loading branch information
f0ssel committed Nov 14, 2024
commit 5994591edaef6dcbada17f81ffde5ffccc271dfb
140 changes: 31 additions & 109 deletions scaletest/terraform/infra/gcp_cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@ data "google_compute_default_service_account" "default" {
}

locals {
abs_module_path = abspath(path.module)
rel_kubeconfig_path = "../../.coderv2/${var.name}-cluster.kubeconfig"
cluster_kubeconfig_path = abspath("${local.abs_module_path}/${local.rel_kubeconfig_path}")
node_pools = flatten([ for i, deployment in var.deployments : [
{
name = "${var.name}-${deployment.name}-coder"
zone = deployment.zone
size = deployment.coder_node_pool_size
cluster_i = i
},
{
name = "${var.name}-${deployment.name}-workspaces"
zone = deployment.zone
size = deployment.workspaces_node_pool_size
cluster_i = i
},
{
name = "${var.name}-${deployment.name}-misc"
zone = deployment.zone
size = deployment.misc_node_pool_size
cluster_i = i
}
] ])
}

resource "google_container_cluster" "primary" {
name = var.name
location = var.zone
resource "google_container_cluster" "cluster" {
count = length(var.deployments)
name = "${var.name}-${var.deployments[count.index].name}"
location = var.deployments[count.index].zone
project = var.project_id
network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.subnet.name
subnetwork = google_compute_subnetwork.subnet[count.index].name
networking_mode = "VPC_NATIVE"
default_max_pods_per_node = 256
ip_allocation_policy { # Required with networking_mode=VPC_NATIVE
Expand Down Expand Up @@ -53,14 +71,15 @@ resource "google_container_cluster" "primary" {
}
}

resource "google_container_node_pool" "coder" {
name = "${var.name}-coder"
location = var.zone
resource "google_container_node_pool" "node_pool" {
count = length(local.node_pools)
name = local.node_pools[count.index].name
location = local.node_pools[count.index].zone
project = var.project_id
cluster = google_container_cluster.primary.name
cluster = google_container_cluster.cluster[local.node_pools[count.index].cluster_i].name
autoscaling {
min_node_count = 1
max_node_count = var.nodepool_size_coder
max_node_count = local.node_pools[count.index].size
}
node_config {
oauth_scopes = [
Expand Down Expand Up @@ -88,100 +107,3 @@ resource "google_container_node_pool" "coder" {
ignore_changes = [management[0].auto_repair, management[0].auto_upgrade, timeouts]
}
}

resource "google_container_node_pool" "workspaces" {
name = "${var.name}-workspaces"
location = var.zone
project = var.project_id
cluster = google_container_cluster.primary.name
autoscaling {
min_node_count = 0
total_max_node_count = var.nodepool_size_workspaces
}
management {
auto_upgrade = false
}
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/trace.append",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
]
disk_size_gb = var.node_disk_size_gb
machine_type = var.nodepool_machine_type_workspaces
image_type = var.node_image_type
preemptible = var.node_preemptible
service_account = data.google_compute_default_service_account.default.email
tags = ["gke-node", "${var.project_id}-gke"]
labels = {
env = var.project_id
}
metadata = {
disable-legacy-endpoints = "true"
}
}
lifecycle {
ignore_changes = [management[0].auto_repair, management[0].auto_upgrade, timeouts]
}
}

resource "google_container_node_pool" "misc" {
name = "${var.name}-misc"
location = var.zone
project = var.project_id
cluster = google_container_cluster.primary.name
node_count = var.state == "stopped" ? 0 : var.nodepool_size_misc
management {
auto_upgrade = false
}
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/trace.append",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
]
disk_size_gb = var.node_disk_size_gb
machine_type = var.nodepool_machine_type_misc
image_type = var.node_image_type
preemptible = var.node_preemptible
service_account = data.google_compute_default_service_account.default.email
tags = ["gke-node", "${var.project_id}-gke"]
labels = {
env = var.project_id
}
metadata = {
disable-legacy-endpoints = "true"
}
}
lifecycle {
ignore_changes = [management[0].auto_repair, management[0].auto_upgrade, timeouts]
}
}

resource "null_resource" "cluster_kubeconfig" {
depends_on = [google_container_cluster.primary]
triggers = {
path = local.cluster_kubeconfig_path
name = google_container_cluster.primary.name
project_id = var.project_id
zone = var.zone
}
provisioner "local-exec" {
command = <<EOF
KUBECONFIG=${self.triggers.path} gcloud container clusters get-credentials ${self.triggers.name} --project=${self.triggers.project_id} --zone=${self.triggers.zone}
EOF
}

provisioner "local-exec" {
when = destroy
command = <<EOF
rm -f ${self.triggers.path}
EOF
}
}
17 changes: 9 additions & 8 deletions scaletest/terraform/infra/gcp_db.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_sql_database_instance" "db" {
name = var.name
region = var.region
name = "${var.name}-coder"
project = var.project_id
region = var.deployments[0].region
database_version = var.cloudsql_version
deletion_protection = false

Expand All @@ -12,7 +13,7 @@ resource "google_sql_database_instance" "db" {
availability_type = "ZONAL"

location_preference {
zone = var.zone
zone = var.deployments[0].zone
}

database_flags {
Expand Down Expand Up @@ -49,11 +50,11 @@ resource "google_sql_database" "coder" {
}
}

resource "random_password" "coder-postgres-password" {
resource "random_password" "coder_postgres_password" {
length = 12
}

resource "random_password" "prometheus-postgres-password" {
resource "random_password" "prometheus_postgres_password" {
length = 12
}

Expand All @@ -62,7 +63,7 @@ resource "google_sql_user" "coder" {
instance = google_sql_database_instance.db.id
name = "${var.name}-coder"
type = "BUILT_IN"
password = random_password.coder-postgres-password.result
password = random_password.coder_postgres_password.result
# required for postgres, otherwise user fails to delete
deletion_policy = "ABANDON"
lifecycle {
Expand All @@ -75,7 +76,7 @@ resource "google_sql_user" "prometheus" {
instance = google_sql_database_instance.db.id
name = "${var.name}-prometheus"
type = "BUILT_IN"
password = random_password.prometheus-postgres-password.result
password = random_password.prometheus_postgres_password.result
# required for postgres, otherwise user fails to delete
deletion_policy = "ABANDON"
lifecycle {
Expand All @@ -84,5 +85,5 @@ resource "google_sql_user" "prometheus" {
}

locals {
coder_db_url = "postgres://${google_sql_user.coder.name}:${urlencode(random_password.coder-postgres-password.result)}@${google_sql_database_instance.db.private_ip_address}/${google_sql_database.coder.name}?sslmode=disable"
coder_db_url = "postgres://${google_sql_user.coder.name}:${urlencode(random_password.coder_postgres_password.result)}@${google_sql_database_instance.db.private_ip_address}/${google_sql_database.coder.name}?sslmode=disable"
}
24 changes: 13 additions & 11 deletions scaletest/terraform/infra/gcp_vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ resource "google_compute_network" "vpc" {
}

resource "google_compute_subnetwork" "subnet" {
name = var.name
count = length(var.deployments)
name = "${var.name}-${var.deployments[count.index].name}"
project = var.project_id
region = var.region
region = var.deployments[count.index].region
network = google_compute_network.vpc.name
ip_cidr_range = var.subnet_cidr
ip_cidr_range = var.deployments[count.index].subnet_cidr
}

resource "google_compute_address" "coder" {
count = length(var.deployments)
project = var.project_id
region = var.deployments[count.index].region
name = "${var.name}-${var.deployments[count.index].name}-coder"
address_type = "EXTERNAL"
network_tier = "PREMIUM"
}

resource "google_compute_global_address" "sql_peering" {
Expand All @@ -24,14 +34,6 @@ resource "google_compute_global_address" "sql_peering" {
network = google_compute_network.vpc.id
}

resource "google_compute_address" "coder" {
project = var.project_id
region = var.region
name = "${var.name}-coder"
address_type = "EXTERNAL"
network_tier = "PREMIUM"
}

resource "google_service_networking_connection" "private_vpc_connection" {
network = google_compute_network.vpc.id
service = "servicenetworking.googleapis.com"
Expand Down
2 changes: 0 additions & 2 deletions scaletest/terraform/infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ terraform {
}

provider "google" {
region = var.region
project = var.project_id
}
Loading