Test target cluster setup
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
Steve McMaster 2024-01-31 20:30:29 -05:00
parent 4a29221bf9
commit f0ac76f924
2 changed files with 56 additions and 8 deletions

View File

@ -1,3 +1,9 @@
CLUSTERS = {
"himmelnat": "/mnt/secrets/kubeconfig/himmelnat",
}
DEFAULT_CLUSTER_NAME = "odjur"
TEMPLATES = {
"_distro": {
"alpine": {
@ -33,6 +39,7 @@ TEMPLATES = {
"distro_package_manager": "apt",
"distro_releases": ["20.04", "22.04", "23.04", "23.10"],
"image": "cr.smcm.xyz/coder-images/ubuntu",
"target_clusters": ["himmelnat"],
},
},
"_lang": {
@ -43,7 +50,7 @@ TEMPLATES = {
"distro_choices": [
{"label": "Ubuntu", "suffix": ""},
{"label": "Alpine Linux", "suffix": "-alpine"},
]
],
},
"golang": {
"lang": "golang",
@ -52,7 +59,7 @@ TEMPLATES = {
"distro_choices": [
{"label": "Debian", "suffix": ""},
{"label": "Alpine Linux", "suffix": "-alpine"},
]
],
},
"gradle": {
"lang": "gradle",
@ -62,7 +69,7 @@ TEMPLATES = {
"distro_choices": [
{"label": "Debian", "suffix": ""},
{"label": "Alpine Linux", "suffix": "-alpine"},
]
],
},
"maven": {
"lang": "eclipse-temurin-maven",
@ -71,7 +78,7 @@ TEMPLATES = {
"distro_choices": [
{"label": "Ubuntu", "suffix": ""},
{"label": "Alpine Linux", "suffix": "-alpine"},
]
],
},
"node": {
"lang": "node",
@ -81,7 +88,7 @@ TEMPLATES = {
"distro_choices": [
{"label": "Debian", "suffix": ""},
{"label": "Alpine Linux", "suffix": "-alpine"},
]
],
},
"python": {
"lang": "python",
@ -90,7 +97,7 @@ TEMPLATES = {
"distro_choices": [
{"label": "Debian", "suffix": ""},
{"label": "Alpine Linux", "suffix": "-alpine"},
]
],
},
"rust": {
"lang": "rust",
@ -99,7 +106,7 @@ TEMPLATES = {
"distro_choices": [
{"label": "Debian", "suffix": ""},
{"label": "Alpine Linux", "suffix": "-alpine"},
]
],
},
},
"android": {
@ -115,7 +122,7 @@ TEMPLATES = {
"jupyter-scipy-notebook": {
"image": "cr.smcm.xyz/coder-images/jupyter-scipy-notebook",
"coder_user": "jovyan",
"coder_user_gid": "100"
"coder_user_gid": "100",
},
},
"splunk": {
@ -152,6 +159,11 @@ def main(ctx):
for jinja_template in TEMPLATES:
for (coder_template, context) in TEMPLATES[jinja_template].items():
target_clusters = [{"name": DEFAULT_CLUSTER_NAME}]
for cluster_name in context.pop("clusters", []):
target_clusters.append({"name": cluster_name, "config_path": CLUSTERS[cluster_name]})
context["target_clusters"] = target_clusters
pipeline["steps"].extend([
{
"name": "generate {coder_template}".format(coder_template = coder_template),

View File

@ -12,6 +12,17 @@ terraform {
}
}
}
{% if target_cluster|length > 1 %}
{% for cluster in target_clusters %}
provider "kubernetes" {
alias = "{{cluster['name']}}"
{% if "config_path" in cluster %}
config_path = "{{cluster['config_path']}}"
{% endif %}
}
{% endfor %}
{% endif %}
{% endblock %}
{% if coder_user is not defined %}
@ -44,6 +55,25 @@ locals {
}
{% block parameters %}
{% block target_cluster_parameter %}
{% if target_cluster|length > 1 %}
data "coder_parameter" "target_cluster" {
name = "target_cluster"
display_name = "Target Cluster"
description = "The target kubernetes cluster"
default = "{{target_cluster[0]['name']}}"
icon = "/icon/k8s.png"
mutable = false
{% for cluster in target_clusters %}
option {
name = "{{cluster['name']}}"
value = "{{cluster ['name']}}"
}
{% endfor %}
}
{% endif %}
{% endblock %}
{% block cpu_parameter %}
data "coder_parameter" "cpu" {
name = "cpu"
@ -304,6 +334,9 @@ resource "coder_script" "{{ startup_script }}" {
{% block home_volume %}
resource "kubernetes_persistent_volume_claim" "home" {
{% if target_cluster %}
provider = kubernetes.{{target_cluster}}
{% endif %}
metadata {
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
namespace = "coder"
@ -337,6 +370,9 @@ resource "kubernetes_persistent_volume_claim" "home" {
{% block kubernetes_pod_main %}
resource "kubernetes_deployment" "main" {
{% if target_cluster %}
provider = kubernetes.{{target_cluster}}
{% endif %}
count = data.coder_workspace.me.start_count
depends_on = [
kubernetes_persistent_volume_claim.home