diff --git a/templates/client-daemonset.yaml b/templates/client-daemonset.yaml index a3269ba9fe..dd56b50aeb 100644 --- a/templates/client-daemonset.yaml +++ b/templates/client-daemonset.yaml @@ -30,6 +30,9 @@ spec: release: {{ .Release.Name }} component: client hasDNS: "true" + {{- if .Values.client.extraLabels }} + {{- toYaml .Values.client.extraLabels | nindent 8 }} + {{- end }} annotations: "consul.hashicorp.com/connect-inject": "false" "consul.hashicorp.com/config-checksum": {{ include (print $.Template.BasePath "/client-config-configmap.yaml") . | sha256sum }} diff --git a/test/unit/client-daemonset.bats b/test/unit/client-daemonset.bats index cf500f7732..d40b4a7881 100755 --- a/test/unit/client-daemonset.bats +++ b/test/unit/client-daemonset.bats @@ -366,6 +366,42 @@ load _helpers [ "${actual}" = "testing" ] } +#-------------------------------------------------------------------- +# extraLabels + +@test "client/DaemonSet: no extra labels defined by default" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/client-daemonset.yaml \ + . | tee /dev/stderr | + yq -r '.spec.template.metadata.labels | del(."app") | del(."chart") | del(."release") | del(."component") | del(."hasDNS")' | tee /dev/stderr) + [ "${actual}" = "{}" ] +} + +@test "client/DaemonSet: extra labels can be set" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/client-daemonset.yaml \ + --set 'client.extraLabels.foo=bar' \ + . | tee /dev/stderr | + yq -r '.spec.template.metadata.labels.foo' | tee /dev/stderr) + [ "${actual}" = "bar" ] +} + +@test "client/DaemonSet: multiple extra labels can be set" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/client-daemonset.yaml \ + --set 'client.extraLabels.foo=bar' \ + --set 'client.extraLabels.baz=qux' \ + . | tee /dev/stderr) + local actualFoo=$(echo "${actual}" | yq -r '.spec.template.metadata.labels.foo' | tee /dev/stderr) + local actualBaz=$(echo "${actual}" | yq -r '.spec.template.metadata.labels.baz' | tee /dev/stderr) + [ "${actualFoo}" = "bar" ] + [ "${actualBaz}" = "qux" ] +} + + #-------------------------------------------------------------------- # annotations diff --git a/values.yaml b/values.yaml index 1e9ac98e39..e79a8d650b 100644 --- a/values.yaml +++ b/values.yaml @@ -787,6 +787,19 @@ client: # @type: string annotations: null + # Extra labels to attach to the client pods. This should be a regular YAML map. + # + # Example: + # + # ```yaml + # extraLabels: + # labelKey: label-value + # anotherLabelKey: another-label-value + # ``` + # + # @type: map + extraLabels: null + # A list of extra environment variables to set within the stateful set. # These could be used to include proxy settings required for cloud auto-join # feature, in case kubernetes cluster is behind egress http proxies. Additionally,