From 2fe2f602d814471004747fe60c72cd1e896dd1f6 Mon Sep 17 00:00:00 2001 From: Henry Whitaker Date: Tue, 23 Jan 2024 13:52:01 +0000 Subject: [PATCH 1/2] Add app+chart version overrides --- chart/Chart.yaml | 2 +- chart/templates/_helpers.tpl | 6 +++--- chart/tests/deployment_test.yaml | 23 +++++++++++++++++++++++ chart/values.yaml | 5 +++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/chart/Chart.yaml b/chart/Chart.yaml index db8f9b9..6ba4d55 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -13,7 +13,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.3.2 +version: 1.3.3 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl index 2587bea..4510f93 100644 --- a/chart/templates/_helpers.tpl +++ b/chart/templates/_helpers.tpl @@ -27,7 +27,7 @@ If release name contains chart name it will be used as a full name. Create chart name and version as used by the chart label. */}} {{- define "generic.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- printf "%s-%s" .Chart.Name (default .Chart.Version .Values.versionOverride) | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} {{/* @@ -36,8 +36,8 @@ Common labels {{- define "generic.labels" -}} helm.sh/chart: {{ include "generic.chart" . }} {{ include "generic.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- if or (.Chart.AppVersion) (.Values.appVersionOverride) }} +app.kubernetes.io/version: {{ default .Chart.AppVersion .Values.appVersionOverride | quote }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} diff --git a/chart/tests/deployment_test.yaml b/chart/tests/deployment_test.yaml index f7c9d82..613232b 100644 --- a/chart/tests/deployment_test.yaml +++ b/chart/tests/deployment_test.yaml @@ -353,3 +353,26 @@ tests: path: .spec.template.spec.containers[0].readinessProbe.exec.command content: tail + - it: sets the app version according to the chart + chart: + Version: "1.3.2" + appVersion: "1.16.0" + asserts: + - isSubset: + path: .metadata.labels + content: + helm.sh/chart: generic-1.3.2 + app.kubernetes.io/version: "1.16.0" + - it: sets the app version according to the overrides + chart: + Version: 1.3.2 + appVersion: "1.16.0" + set: + versionOverride: 11.0.0 + appVersionOverride: "2.0.0" + asserts: + - isSubset: + path: .metadata.labels + content: + helm.sh/chart: generic-11.0.0 + app.kubernetes.io/version: "2.0.0" diff --git a/chart/values.yaml b/chart/values.yaml index 28e4483..fbb0371 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -5,6 +5,11 @@ nameOverride: "" fullnameOverride: "" +# Override the chart version +versionOverride: "" +# Override the app version +appVersionOverride: "" + replicaCount: 1 image: From 5110b3ce43d9e5fb681de48119a5b0f0a1e329f3 Mon Sep 17 00:00:00 2001 From: Henry Whitaker Date: Tue, 23 Jan 2024 13:54:06 +0000 Subject: [PATCH 2/2] fix version case-typo --- chart/tests/deployment_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chart/tests/deployment_test.yaml b/chart/tests/deployment_test.yaml index 613232b..e01b1ea 100644 --- a/chart/tests/deployment_test.yaml +++ b/chart/tests/deployment_test.yaml @@ -355,7 +355,7 @@ tests: tail - it: sets the app version according to the chart chart: - Version: "1.3.2" + version: "1.3.2" appVersion: "1.16.0" asserts: - isSubset: @@ -365,7 +365,7 @@ tests: app.kubernetes.io/version: "1.16.0" - it: sets the app version according to the overrides chart: - Version: 1.3.2 + version: 1.3.2 appVersion: "1.16.0" set: versionOverride: 11.0.0