Skip to content

Commit a3b9053

Browse files
authored
feat: allow specifying extra labels on the coderd deployment (#182)
This commit allows users to specify arbitrary additional labels on pods in the coderd deployment, and adds unit tests for the above feature.
1 parent 7d8c624 commit a3b9053

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ View [our docs](https://coder.com/docs/setup/installation) for detailed installa
2525
| certs | object | Certificate that will be mounted inside Coder services. | `{"secret":{"key":"","name":""}}` |
2626
| certs.secret.key | string | Key pointing to a certificate in the secret. | `""` |
2727
| certs.secret.name | string | Name of the secret. | `""` |
28-
| coderd | object | Primary service responsible for all things Coder! | `{"affinity":{"podAntiAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"podAffinityTerm":{"labelSelector":{"matchExpressions":[{"key":"app.kubernetes.io/name","operator":"In","values":["coderd"]}]},"topologyKey":"kubernetes.io/hostname"},"weight":1}]}},"builtinProviderServiceAccount":{"annotations":{},"labels":{}},"devurlsHost":"","image":"","oidc":{"enableRefresh":false,"redirectOptions":{}},"podSecurityContext":{"runAsGroup":1000,"runAsNonRoot":true,"runAsUser":1000,"seccompProfile":{"type":"RuntimeDefault"}},"replicas":1,"resources":{"limits":{"cpu":"250m","memory":"512Mi"},"requests":{"cpu":"250m","memory":"512Mi"}},"satellite":{"accessURL":"","enable":false,"primaryURL":""},"securityContext":{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":1000,"runAsNonRoot":true,"runAsUser":1000,"seccompProfile":{"type":"RuntimeDefault"}},"serviceAnnotations":{},"serviceNodePorts":{"http":null,"https":null},"serviceSpec":{"externalTrafficPolicy":"Local","loadBalancerIP":"","loadBalancerSourceRanges":[],"type":"LoadBalancer"},"superAdmin":{"passwordSecret":{"key":"password","name":""}},"tls":{"devurlsHostSecretName":"","hostSecretName":""},"trustProxyIP":false}` |
28+
| coderd | object | Primary service responsible for all things Coder! | `{"affinity":{"podAntiAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"podAffinityTerm":{"labelSelector":{"matchExpressions":[{"key":"app.kubernetes.io/name","operator":"In","values":["coderd"]}]},"topologyKey":"kubernetes.io/hostname"},"weight":1}]}},"builtinProviderServiceAccount":{"annotations":{},"labels":{}},"devurlsHost":"","extraLabels":{},"image":"","oidc":{"enableRefresh":false,"redirectOptions":{}},"podSecurityContext":{"runAsGroup":1000,"runAsNonRoot":true,"runAsUser":1000,"seccompProfile":{"type":"RuntimeDefault"}},"replicas":1,"resources":{"limits":{"cpu":"250m","memory":"512Mi"},"requests":{"cpu":"250m","memory":"512Mi"}},"satellite":{"accessURL":"","enable":false,"primaryURL":""},"securityContext":{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":1000,"runAsNonRoot":true,"runAsUser":1000,"seccompProfile":{"type":"RuntimeDefault"}},"serviceAnnotations":{},"serviceNodePorts":{"http":null,"https":null},"serviceSpec":{"externalTrafficPolicy":"Local","loadBalancerIP":"","loadBalancerSourceRanges":[],"type":"LoadBalancer"},"superAdmin":{"passwordSecret":{"key":"password","name":""}},"tls":{"devurlsHostSecretName":"","hostSecretName":""},"trustProxyIP":false}` |
2929
| coderd.affinity | object | Allows specifying an affinity rule for the `coderd` deployment. The default rule prefers to schedule coderd pods on different nodes, which is only applicable if coderd.replicas is greater than 1. | `{"podAntiAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"podAffinityTerm":{"labelSelector":{"matchExpressions":[{"key":"app.kubernetes.io/name","operator":"In","values":["coderd"]}]},"topologyKey":"kubernetes.io/hostname"},"weight":1}]}}` |
3030
| coderd.builtinProviderServiceAccount | object | Customize the built-in Kubernetes provider service account. | `{"annotations":{},"labels":{}}` |
3131
| coderd.builtinProviderServiceAccount.annotations | object | A KV mapping of annotations. See: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ | `{}` |
3232
| coderd.builtinProviderServiceAccount.labels | object | Add labels to the service account used for the built-in provider. | `{}` |
3333
| coderd.devurlsHost | string | Wildcard hostname to allow matching against custom-created dev URLs. Leaving as an empty string results in DevURLs being disabled. | `""` |
34+
| coderd.extraLabels | object | Allows specifying additional labels to pods in the `coderd` deployment (.spec.template.metadata.labels). | `{}` |
3435
| coderd.image | string | Injected by Coder during release. | `""` |
3536
| coderd.podSecurityContext | object | Fields related to the pod's security context (as opposed to the container). Some fields are also present in the container security context, which will take precedence over these values. | `{"runAsGroup":1000,"runAsNonRoot":true,"runAsUser":1000,"seccompProfile":{"type":"RuntimeDefault"}}` |
3637
| coderd.podSecurityContext.runAsGroup | int | Sets the group id of the pod. For security reasons, we recommend using a non-root group. | `1000` |

templates/coderd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ spec:
2727
app.kubernetes.io/part-of: coder
2828
app: {{ include "coder.serviceName" . }}
2929
coder.deployment: {{ include "coder.serviceName" . }}
30+
{{- with .Values.coderd.extraLabels -}}
31+
{{ toYaml . | nindent 8 }}
32+
{{- end }}
3033
annotations: {{ toYaml .Values.services.annotations | nindent 8 }}
3134
spec:
3235
securityContext: {{ toYaml .Values.coderd.podSecurityContext | nindent 8 }}

tests/deployment_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestDeployment(t *testing.T) {
10+
t.Parallel()
11+
12+
t.Run("Labels", func(t *testing.T) {
13+
var (
14+
expectedLabels = map[string]string{
15+
"app": "coderd",
16+
"app.kubernetes.io/name": "coderd",
17+
"app.kubernetes.io/part-of": "coder",
18+
"coder.deployment": "coderd",
19+
}
20+
extraLabels = map[string]string{
21+
"foo": "bar",
22+
}
23+
24+
objs = LoadChart(t).MustRender(t, func(cv *CoderValues) {
25+
cv.Coderd.ExtraLabels = extraLabels
26+
})
27+
coderd = MustFindDeployment(t, objs, "coderd")
28+
)
29+
30+
for k, v := range extraLabels {
31+
if _, found := expectedLabels[k]; !found {
32+
expectedLabels[k] = v
33+
}
34+
}
35+
36+
require.EqualValues(t, expectedLabels, coderd.Spec.Template.Labels)
37+
})
38+
}

tests/values.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type CoderdValues struct {
8989
OIDC *CoderdOIDCValues `json:"oidc" yaml:"oidc"`
9090
SuperAdmin *CoderdSuperAdminValues `json:"superAdmin" yaml:"superAdmin"`
9191
Affinity *corev1.Affinity `json:"affinity" yaml:"affinity"`
92+
ExtraLabels map[string]string `json:"extraLabels" yaml:"extraLabels"`
9293
}
9394

9495
// CoderdServiceNodePortsValues reflect values from

values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ coderd:
165165
# contains the super admin password.
166166
key: "password"
167167

168+
# coderd.extraLabels -- Allows specifying additional labels to pods in the
169+
# `coderd` deployment (.spec.template.metadata.labels).
170+
extraLabels: {}
168171
# coderd.affinity -- Allows specifying an affinity rule for the `coderd`
169172
# deployment. The default rule prefers to schedule coderd pods on different
170173
# nodes, which is only applicable if coderd.replicas is greater than 1.

0 commit comments

Comments
 (0)