Skip to content

Commit 21af020

Browse files
authored
feat: add external provisioner daemon helm chart (#8939)
* Refactor helm to extract common templates to libcoder Signed-off-by: Spike Curtis <spike@coder.com> * Remove comment from libcoder Chart.yaml Signed-off-by: Spike Curtis <spike@coder.com> * Add provisioner helm chart * Fix prettier, linting, docs Signed-off-by: Spike Curtis <spike@coder.com> * Log at INFO when provisionerd connects to coderd Signed-off-by: Spike Curtis <spike@coder.com> * remove unnecessary exports in helm tests Signed-off-by: Spike Curtis <spike@coder.com> --------- Signed-off-by: Spike Curtis <spike@coder.com>
1 parent cdb0890 commit 21af020

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2616
-981
lines changed

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ scaletest/terraform/secrets.tfvars
6767
# .prettierignore.include:
6868
# Helm templates contain variables that are invalid YAML and can't be formatted
6969
# by Prettier.
70-
helm/templates/*.yaml
70+
helm/**/templates/*.yaml
7171

7272
# Terraform state files used in tests, these are automatically generated.
7373
# Example: provisioner/terraform/testdata/instance-id/instance-id.tfstate.json

.prettierignore.include

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Helm templates contain variables that are invalid YAML and can't be formatted
22
# by Prettier.
3-
helm/templates/*.yaml
3+
helm/**/templates/*.yaml
44

55
# Terraform state files used in tests, these are automatically generated.
66
# Example: provisioner/terraform/testdata/instance-id/instance-id.tfstate.json

Makefile

+7-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 helm/provisioner/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,12 @@ 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
569+
touch "$@"
570+
571+
helm/provisioner/tests/testdata/.gen-golden: $(wildcard helm/provisioner/tests/testdata/*.yaml) $(wildcard helm/provisioner/tests/testdata/*.golden) $(GO_SRC_FILES) $(wildcard helm/provisioner/tests/*_test.go)
572+
go test ./helm/provisioner/tests -run=TestUpdateGoldenFiles -update
569573
touch "$@"
570574

571575
scripts/ci-report/testdata/.gen-golden: $(wildcard scripts/ci-report/testdata/*) $(wildcard scripts/ci-report/*.go)

docs/admin/configure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ If you are providing TLS certificates directly to the Coder server, either
4242

4343
1. Use a single certificate and key for both the root and wildcard domains.
4444
2. Configure multiple certificates and keys via
45-
[`coder.tls.secretNames`](https://github.com/coder/coder/blob/main/helm/values.yaml) in the Helm Chart, or
45+
[`coder.tls.secretNames`](https://github.com/coder/coder/blob/main/helm/coder/values.yaml) in the Helm Chart, or
4646
[`--tls-cert-file`](../cli/server.md#--tls-cert-file) and [`--tls-key-file`](../cli/server.md#--tls-key-file) command
4747
line options (these both take a comma separated list of files; list certificates and their respective keys in the
4848
same order).

docs/admin/scale.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Users accessing workspaces via SSH will consume fewer resources, as SSH connecti
4242

4343
Workspace builds are CPU-intensive, as it relies on Terraform. Various [Terraform providers](https://registry.terraform.io/browse/providers) have different resource requirements.
4444
When tested with our [kubernetes](https://github.com/coder/coder/tree/main/examples/templates/kubernetes) template, `coderd` will consume roughly 0.25 cores per concurrent workspace build.
45-
For effective provisioning, our helm chart prefers to schedule [one coderd replica per-node](https://github.com/coder/coder/blob/main/helm/values.yaml#L188-L202).
45+
For effective provisioning, our helm chart prefers to schedule [one coderd replica per-node](https://github.com/coder/coder/blob/main/helm/coder/values.yaml#L188-L202).
4646

4747
We recommend:
4848

docs/install/kubernetes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ to log in and manage templates.
105105
> You can view our
106106
> [Helm README](https://github.com/coder/coder/blob/main/helm#readme) for
107107
> details on the values that are available, or you can view the
108-
> [values.yaml](https://github.com/coder/coder/blob/main/helm/values.yaml)
108+
> [values.yaml](https://github.com/coder/coder/blob/main/helm/coder/values.yaml)
109109
> file directly.
110110
111111
1. Run the following command to install the chart in your cluster.

helm/Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ all: lint
1313
lint: lint/helm
1414
.PHONY: lint
1515

16-
lint/helm:
17-
helm lint --strict --set coder.image.tag=v0.0.1 .
16+
lint/helm: lint/helm/coder lint/helm/provisioner
1817
.PHONY: lint/helm
18+
19+
lint/helm/coder:
20+
helm lint --strict --set coder.image.tag=v0.0.1 coder/
21+
.PHONY: lint/helm/coder
22+
23+
lint/helm/provisioner:
24+
helm lint --strict --set coder.image.tag=v0.0.1 provisioner/
25+
.PHONY: lint/helm/provisioner
File renamed without changes.

helm/coder/Chart.lock

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: libcoder
3+
repository: file://../libcoder
4+
version: 0.1.0
5+
digest: sha256:5c9a99109258073b590a9f98268490ef387fde24c0c7c7ade9c1a8c7ef5e6e10
6+
generated: "2023-08-08T07:27:19.677972411Z"

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ keywords:
2121
- coder
2222
- terraform
2323
sources:
24-
- https://github.com/coder/coder/tree/main/helm
24+
- https://github.com/coder/coder/tree/main/helm/coder
2525
icon: https://helm.coder.com/coder_logo_black.png
2626
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.93 KB
Binary file not shown.
File renamed without changes.

helm/coder/templates/_coder.tpl

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

helm/coder/templates/coder.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
{{ include "libcoder.serviceaccount" (list . "coder.serviceaccount") }}
3+
4+
---
5+
{{ include "libcoder.deployment" (list . "coder.deployment") }}
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.

helm/tests/chart_test.go renamed to helm/coder/tests/chart_test.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
// All values and golden files are located in the `testdata` directory.
2121
// To update golden files, run `go test . -update`.
2222

23-
// UpdateGoldenFiles is a flag that can be set to update golden files.
24-
var UpdateGoldenFiles = flag.Bool("update", false, "Update golden files")
23+
// updateGoldenFiles is a flag that can be set to update golden files.
24+
var updateGoldenFiles = flag.Bool("update", false, "Update golden files")
2525

26-
var TestCases = []TestCase{
26+
var testCases = []testCase{
2727
{
2828
name: "default_values",
2929
expectedError: "",
@@ -56,24 +56,28 @@ var TestCases = []TestCase{
5656
name: "command_args",
5757
expectedError: "",
5858
},
59+
{
60+
name: "provisionerd_psk",
61+
expectedError: "",
62+
},
5963
}
6064

61-
type TestCase struct {
65+
type testCase struct {
6266
name string // Name of the test case. This is used to control which values and golden file are used.
6367
expectedError string // Expected error from running `helm template`.
6468
}
6569

66-
func (tc TestCase) valuesFilePath() string {
70+
func (tc testCase) valuesFilePath() string {
6771
return filepath.Join("./testdata", tc.name+".yaml")
6872
}
6973

70-
func (tc TestCase) goldenFilePath() string {
74+
func (tc testCase) goldenFilePath() string {
7175
return filepath.Join("./testdata", tc.name+".golden")
7276
}
7377

7478
func TestRenderChart(t *testing.T) {
7579
t.Parallel()
76-
if *UpdateGoldenFiles {
80+
if *updateGoldenFiles {
7781
t.Skip("Golden files are being updated. Skipping test.")
7882
}
7983
if testutil.InCI() {
@@ -85,7 +89,7 @@ func TestRenderChart(t *testing.T) {
8589

8690
// Ensure that Helm is available in $PATH
8791
helmPath := lookupHelm(t)
88-
for _, tc := range TestCases {
92+
for _, tc := range testCases {
8993
tc := tc
9094
t.Run(tc.name, func(t *testing.T) {
9195
t.Parallel()
@@ -121,12 +125,12 @@ func TestRenderChart(t *testing.T) {
121125

122126
func TestUpdateGoldenFiles(t *testing.T) {
123127
t.Parallel()
124-
if !*UpdateGoldenFiles {
128+
if !*updateGoldenFiles {
125129
t.Skip("Run with -update to update golden files")
126130
}
127131

128132
helmPath := lookupHelm(t)
129-
for _, tc := range TestCases {
133+
for _, tc := range testCases {
130134
if tc.expectedError != "" {
131135
t.Logf("skipping test case %q with render error", tc.name)
132136
continue

0 commit comments

Comments
 (0)