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
push template
  • Loading branch information
f0ssel committed Dec 11, 2024
commit 5385e883e4e6db1ec08d1e5a65533883042469ff
43 changes: 27 additions & 16 deletions scaletest/terraform/action/coder_proxies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ resource "null_resource" "api_key" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOF
set -e

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
Expand All @@ -28,12 +30,13 @@ 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' \
echo -n $${session_token} > ${path.module}/.coderv2/session_token

api_key=$(curl '${local.deployments.primary.url}/api/v2/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
}
Expand All @@ -58,34 +61,42 @@ EOF
}
}

resource "null_resource" "proxy_tokens" {
resource "null_resource" "europe_proxy_token" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOF
europe_token=$(curl '${local.deployments.primary.url}/api/v2/workspaceproxies' \
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
--insecure --silent \
| jq -r .proxy_token > ${path.module}/.coderv2/europe_proxy_token
EOF
}

depends_on = [data.http.coder_healthy]
depends_on = [null_resource.license]
}

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

resource "null_resource" "asia_proxy_token" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOF
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 > ${path.module}/.coderv2/asia_proxy_token
EOF
}

depends_on = [null_resource.license]
}

data "local_file" "asia_proxy_token" {
filename = "${path.module}/.coderv2/asia_proxy_token"
depends_on = [null_resource.proxy_tokens]
depends_on = [null_resource.asia_proxy_token]
}
80 changes: 42 additions & 38 deletions scaletest/terraform/action/coder_templates.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ resource "kubernetes_config_map" "template" {
}
}

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

metadata {
Expand All @@ -109,48 +109,52 @@ resource "kubernetes_pod" "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}"]
completions = 1
template {
metadata {}
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"
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=/home/coder/template",
"--yes",
"kubernetes"
]
volume_mount {
name = "coder-template"
mount_path = "/home/coder/template/main.tf"
sub_path = "main.tf"
}
}
volume {
name = "coder-template"
config_map {
name = kubernetes_config_map.template.metadata.0.name
}
}
restart_policy = "Never"
}
}
restart_policy = "Never"
}
wait_for_completion = true
}
14 changes: 13 additions & 1 deletion scaletest/terraform/action/workspace_traffic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@
# 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)} exp scaletest create-workspaces --count ${var.workspace_count} --template=kubernetes --concurrency ${var.workspace_create_concurrency} --no-cleanup"]
# command = [
# "/opt/coder",
# "--verbose",
# "--url=${local.deployments.primary.url}",
# "--token=${trimspace(data.local_file.api_key.content)}",
# "exp",
# "scaletest",
# "create-workspaces",
# "--count=${var.workspace_count}",
# "--template=kubernetes",
# "--concurrency=${var.workspace_create_concurrency}",
# "--no-cleanup"
# ]
# }
# restart_policy = "Never"
# }
Expand Down