fix: prevent warning when using version range constraints#31758
Conversation
|
|
||
| if constraint.Check(test) { | ||
| if len(version) != 0 { | ||
| if len(version) != 0 && !isVersionRange(version) { |
There was a problem hiding this comment.
Can we also add a debug logging here when we use constraints and not exact version to see which version we got as closest which satisfy our requirement in --version?
Otherwise, we only see original (log before fix):
level=DEBUG msg="original chart version" version=1.9.1
level=DEBUG msg="set up default downloader cache"
level=WARN msg="unable to find exact version requested; falling back to closest available version" chart=cert-manager requested=1.9.1 selected=v1.9.1
level=DEBUG msg="found chart in cache" id=46273177b5ca6930af8047cd52bf0b784c8482ac042e7812d08643c2898692d5It will show the version we got for helm show but I'm not sure about all commands :)
Just as an idea.
There was a problem hiding this comment.
I thought about this too as I think it is still interesting to know which version is selected when you specify a version range. I added the feature in 7749ebf. Thanks for the good idea.
|
We should be good. |
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #31757 where Helm incorrectly showed warnings when using version range constraints like ^1 or ~1.10. The fix distinguishes between exact version requests and version range constraints, showing warnings only for exact versions that aren't found while logging version range selections at debug level.
Changes:
- Added
isVersionRange()helper function to detect version range syntax - Modified logging behavior in
IndexFile.Get()to use appropriate log levels - Added comprehensive test coverage for version range detection
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/repo/v1/index.go | Implemented version range detection and conditional logging logic |
| pkg/repo/v1/index_test.go | Added unit tests for the isVersionRange() function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When using version ranges like ^1 or ~1.10, Helm incorrectly showed warnings about falling back to closest version. Only show the warning when an exact version is requested but not found. Fixes: helm#31757 Signed-off-by: Benoit Tigeot <[email protected]>
Signed-off-by: Benoit Tigeot <[email protected]>
From Matt's comment > The check for " || " should remove the spaces and have "||". Spaces around the || aren't required. Signed-off-by: Benoit Tigeot <[email protected]>
`isVersionRange` checked for `x`/`X` across the entire version string, misclassifying exact versions like `1.0.0-fix`, `2.0.0-next`, or `1.0.0+exp` as ranges. Signed-off-by: Benoit Tigeot <[email protected]>
|
Sorry @TerryHowe forgot about this PR. Legit feedback from copilot. Fixed in last commit. |
|
@mattfarina I think we should merge this to avoid unecessary noise. |
|
|
||
| // isVersionRange checks if the version string is a range constraint (e.g., "^1", "~1.10") | ||
| // rather than an exact version (e.g., "1.10.0"). | ||
| func isVersionRange(version string) bool { |
There was a problem hiding this comment.
It would be better to be able to get the constraint operations from semver.Constraint type, IMHO. Rather than trying to duplicate the parsing here.
But given this is simply for logging (though it is possible this could change in the future), this is fine I think.
What this PR does / why we need it:
When using version ranges like
^1or~1.10, Helm incorrectly showed warnings about falling back to closest version 😬. Only show the warning when an exact version is requested but not found and move to debug for version range.Fixes: #31757
Special notes for your reviewer:
I've also tested via the CLI that all unit test value are working properly. For example:
Also other scenarios like
If applicable:
docs neededlabel should be applied if so)