fix(repo/v1): suppress fallback warning when no version is specified

pull/31598/head
maryamsul 10 months ago
parent ff35414bed
commit 16523e7d2f

@ -200,29 +200,39 @@ func (i IndexFile) Get(name, version string) (*ChartVersion, error) {
} }
// when customer inputs specific version, check whether there's an exact match first // when customer inputs specific version, check whether there's an exact match first
if len(version) != 0 { // Check exact match first
for _, ver := range vs { if version != "" {
if version == ver.Version { for _, ver := range vs {
return ver, nil if version == ver.Version {
} return ver, nil
} }
} }
}
for _, ver := range vs {
test, err := semver.NewVersion(ver.Version)
if err != nil {
continue
}
if constraint.Check(test) { // Find closest match
slog.Warn("unable to find exact version; falling back to closest available version", "chart", name, "requested", version, "selected", ver.Version) for _, ver := range vs {
return ver, nil test, err := semver.NewVersion(ver.Version)
} if err != nil {
} continue
return nil, fmt.Errorf("no chart version found for %s-%s", name, version) }
if constraint.Check(test) {
// Only warn if a specific version was requested
if version != "" {
slog.Warn(
"unable to find exact version; falling back to closest available version",
"chart", name,
"requested", version,
"selected", ver.Version)
}
return ver, nil
}
} }
// WriteFile writes an index file to the given destination path. // No match found at all
return nil, fmt.Errorf("no chart version found for %s-%s", name, version)
}
//ile writes an index file to the given destination path.
// //
// The mode on the file is set to 'mode'. // The mode on the file is set to 'mode'.
func (i IndexFile) WriteFile(dest string, mode os.FileMode) error { func (i IndexFile) WriteFile(dest string, mode os.FileMode) error {

Loading…
Cancel
Save