Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions charts/openhab/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ Validate ConfigMap sync configuration.
{{- end }}
{{- end }}

{{/*
Validate pod labels do not override immutable selector labels.
*/}}
{{- define "openhab.validatePodLabels" -}}
{{- $podLabels := .Values.podLabels | default dict -}}
{{- if hasKey $podLabels "app.kubernetes.io/name" -}}
{{- fail "podLabels must not override the selector label app.kubernetes.io/name" -}}
{{- end -}}
{{- if hasKey $podLabels "app.kubernetes.io/instance" -}}
{{- fail "podLabels must not override the selector label app.kubernetes.io/instance" -}}
{{- end -}}
{{- end }}

{{/*
Resolve the admin secret name.
*/}}
Expand Down
3 changes: 2 additions & 1 deletion charts/openhab/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{- include "openhab.validateReplicaCount" . }}
{{- include "openhab.validateAdmin" . }}
{{- include "openhab.validateConfigMaps" . }}
{{- include "openhab.validatePodLabels" . }}
{{- $hasSitemaps := and .Values.configMaps.sitemaps.enabled (gt (len (.Values.configMaps.sitemaps.files | default dict)) 0) }}
{{- $hasThings := and .Values.configMaps.things.enabled (gt (len (.Values.configMaps.things.files | default dict)) 0) }}
{{- $hasItems := and .Values.configMaps.items.enabled (gt (len (.Values.configMaps.items.files | default dict)) 0) }}
Expand Down Expand Up @@ -35,7 +36,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "openhab.labels" . | nindent 8 }}
{{- include "openhab.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
4 changes: 4 additions & 0 deletions charts/openhab/tests/podlabels-selector-combined-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
podLabels:
app.kubernetes.io/name: custom
app.kubernetes.io/instance: custom
3 changes: 3 additions & 0 deletions charts/openhab/tests/podlabels-selector-instance-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
podLabels:
app.kubernetes.io/instance: custom
3 changes: 3 additions & 0 deletions charts/openhab/tests/podlabels-selector-name-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
podLabels:
app.kubernetes.io/name: custom
21 changes: 21 additions & 0 deletions charts/openhab/tests/validation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,24 @@ tests:
asserts:
- isKind:
of: StatefulSet

- it: should fail when podLabels override selector name
values:
- podlabels-selector-name-values.yaml
asserts:
- failedTemplate:
errorMessage: "podLabels must not override the selector label app.kubernetes.io/name"

- it: should fail when podLabels override selector name and instance
values:
- podlabels-selector-combined-values.yaml
asserts:
- failedTemplate:
errorMessage: "podLabels must not override the selector label app.kubernetes.io/name"

- it: should fail when podLabels override selector instance
values:
- podlabels-selector-instance-values.yaml
asserts:
- failedTemplate:
errorMessage: "podLabels must not override the selector label app.kubernetes.io/instance"