Skip to content

Commit

Permalink
Add ability to set extra labels on client pods (hashicorp#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishforbes authored Jan 27, 2021
1 parent 1e2330e commit c93b5db
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions templates/client-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
36 changes: 36 additions & 0 deletions test/unit/client-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c93b5db

Please sign in to comment.