Skip to content

Commit

Permalink
controllers: use short SHA in chart SemVer meta
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hiddeco committed Dec 2, 2021
1 parent 59dc602 commit ea65f66
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion controllers/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea65f66

Please sign in to comment.