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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
back to curl
  • Loading branch information
f0ssel committed Dec 11, 2024
commit acc56b03e70c43c7df26b8e2267561de58e1001e
91 changes: 91 additions & 0 deletions scaletest/terraform/action/coder_proxies.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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 "null_resource" "license" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOF
curl '${local.deployments.primary.url}/api/v2/licenses' \
-H "Coder-Session-Token: ${trimspace(data.local_file.api_key.content)}" \
--data-raw '{"license":"${var.coder_license}"}' \
--insecure --silent --output /dev/null
EOF
}
}

resource "null_resource" "proxy_tokens" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOF
europe_token=$(curl '${local.deployments.primary.url}/api/v2/workspaceproxies' \
-H "Coder-Session-Token: ${trimspace(data.local_file.api_key.content)}" \
--data-raw '{"name":"europe","display_name":"Europe","icon":"/emojis/1f950.png"}' \
--insecure --silent | jq -r .proxy_token)

asia_token=$(curl '${local.deployments.primary.url}/api/v2/workspaceproxies' \
-H "Coder-Session-Token: ${trimspace(data.local_file.api_key.content)}" \
--data-raw '{"name":"asia","display_name":"Asia","icon":"/emojis/1f35b.png"}' \
--insecure --silent | jq -r .proxy_token)

echo -n $${europe_token} > ${path.module}/.coderv2/europe_proxy_token
echo -n $${asia_token} > ${path.module}/.coderv2/asia_proxy_token
EOF
}

depends_on = [data.http.coder_healthy]
}

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

data "local_file" "asia_proxy_token" {
filename = "${path.module}/.coderv2/asia_proxy_token"
depends_on = [null_resource.proxy_tokens]
}
Original file line number Diff line number Diff line change
@@ -1,74 +1,3 @@
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
Expand Down Expand Up @@ -128,12 +57,12 @@ resource "local_file" "kubernetes_template" {
}
resources {
requests = {
"cpu" = "${local.scenarios[var.scenario].workspace.cpu_request}"
"memory" = "${local.scenarios[var.scenario].workspace.mem_request}"
"cpu" = "${local.scenarios[var.scenario].workspaces.cpu_request}"
"memory" = "${local.scenarios[var.scenario].workspaces.mem_request}"
}
limits = {
"cpu" = "${local.scenarios[var.scenario].workspace.cpu_limit}"
"memory" = "${local.scenarios[var.scenario].workspace.mem_limit}"
"cpu" = "${local.scenarios[var.scenario].workspaces.cpu_limit}"
"memory" = "${local.scenarios[var.scenario].workspaces.mem_limit}"
}
}
}
Expand All @@ -156,10 +85,72 @@ resource "local_file" "kubernetes_template" {
EOF
}

resource "coderd_template" "kubernetes" {
name = "kubernetes"
versions = [{
directory = "${path.module}/.coderv2/templates/kubernetes"
active = true
}]
resource "kubernetes_config_map" "template" {
provider = kubernetes.primary

metadata {
name = "coder-template"
namespace = kubernetes_namespace.coder_primary.metadata.0.name
}

data = {
"main.tf" = local_file.kubernetes_template.content
}
}

resource "kubernetes_pod" "push_template" {
provider = kubernetes.primary

metadata {
name = "${var.name}-push-template"
namespace = kubernetes_namespace.coder_primary.metadata.0.name
labels = {
"app.kubernetes.io/name" = "${var.name}-push-template"
}
}
spec {
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_misc"].name}"]
}
}
}
}
}
container {
name = "cli"
image = "${var.coder_image_repo}:${var.coder_image_tag}"
command = [
"/opt/coder",
"--verbose",
"--url=${local.deployments.primary.url}",
"--token=${trimspace(data.local_file.api_key.content)}",
"templates",
"push",
"--directory=/template",
"--yes",
"kubernetes"
]
volume_mount {
name = "coder-template"
mount_path = "/template"
}
}
volume {
name = "coder-template"
config_map {
name = kubernetes_config_map.template.metadata.0.name
items {
key = "main.tf"
path = "main.tf"
}
}
}
restart_policy = "Never"
}
}
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 = coderd_workspace_proxy.asia.session_token
token = trimspace(data.local_file.asia_proxy_token.content)
}
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 = coderd_workspace_proxy.europe.session_token
token = trimspace(data.local_file.europe_proxy_token.content)
}
lifecycle {
ignore_changes = [timeouts, wait_for_service_account_token]
Expand Down
18 changes: 9 additions & 9 deletions scaletest/terraform/action/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ variable "provisionerd_image_tag" {
}

// Traffic
variable "traffic_bytes_per_tick" {
description = "Number of bytes to send per tick."
default = 1024
}
# 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 "traffic_tick_interval" {
# description = "Interval between ticks."
# default = "10s"
# }

variable "workspace_count" {
description = "Number of workspaces to create."
Expand All @@ -104,5 +104,5 @@ variable "workspace_count" {

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