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
start traffic
  • Loading branch information
f0ssel committed Dec 11, 2024
commit b2349d39a12d1835a7b68e3f4a1efb0e8db483c6
63 changes: 0 additions & 63 deletions scaletest/terraform/action/coder_proxies.tf

This file was deleted.

165 changes: 165 additions & 0 deletions scaletest/terraform/action/coderd.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
data "http" "coder_healthy" {
url = local.deployments.primary.url
// Wait up to 5 minutes for DNS to propagate
retry {
attempts = 30
min_delay_ms = 10000
}

lifecycle {
postcondition {
condition = self.status_code == 200
error_message = "${self.url} returned an unhealthy status code"
}
}

depends_on = [helm_release.coder_primary, cloudflare_record.coder["primary"]]
}

resource "null_resource" "api_key" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOF
curl '${local.deployments.primary.url}/api/v2/users/first' \
--data-raw $'{"email":"${local.coder_admin_email}","password":"${local.coder_admin_password}","username":"${local.coder_admin_user}","name":"${local.coder_admin_full_name}","trial":false}' \
--insecure --silent --output /dev/null

session_token=$(curl '${local.deployments.primary.url}/api/v2/users/login' \
--data-raw $'{"email":"${local.coder_admin_email}","password":"${local.coder_admin_password}"}' \
--insecure --silent | jq -r .session_token)

api_key=$(curl '${local.deployments.primary.url}/users/me/keys/tokens' \
-H "Coder-Session-Token: $${session_token}" \
--data-raw '{"token_name":"terraform","scope":"all"}' \
--insecure --silent | jq -r .key)

mkdir -p ${path.module}/.coderv2
echo -n $${api_key} > ${path.module}/.coderv2/api_key
EOF
}

depends_on = [data.http.coder_healthy]
}

data "local_file" "api_key" {
filename = "${path.module}/.coderv2/api_key"
depends_on = [null_resource.api_key]
}

resource "coderd_license" "license" {
license = var.coder_license
lifecycle {
create_before_destroy = true
}
}

resource "coderd_workspace_proxy" "europe" {
name = "europe"
display_name = "Europe"
icon = "/emojis/1f950.png"

depends_on = [coderd_license.license]
}

resource "coderd_workspace_proxy" "asia" {
name = "asia"
display_name = "Asia"
icon = "/emojis/1f35b.png"

depends_on = [coderd_license.license]
}

resource "local_file" "kubernetes_template" {
filename = "${path.module}/.coderv2/templates/kubernetes/main.tf"
content = <<EOF
terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~> 0.23.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.30"
}
}
}

provider "coder" {}

provider "kubernetes" {
config_path = null # always use host
}

data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}

resource "coder_agent" "main" {
os = "linux"
arch = "amd64"
}

resource "kubernetes_pod" "main" {
count = data.coder_workspace.me.start_count
metadata {
name = "coder-$${lower(data.coder_workspace_owner.me.name)}-$${lower(data.coder_workspace.me.name)}"
namespace = "${local.coder_namespace}"
labels = {
"app.kubernetes.io/name" = "coder-workspace"
"app.kubernetes.io/instance" = "coder-workspace-$${lower(data.coder_workspace_owner.me.name)}-$${lower(data.coder_workspace.me.name)}"
}
}
spec {
security_context {
run_as_user = "1000"
fs_group = "1000"
}
container {
name = "dev"
image = "${var.workspace_image}"
image_pull_policy = "Always"
command = ["sh", "-c", coder_agent.main.init_script]
security_context {
run_as_user = "1000"
}
env {
name = "CODER_AGENT_TOKEN"
value = coder_agent.main.token
}
resources {
requests = {
"cpu" = "${local.scenarios[var.scenario].workspace.cpu_request}"
"memory" = "${local.scenarios[var.scenario].workspace.mem_request}"
}
limits = {
"cpu" = "${local.scenarios[var.scenario].workspace.cpu_limit}"
"memory" = "${local.scenarios[var.scenario].workspace.mem_limit}"
}
}
}

affinity {
node_affinity {
required_during_scheduling_ignored_during_execution {
node_selector_term {
match_expressions {
key = "cloud.google.com/gke-nodepool"
operator = "In"
values = ["${google_container_node_pool.node_pool["primary_workspaces"].name}","${google_container_node_pool.node_pool["europe_workspaces"].name}","${google_container_node_pool.node_pool["asia_workspaces"].name}"]
}
}
}
}
}
}
}
EOF
}

resource "coderd_template" "kubernetes" {
name = "kubernetes"
versions = [{
directory = "${path.module}/.coderv2/templates/kubernetes"
active = true
}]
}
25 changes: 0 additions & 25 deletions scaletest/terraform/action/deployments.tf

This file was deleted.

23 changes: 23 additions & 0 deletions scaletest/terraform/action/gcp_clusters.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ data "google_compute_default_service_account" "default" {
}

locals {
deployments = {
primary = {
subdomain = "${var.name}-scaletest"
url = "http://${var.name}-scaletest.${var.cloudflare_domain}"
region = "us-east1"
zone = "us-east1-c"
cidr = "10.200.0.0/24"
}
europe = {
subdomain = "${var.name}-europe-scaletest"
url = "http://${var.name}-europe-scaletest.${var.cloudflare_domain}"
region = "europe-west1"
zone = "europe-west1-b"
cidr = "10.201.0.0/24"
}
asia = {
subdomain = "${var.name}-asia-scaletest"
url = "http://${var.name}-asia-scaletest.${var.cloudflare_domain}"
region = "asia-southeast1"
zone = "asia-southeast1-a"
cidr = "10.202.0.0/24"
}
}
node_pools = {
primary_coder = {
name = "coder"
Expand Down
2 changes: 1 addition & 1 deletion scaletest/terraform/action/k8s_coder_asia.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "kubernetes_secret" "proxy_token_asia" {
namespace = kubernetes_namespace.coder_asia.metadata.0.name
}
data = {
token = trimspace(data.local_file.asia_proxy_token.content)
token = coderd_workspace_proxy.asia.session_token
}
lifecycle {
ignore_changes = [timeouts, wait_for_service_account_token]
Expand Down
2 changes: 1 addition & 1 deletion scaletest/terraform/action/k8s_coder_europe.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "kubernetes_secret" "proxy_token_europe" {
namespace = kubernetes_namespace.coder_europe.metadata.0.name
}
data = {
token = trimspace(data.local_file.europe_proxy_token.content)
token = coderd_workspace_proxy.europe.session_token
}
lifecycle {
ignore_changes = [timeouts, wait_for_service_account_token]
Expand Down
5 changes: 5 additions & 0 deletions scaletest/terraform/action/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ terraform {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}

coderd = {
source = "coder/coderd"
version = "~> 0.0.8"
}
}

required_version = "~> 1.9.0"
Expand Down
21 changes: 21 additions & 0 deletions scaletest/terraform/action/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,24 @@ variable "provisionerd_image_tag" {
description = "Tag to use for Provisionerd image."
default = "latest"
}

// Traffic
variable "traffic_bytes_per_tick" {
description = "Number of bytes to send per tick."
default = 1024
}

variable "traffic_tick_interval" {
description = "Interval between ticks."
default = "1s"
}

variable "workspace_count" {
description = "Number of workspaces to create."
default = 10
}

variable "workspace_create_concurrency" {
description = "Number of workspaces to create concurrently."
default = 1
}
Loading