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

+3-3
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

+5
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

+90
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.

helm/coder/templates/rbac.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ include "libcoder.rbac.tpl" . }}
File renamed without changes.
File renamed without changes.

helm/tests/testdata/command.golden renamed to helm/coder/tests/testdata/command.golden

+66-75
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
apiVersion: v1
44
kind: ServiceAccount
55
metadata:
6-
name: "coder"
7-
annotations:
8-
{}
6+
annotations: {}
97
labels:
10-
helm.sh/chart: coder-0.1.0
11-
app.kubernetes.io/name: coder
128
app.kubernetes.io/instance: release-name
13-
app.kubernetes.io/part-of: coder
14-
app.kubernetes.io/version: "0.1.0"
159
app.kubernetes.io/managed-by: Helm
10+
app.kubernetes.io/name: coder
11+
app.kubernetes.io/part-of: coder
12+
app.kubernetes.io/version: 0.1.0
13+
helm.sh/chart: coder-0.1.0
14+
name: coder
1615
---
1716
# Source: coder/templates/rbac.yaml
1817
apiVersion: rbac.authorization.k8s.io/v1
@@ -100,37 +99,32 @@ spec:
10099
apiVersion: apps/v1
101100
kind: Deployment
102101
metadata:
103-
name: coder
102+
annotations: {}
104103
labels:
105-
helm.sh/chart: coder-0.1.0
106-
app.kubernetes.io/name: coder
107104
app.kubernetes.io/instance: release-name
108-
app.kubernetes.io/part-of: coder
109-
app.kubernetes.io/version: "0.1.0"
110105
app.kubernetes.io/managed-by: Helm
111-
annotations:
112-
{}
106+
app.kubernetes.io/name: coder
107+
app.kubernetes.io/part-of: coder
108+
app.kubernetes.io/version: 0.1.0
109+
helm.sh/chart: coder-0.1.0
110+
name: coder
113111
spec:
114112
replicas: 1
115113
selector:
116114
matchLabels:
117-
app.kubernetes.io/name: coder
118115
app.kubernetes.io/instance: release-name
116+
app.kubernetes.io/name: coder
119117
template:
120118
metadata:
119+
annotations: {}
121120
labels:
122-
helm.sh/chart: coder-0.1.0
123-
app.kubernetes.io/name: coder
124121
app.kubernetes.io/instance: release-name
125-
app.kubernetes.io/part-of: coder
126-
app.kubernetes.io/version: "0.1.0"
127122
app.kubernetes.io/managed-by: Helm
128-
annotations:
129-
{}
123+
app.kubernetes.io/name: coder
124+
app.kubernetes.io/part-of: coder
125+
app.kubernetes.io/version: 0.1.0
126+
helm.sh/chart: coder-0.1.0
130127
spec:
131-
serviceAccountName: "coder"
132-
restartPolicy: Always
133-
terminationGracePeriodSeconds: 60
134128
affinity:
135129
podAntiAffinity:
136130
preferredDuringSchedulingIgnoredDuringExecution:
@@ -144,55 +138,52 @@ spec:
144138
topologyKey: kubernetes.io/hostname
145139
weight: 1
146140
containers:
147-
- name: coder
148-
image: "ghcr.io/coder/coder:latest"
149-
imagePullPolicy: IfNotPresent
150-
command:
151-
- /opt/colin
152-
args:
153-
- server
154-
resources:
155-
{}
156-
lifecycle:
157-
{}
158-
env:
159-
- name: CODER_HTTP_ADDRESS
160-
value: "0.0.0.0:8080"
161-
- name: CODER_PROMETHEUS_ADDRESS
162-
value: "0.0.0.0:2112"
163-
# Set the default access URL so a `helm apply` works by default.
164-
# See: https://github.com/coder/coder/issues/5024
165-
- name: CODER_ACCESS_URL
166-
value: "http://coder.default.svc.cluster.local"
167-
# Used for inter-pod communication with high-availability.
168-
- name: KUBE_POD_IP
169-
valueFrom:
170-
fieldRef:
171-
fieldPath: status.podIP
172-
- name: CODER_DERP_SERVER_RELAY_URL
173-
value: "http://$(KUBE_POD_IP):8080"
174-
175-
ports:
176-
- name: "http"
177-
containerPort: 8080
178-
protocol: TCP
179-
securityContext:
180-
allowPrivilegeEscalation: false
181-
readOnlyRootFilesystem: null
182-
runAsGroup: 1000
183-
runAsNonRoot: true
184-
runAsUser: 1000
185-
seccompProfile:
186-
type: RuntimeDefault
187-
readinessProbe:
188-
httpGet:
189-
path: /healthz
190-
port: "http"
191-
scheme: "HTTP"
192-
livenessProbe:
193-
httpGet:
194-
path: /healthz
195-
port: "http"
196-
scheme: "HTTP"
197-
volumeMounts: []
141+
- args:
142+
- server
143+
command:
144+
- /opt/colin
145+
env:
146+
- name: CODER_HTTP_ADDRESS
147+
value: 0.0.0.0:8080
148+
- name: CODER_PROMETHEUS_ADDRESS
149+
value: 0.0.0.0:2112
150+
- name: CODER_ACCESS_URL
151+
value: http://coder.default.svc.cluster.local
152+
- name: KUBE_POD_IP
153+
valueFrom:
154+
fieldRef:
155+
fieldPath: status.podIP
156+
- name: CODER_DERP_SERVER_RELAY_URL
157+
value: http://$(KUBE_POD_IP):8080
158+
image: ghcr.io/coder/coder:latest
159+
imagePullPolicy: IfNotPresent
160+
lifecycle: {}
161+
livenessProbe:
162+
httpGet:
163+
path: /healthz
164+
port: http
165+
scheme: HTTP
166+
name: coder
167+
ports:
168+
- containerPort: 8080
169+
name: http
170+
protocol: TCP
171+
readinessProbe:
172+
httpGet:
173+
path: /healthz
174+
port: http
175+
scheme: HTTP
176+
resources: {}
177+
securityContext:
178+
allowPrivilegeEscalation: false
179+
readOnlyRootFilesystem: null
180+
runAsGroup: 1000
181+
runAsNonRoot: true
182+
runAsUser: 1000
183+
seccompProfile:
184+
type: RuntimeDefault
185+
volumeMounts: []
186+
restartPolicy: Always
187+
serviceAccountName: coder
188+
terminationGracePeriodSeconds: 60
198189
volumes: []

0 commit comments

Comments
 (0)