From ea65f664a4474e8d8284a7200f6b5358aaa093ff Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 2 Dec 2021 16:07:03 +0100 Subject: [PATCH] controllers: use short SHA in chart SemVer meta As the full version can be used as a label value, the full SHA from the reference takes up too much space from the 63 characters available in total. To mitigate against this, we now take a "short" version of the first 12 characters, which is the limit the Linux code base reached in 2019: http://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#Short-SHA-1 This should be sufficient to safely detect all changes within the context of operations. Signed-off-by: Hidde Beydals --- controllers/helmchart_controller.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index ddc149f45..d12081536 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -447,7 +447,12 @@ func (r *HelmChartReconciler) fromTarballArtifact(ctx context.Context, source so if c.Spec.ReconcileStrategy == sourcev1.ReconcileStrategyRevision { // Isolate the commit SHA from GitRepository type artifacts by removing the branch/ prefix. splitRev := strings.Split(source.Revision, "/") - opts.VersionMetadata = splitRev[len(splitRev)-1] + sha := splitRev[len(splitRev)-1] + // The version is used in e.g. resource labels in many charts, which means it has a limited + // length of 63 characters. To not use all that space with e.g. the length from a Git commit + // SHA (40 characters): take the short SHA of the first 12 characters. + // Length ref: http://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#Short-SHA-1 + opts.VersionMetadata = sha[0:12] } // Set the VersionMetadata to the object's Generation if ValuesFiles is defined // This ensures changes can be noticed by the Artifact consumer