Skip to content

Commit dd59fcb

Browse files
committed
Refactor helm to extract common templates to libcoder
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent cb4989c commit dd59fcb

37 files changed

+963
-950
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen $(FIND_EXCLUSIONS)
553553
./scripts/apidocgen/generate.sh
554554
pnpm run format:write:only ./docs/api ./docs/manifest.json ./coderd/apidoc/swagger.json
555555

556-
update-golden-files: cli/testdata/.gen-golden helm/tests/testdata/.gen-golden scripts/ci-report/testdata/.gen-golden enterprise/cli/testdata/.gen-golden
556+
update-golden-files: cli/testdata/.gen-golden helm/coder/tests/testdata/.gen-golden scripts/ci-report/testdata/.gen-golden enterprise/cli/testdata/.gen-golden
557557
.PHONY: update-golden-files
558558

559559
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) $(wildcard cli/*.tpl) $(GO_SRC_FILES) $(wildcard cli/*_test.go)
@@ -564,8 +564,8 @@ enterprise/cli/testdata/.gen-golden: $(wildcard enterprise/cli/testdata/*.golden
564564
go test ./enterprise/cli -run="TestEnterpriseCommandHelp" -update
565565
touch "$@"
566566

567-
helm/tests/testdata/.gen-golden: $(wildcard helm/tests/testdata/*.yaml) $(wildcard helm/tests/testdata/*.golden) $(GO_SRC_FILES) $(wildcard helm/tests/*_test.go)
568-
go test ./helm/tests -run=TestUpdateGoldenFiles -update
567+
helm/coder/tests/testdata/.gen-golden: $(wildcard helm/coder/tests/testdata/*.yaml) $(wildcard helm/coder/tests/testdata/*.golden) $(GO_SRC_FILES) $(wildcard helm/coder/tests/*_test.go)
568+
go test ./helm/coder/tests -run=TestUpdateGoldenFiles -update
569569
touch "$@"
570570

571571
scripts/ci-report/testdata/.gen-golden: $(wildcard scripts/ci-report/testdata/*) $(wildcard scripts/ci-report/*.go)
File renamed without changes.

helm/Chart.yaml renamed to helm/coder/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ maintainers:
2727
- name: Coder Technologies, Inc.
2828
email: support@coder.com
2929
url: https://coder.com/contact
30+
31+
dependencies:
32+
- name: libcoder
33+
version: 0.1.0
34+
repository: file://../libcoder
File renamed without changes.

helm/coder/charts/libcoder-0.1.0.tgz

2.89 KB
Binary file not shown.
File renamed without changes.

helm/coder/templates/coder.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
{{- include "libcoder.serviceaccount" (list . "coder.serviceaccount") -}}
3+
{{- define "coder.serviceaccount" -}}
4+
{{- end }}
5+
6+
---
7+
{{ include "libcoder.deployment" (list . "coder.deployment") -}}
8+
{{- define "coder.deployment" -}}
9+
spec:
10+
template:
11+
spec:
12+
containers:
13+
-
14+
{{ include "libcoder.containerspec" (list . "coder.containerspec") | indent 8}}
15+
16+
{{- end }}
17+
18+
{{- define "coder.containerspec" -}}
19+
args:
20+
{{- if .Values.coder.commandArgs }}
21+
{{- toYaml .Values.coder.commandArgs | nindent 12 }}
22+
{{- else }}
23+
{{- if .Values.coder.workspaceProxy }}
24+
- wsproxy
25+
{{- end }}
26+
- server
27+
{{- end }}
28+
env:
29+
- name: CODER_HTTP_ADDRESS
30+
value: "0.0.0.0:8080"
31+
- name: CODER_PROMETHEUS_ADDRESS
32+
value: "0.0.0.0:2112"
33+
# Set the default access URL so a `helm apply` works by default.
34+
# See: https://github.com/coder/coder/issues/5024
35+
{{- $hasAccessURL := false }}
36+
{{- range .Values.coder.env }}
37+
{{- if eq .name "CODER_ACCESS_URL" }}
38+
{{- $hasAccessURL = true }}
39+
{{- end }}
40+
{{- end }}
41+
{{- if not $hasAccessURL }}
42+
- name: CODER_ACCESS_URL
43+
value: {{ include "coder.defaultAccessURL" . | quote }}
44+
{{- end }}
45+
# Used for inter-pod communication with high-availability.
46+
- name: KUBE_POD_IP
47+
valueFrom:
48+
fieldRef:
49+
fieldPath: status.podIP
50+
- name: CODER_DERP_SERVER_RELAY_URL
51+
value: "http://$(KUBE_POD_IP):8080"
52+
{{- include "coder.tlsEnv" . }}
53+
{{- with .Values.coder.env }}
54+
{{ toYaml . }}
55+
{{- end }}
56+
ports:
57+
- name: "http"
58+
containerPort: 8080
59+
protocol: TCP
60+
{{- if eq (include "coder.tlsEnabled" .) "true" }}
61+
- name: "https"
62+
containerPort: 8443
63+
protocol: TCP
64+
{{- end }}
65+
{{- range .Values.coder.env }}
66+
{{- if eq .name "CODER_PROMETHEUS_ENABLE" }}
67+
{{/*
68+
This sadly has to be nested to avoid evaluating the second part
69+
of the condition too early and potentially getting type errors if
70+
the value is not a string (like a `valueFrom`). We do not support
71+
`valueFrom` for this env var specifically.
72+
*/}}
73+
{{- if eq .value "true" }}
74+
- name: "prometheus-http"
75+
containerPort: 2112
76+
protocol: TCP
77+
{{- end }}
78+
{{- end }}
79+
{{- end }}
80+
readinessProbe:
81+
httpGet:
82+
path: /healthz
83+
port: "http"
84+
scheme: "HTTP"
85+
livenessProbe:
86+
httpGet:
87+
path: /healthz
88+
port: "http"
89+
scheme: "HTTP"
90+
{{- end }}
File renamed without changes.
File renamed without changes.

helm/coder/templates/rbac.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ include "libcoder.rbac.tpl" . }}

0 commit comments

Comments
 (0)