diff --git a/application/templates/_helpers.tpl b/application/templates/_helpers.tpl index 48f1ef03..48f8166d 100644 --- a/application/templates/_helpers.tpl +++ b/application/templates/_helpers.tpl @@ -11,7 +11,8 @@ Define the name of the chart/application. Define the name of the chart/application. */}} {{- define "application.version" -}} -{{ regexReplaceAll "[^a-zA-Z0-9_\\.\\-]" .Values.deployment.image.tag "-" | trunc 63 | trimSuffix "-" -}} + {{- $version := default "" .Values.deployment.image.tag -}} + {{- regexReplaceAll "[^a-zA-Z0-9_\\.\\-]" $version "-" | trunc 63 | trimSuffix "-" -}} {{- end -}} {{/* @@ -39,8 +40,8 @@ Common labels */}} {{- define "application.labels" -}} helm.sh/chart: {{ include "application.chart" . }} -{{- if .Values.deployment.image.tag }} -app.kubernetes.io/version: {{ include "application.version" . | quote }} +{{- with include "application.version" . }} +app.kubernetes.io/version: {{ quote . }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/part-of: {{ include "application.name" . }} diff --git a/application/tests/deployment_test.yaml b/application/tests/deployment_test.yaml index 1c368a35..c98cae84 100644 --- a/application/tests/deployment_test.yaml +++ b/application/tests/deployment_test.yaml @@ -50,6 +50,9 @@ tests: - equal: path: spec.template.spec.containers[0].image value: example-image:example-tag + - equal: + path: metadata.labels["app.kubernetes.io/version"] + value: example-tag - it: uses image digest when given set: @@ -60,6 +63,8 @@ tests: - equal: path: spec.template.spec.containers[0].image value: example-image@sha256:example-digest + - isNull: + path: metadata.labels["app.kubernetes.io/version"] - it: uses both image digest and tag when given both set: