From db466964c6cfb3368ab87be6bb4d16f74d5c6fd0 Mon Sep 17 00:00:00 2001 From: Juan Ariza Toledano Date: Tue, 12 Sep 2023 10:21:49 +0200 Subject: [PATCH] [bitnami/common] New helper to return image version (#19223) --- bitnami/common/Chart.yaml | 4 ++-- bitnami/common/templates/_images.tpl | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bitnami/common/Chart.yaml b/bitnami/common/Chart.yaml index d5f9277896..119125eccc 100644 --- a/bitnami/common/Chart.yaml +++ b/bitnami/common/Chart.yaml @@ -6,7 +6,7 @@ annotations: licenses: Apache-2.0 apiVersion: v2 # Please make sure that version and appVersion are always the same. -appVersion: 2.10.1 +appVersion: 2.11.0 description: A Library Helm Chart for grouping common logic between bitnami charts. This chart is not deployable by itself. home: https://bitnami.com icon: https://bitnami.com/downloads/logos/bitnami-mark.png @@ -23,4 +23,4 @@ name: common sources: - https://github.com/bitnami/charts type: library -version: 2.10.1 +version: 2.11.0 diff --git a/bitnami/common/templates/_images.tpl b/bitnami/common/templates/_images.tpl index 2181f32245..e248d6d08e 100644 --- a/bitnami/common/templates/_images.tpl +++ b/bitnami/common/templates/_images.tpl @@ -83,3 +83,19 @@ imagePullSecrets: {{- end }} {{- end }} {{- end -}} + +{{/* +Return the proper image version (ingores image revision/prerelease info & fallbacks to chart appVersion) +{{ include "common.images.version" ( dict "imageRoot" .Values.path.to.the.image "chart" .Chart ) }} +*/}} +{{- define "common.images.version" -}} +{{- $imageTag := .imageRoot.tag | toString -}} +{{/* regexp from https://github.com/Masterminds/semver/blob/23f51de38a0866c5ef0bfc42b3f735c73107b700/version.go#L41-L44 */}} +{{- if regexMatch `^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$` $imageTag -}} + {{- $version := semver $imageTag -}} + {{- printf "%d.%d.%d" $version.Major $version.Minor $version.Patch -}} +{{- else -}} + {{- print .chart.AppVersion -}} +{{- end -}} +{{- end -}} +