-
Notifications
You must be signed in to change notification settings - Fork 234
Support Helm semver encoding in OCI repositories #1834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -898,7 +898,11 @@ func (r *OCIRepositoryReconciler) getTagBySemver(repo name.Repository, exp strin | |
|
|
||
| var matchingVersions []*semver.Version | ||
| for _, t := range validTags { | ||
| v, err := version.ParseVersion(t) | ||
| // Helm translates `+` to `_` in OCI tags, because `+` is not a valid tag character. | ||
| versionStr := strings.Replace(t, "_", "+", 1) | ||
| // It would be even better to use `org.opencontainers.image.version` annotation | ||
| // if present, but that adds a fetch for each tag. | ||
| v, err := version.ParseVersion(versionStr) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OCIRepository is not specific to Helm in any way, we are going to break versions that contain
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm willing to do that; another option is to do this only if
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly, in the tests I didn't need to actually set the media type on the podinfo images for the test to pass. |
||
| if err != nil { | ||
| continue | ||
| } | ||
|
|
@@ -913,7 +917,8 @@ func (r *OCIRepositoryReconciler) getTagBySemver(repo name.Repository, exp strin | |
| } | ||
|
|
||
| sort.Sort(sort.Reverse(semver.Collection(matchingVersions))) | ||
| return repo.Tag(matchingVersions[0].Original()), nil | ||
| asTag := strings.Replace(matchingVersions[0].Original(), "+", "_", 1) | ||
| return repo.Tag(asTag), nil | ||
| } | ||
|
|
||
| // keychain generates the credential keychain based on the resource | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2866,6 +2866,7 @@ func TestOCIRepository_getArtifactRef(t *testing.T) { | |
| "6.1.5", | ||
| "6.1.6-rc.1", | ||
| "6.1.6", | ||
| "6.1.7_ref.1234567", // Version 6.1.7+ref.1234567, encoded as a tag | ||
| ) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
|
|
@@ -2898,12 +2899,12 @@ func TestOCIRepository_getArtifactRef(t *testing.T) { | |
| want: "ghcr.io/stefanprodan/charts@" + imgs["6.1.6"].digest.String(), | ||
| }, | ||
| { | ||
| name: "valid url with semver reference", | ||
| name: "valid url with semver reference and build identifier", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a new test case for the build identifier. For the existing semver test case, set
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need a test to prove that ordering will be random and not what people expect, because Git commit SHAs are not numeric. Having the same version and two build tags, will not give you the "latest" one. |
||
| url: fmt.Sprintf("oci://%s/podinfo", server.registryHost), | ||
| reference: &sourcev1.OCIRepositoryRef{ | ||
| SemVer: ">= 6.1.6", | ||
| }, | ||
| want: server.registryHost + "/podinfo:6.1.6", | ||
| want: server.registryHost + "/podinfo:6.1.7_ref.1234567", | ||
| }, | ||
| { | ||
| name: "invalid url without oci prefix", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this comment please, we never considered fetching artifacts to determine the version.