Skip to content

Commit 76b4044

Browse files
committed
Support Helm semver encoding in OCI repositories
1 parent 97c995b commit 76b4044

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

internal/controller/ocirepository_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,11 @@ func (r *OCIRepositoryReconciler) getTagBySemver(repo name.Repository, exp strin
898898

899899
var matchingVersions []*semver.Version
900900
for _, t := range validTags {
901-
v, err := version.ParseVersion(t)
901+
// Helm translates `+` to `_` in OCI tags, because `+` is not a valid tag character.
902+
versionStr := strings.Replace(t, "_", "+", 1)
903+
// It would be even better to use `org.opencontainers.image.version` annotation
904+
// if present, but that adds a fetch for each tag.
905+
v, err := version.ParseVersion(versionStr)
902906
if err != nil {
903907
continue
904908
}
@@ -913,7 +917,8 @@ func (r *OCIRepositoryReconciler) getTagBySemver(repo name.Repository, exp strin
913917
}
914918

915919
sort.Sort(sort.Reverse(semver.Collection(matchingVersions)))
916-
return repo.Tag(matchingVersions[0].Original()), nil
920+
asTag := strings.Replace(matchingVersions[0].Original(), "+", "_", 1)
921+
return repo.Tag(asTag), nil
917922
}
918923

919924
// keychain generates the credential keychain based on the resource

internal/controller/ocirepository_controller_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,7 @@ func TestOCIRepository_getArtifactRef(t *testing.T) {
28662866
"6.1.5",
28672867
"6.1.6-rc.1",
28682868
"6.1.6",
2869+
"6.1.7_ref.1234567", // Version 6.1.7+ref.1234567, encoded as a tag
28692870
)
28702871
g.Expect(err).ToNot(HaveOccurred())
28712872

@@ -2898,12 +2899,12 @@ func TestOCIRepository_getArtifactRef(t *testing.T) {
28982899
want: "ghcr.io/stefanprodan/charts@" + imgs["6.1.6"].digest.String(),
28992900
},
29002901
{
2901-
name: "valid url with semver reference",
2902+
name: "valid url with semver reference and build identifier",
29022903
url: fmt.Sprintf("oci://%s/podinfo", server.registryHost),
29032904
reference: &sourcev1.OCIRepositoryRef{
29042905
SemVer: ">= 6.1.6",
29052906
},
2906-
want: server.registryHost + "/podinfo:6.1.6",
2907+
want: server.registryHost + "/podinfo:6.1.7_ref.1234567",
29072908
},
29082909
{
29092910
name: "invalid url without oci prefix",
Binary file not shown.

0 commit comments

Comments
 (0)