You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Handle OCI artifact versions with '+' correctly
This change addresses an issue where Helm's automatic replacement of '+'
with '_' in version strings causes problems with OCI artifact registries
that do not support '+' in tags.
The following improvements have been made:
- Modified `internal/helper/helper.go`:
- Added comprehensive documentation to the `SemVerReplace` function.
- Clarified that `SemVerReplace` focuses on underscore-to-plus
conversion and does not perform full semver validation.
- Simplified the `SemVerReplace` function logic.
- Added extensive unit tests for `SemVerReplace` covering various
scenarios, including empty strings, multiple underscores,
leading/trailing underscores, and mixed-case strings.
- Updated `internal/manifest/charts.go`:
- Added debug logging before attempting underscore-to-plus conversion
for chart versions.
- Enhanced error messages to be more specific when a chart version is
not found, indicating that lookups were attempted with both the
original reference and the converted reference.
- Updated `internal/manifest/manifest.go`:
- Ensured consistent handling of underscore-to-plus conversion for
manifest targets in both GET and HEAD request methods.
- Added debug logging before attempting underscore-to-plus conversion
for manifest targets in both GET and HEAD methods.
- Enhanced error messages to be more specific when a manifest is not
found, indicating that lookups were attempted with both the
original target and the converted target.
These changes ensure that versions containing '+' are correctly processed
by first attempting the lookup with the original reference (which might
contain '_') and then, if that fails, by attempting the lookup again
after converting underscores to plus signs. This provides more robust
handling for OCI artifacts and improves debuggability.
m.log.Printf("searching index for %s with reference %s\n", chart, reference)
48
49
chartVer, err:=index.Get(chart, reference)
49
50
iferr!=nil {
51
+
originalReference:=reference// Store Original Reference
52
+
ifm.config.Debug {
53
+
m.log.Printf("Chart lookup for '%s' with reference '%s' failed. Attempting again after converting underscores to plus signs in reference.", chart, originalReference)
54
+
}
55
+
reference=helper.SemVerReplace(originalReference) // Use originalReference for conversion
Message: fmt.Sprintf("Chart: %s version: %s not found. Attempted lookup with original reference and after converting underscores to plus signs. Last error: %v", chart, originalReference, err),
Message: fmt.Sprintf("Chart prepare's result not found: %v, %v", repo, target),
163
+
originalTarget:=target// Store original target
164
+
ifm.config.Debug {
165
+
m.log.Printf("GET: Chart lookup failed for repo %s with target %s after prepareChart. Attempting again after converting underscores to plus signs.", repo, originalTarget)
166
+
}
167
+
target=helper.SemVerReplace(originalTarget) // Use originalTarget for conversion
168
+
ma, ok=c[target] // Attempt lookup with the new target
169
+
if!ok {
170
+
// we failed again
171
+
return&errors.RegError{
172
+
Status: http.StatusNotFound,
173
+
Code: "NOT FOUND",
174
+
Message: fmt.Sprintf("GET: Chart prepare's result not found for repo %s. Tried target '%s' and after underscore conversion '%s'.", repo, originalTarget, target),
// First lookup failed, try preparing chart (which might involve its own SemVerReplace)
195
204
err:=m.prepareChart(req.Context(), repo, target)
196
205
iferr!=nil {
197
-
returnerr
206
+
returnerr// Error from prepareChart
198
207
}
208
+
// After prepareChart, try lookup again with the potentially modified target from prepareChart
209
+
// and then with SemVerReplace if that also fails.
199
210
ma, ok= m.manifests[repo][target]
200
211
if!ok {
201
-
// we failed
202
-
return&errors.RegError{
203
-
Status: http.StatusNotFound,
204
-
Code: "NOT FOUND",
205
-
Message: "Chart prepare error",
212
+
originalTarget:=target// Store target before SemVerReplace
213
+
ifm.config.Debug {
214
+
m.log.Printf("HEAD: Manifest not found for repo %s with target %s even after prepareChart. Attempting again after converting underscores to plus signs.", repo, originalTarget)
ma, ok= m.manifests[repo][target] // Final attempt
218
+
if!ok {
219
+
// All attempts failed
220
+
return&errors.RegError{
221
+
Status: http.StatusNotFound,
222
+
Code: "NOT FOUND",
223
+
Message: fmt.Sprintf("HEAD: Chart manifest not found for repo %s. Tried target '%s' and after underscore conversion '%s'.", repo, originalTarget, target),
0 commit comments