Skip to content

fix: prevent warning when using version range constraints#31758

Merged
gjenkins8 merged 4 commits into
helm:mainfrom
benoittgt:fix-31757
Jun 9, 2026
Merged

fix: prevent warning when using version range constraints#31758
gjenkins8 merged 4 commits into
helm:mainfrom
benoittgt:fix-31757

Conversation

@benoittgt

@benoittgt benoittgt commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

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 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:

bin/helm show chart brigade/brigade --version '^1.8.0 || ^1.9.0' | grep -E '(level=|^version:)'
version: 1.10.0

Also other scenarios like

❯ bin/helm show chart jetstack/cert-manager --version 'v1' | head -1
level=WARN msg="unable to find exact version requested; falling back to closest available version" chart=cert-manager requested=v1 selected=v1.19.2
annotations:

❯ bin/helm show chart jetstack/cert-manager --version 'v1.x' | head -1
annotations:

❯ bin/helm show chart jetstack/cert-manager --version 'v1.x' --debug | head -1
level=DEBUG msg="original chart version" version=v1.x
level=DEBUG msg="set up default downloader cache"
level=DEBUG msg="selected version matching constraint" chart=cert-manager constraint=v1.x selected=v1.19.2
level=DEBUG msg="found chart in cache" id=87e2dafa946bd05c56be897b2fe2e171f2bbfad96c9d48409d4b1188d240af6f
annotations:

❯ bin/helm show chart jetstack/cert-manager --version '^v1' | head -1
annotations:

❯ bin/helm show chart brigade/brigade --version '^1' --debug | grep -E '(level=DEBUG.*selected version)'           
level=DEBUG msg="selected version matching constraint" chart=brigade constraint=^1 selected=1.10.0

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 23, 2026
@benoittgt benoittgt changed the title fix: fix: prevent warning when using version range constraints fix: prevent warning when using version range constraints Jan 23, 2026
@benoittgt
benoittgt marked this pull request as ready for review January 23, 2026 14:32
Comment thread pkg/repo/v1/index.go

if constraint.Check(test) {
if len(version) != 0 {
if len(version) != 0 && !isVersionRange(version) {

@Noksa Noksa Jan 23, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=46273177b5ca6930af8047cd52bf0b784c8482ac042e7812d08643c2898692d5

It will show the version we got for helm show but I'm not sure about all commands :)

Just as an idea.

@benoittgt benoittgt Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/repo/v1/index.go Outdated
@benoittgt
benoittgt requested a review from mattfarina February 4, 2026 21:17
@benoittgt

Copy link
Copy Markdown
Contributor Author

We should be good.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/repo/v1/index_test.go
Comment thread pkg/repo/v1/index.go Outdated
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]>
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]>
@benoittgt

Copy link
Copy Markdown
Contributor Author

Sorry @TerryHowe forgot about this PR. Legit feedback from copilot. Fixed in last commit.

@benoittgt

Copy link
Copy Markdown
Contributor Author

@mattfarina I think we should merge this to avoid unecessary noise.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@TerryHowe TerryHowe added the Has One Approval This PR has one approval. It still needs a second approval to be merged. label May 23, 2026
Comment thread pkg/repo/v1/index.go

// 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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gjenkins8
gjenkins8 merged commit e5efe06 into helm:main Jun 9, 2026
5 checks passed
@scottrigby scottrigby added needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. bug Categorizes issue or PR as related to a bug. labels Jun 12, 2026
@scottrigby scottrigby added this to the 4.2.1 milestone Jun 12, 2026
@scottrigby scottrigby added picked Indicates that a PR has been cherry-picked into the next release candidate. and removed needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. Has One Approval This PR has one approval. It still needs a second approval to be merged. labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. picked Indicates that a PR has been cherry-picked into the next release candidate. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helm 4: Emits "unable to find exact version" when a version range was specified

7 participants