Skip to content

fix: skip --reuse-values for a release that is not installed (#481) - #1086

Merged
yxxhero merged 2 commits into
databus23:masterfrom
rishabhvenu:fix/reuse-values-unreleased
Oct 8, 2026
Merged

yxxhero merged 2 commits into
databus23:masterfrom
rishabhvenu:fix/reuse-values-unreleased

Conversation

@rishabhvenu

@rishabhvenu rishabhvenu commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

helm diff upgrade --install --reuse-values fails with Error: Failed to render chart: exit status 1 when the release does not exist yet. The same happens with --allow-unreleased and with --reset-then-reuse-values. helm upgrade --install --reuse-values works in that situation.

Cause: template() in cmd/helm.go runs helm get values whenever one of the two flags is set. Only the implicit reuse of values (no --set/--values given) has been limited to upgrades since a25763a. For a new install there is no release, so helm get values exits with release: not found and the render is aborted.

Fix: only fetch the existing values when the release exists. For a new install the two flags are ignored, which is what helm upgrade --install does. Nothing changes for a release that exists.

Tests:

  • TestUpgradeCommand_Execution_ReuseValues runs the upgrade command against the fake helm. A new unreleased fake helm mode makes every helm get fail with release: not found. Six cases for a missing release fail on master with the error from the issue and pass with this change. They also check that helm get values is not called. Four cases for an existing release check that it still is.
  • I ran the built binary with Helm v3.17.3 and v4.3.0 against a local kube-apiserver and etcd (no kubelet) with a ConfigMap-only chart. On master, --install or --allow-unreleased with --reuse-values or --reset-then-reuse-values fails, also together with --dry-run=server, --three-way-merge and HELM_DIFF_USE_UPGRADE_DRY_RUN=true. With this change each of them prints the manifest as added. For an installed release, --reuse-values --set other=changed gives the same diff before and after, with the previously set value kept.
  • make format, make lint, make test and make verify-readme pass, and golangci-lint v2.14.0 reports 0 issues.

Not tested: a kind cluster, so the CI integration job has not been run locally. I did not add a scripts/issues/481.sh; I can add one if you want it.

Two things this does not change or changes on purpose:

  • With Helm older than v3.14, --reset-then-reuse-values on a release that does not exist no longer returns the "requires at least helm version 3.14.0" error, because the flag is now ignored for a new install.
  • The issue also suggests passing --reuse-values through to helm upgrade when HELM_DIFF_USE_UPGRADE_DRY_RUN is set. That is not part of this PR. In that mode the values of an existing release are still read with helm get values, as before.

Fixes #481

rishabhvenu and others added 2 commits October 7, 2026 20:50
…23#481)

With --install/--allow-unreleased and an explicit --reuse-values or
--reset-then-reuse-values, helm-diff still ran `helm get values` for a
release that does not exist and failed with "Failed to render chart:
exit status 1". Only the implicit reuse of values was limited to
upgrades.

`helm upgrade --install` ignores both flags when it installs, so do the
same and only fetch the existing values when the release exists.
The new condition in template() moved isUpgrade out of
shouldDefaultReusingValues, but no case exercised the two boundaries
of that rewrite:

- an existing release without any --set/--values flags still fetches
  the release values (helm enables --reuse-values by default), and
- a new install without any value flags must not fetch them.

Add both cases to TestUpgradeCommand_Execution_ReuseValues.

Signed-off-by: yxxhero <aiopsclub@163.com>

@yxxhero yxxhero left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the change in depth against all call paths of template() — the fix is correct. Summary of the review, plus one small commit added on top.

Why it's correct

  • template(isUpgrade) is called only from runHelm3() as d.template(!newInstall), and newInstall becomes true only after helm get manifest fails with release: not found while --allow-unreleased/--install is set. So gating the whole reuse block on isUpgrade means exactly "the release exists", which mirrors what helm upgrade --install does (ignore reuse flags for a new install).
  • For an existing release (isUpgrade == true) the new condition is equivalent to the old one, so behavior there is unchanged.
  • --dry-run=client/--dry-run=true paths remain safe: clusterAccessAllowed() is false there, so the block was already skipped.
  • --revision > 0 on a missing release still errors out before template(), unchanged.
  • The unreleased fake-helm mode fails helm get with Error: release: not found, which is what outputWithRichError surfaces and runHelm3 matches on — consistent with real helm. The only other get consumer (getChart in release.go) is not part of the upgrade flow.
  • The dropped --reset-then-reuse-values version error for a missing release (helm < 3.14) is fine: the flag is ignored for a new install, so erroring about it would be inconsistent.

Commit added on top (08f8526): the rewrite moved isUpgrade out of shouldDefaultReusingValues, but no case exercised the two boundaries of that exact condition:

  • existing release without any value flags → implicit default reuse must still fetch helm get values --all (guards shouldDefaultReusingValues against being dropped from the condition);
  • new install without any value flags (bare --install, the most common new-release invocation) → must not fetch values.

Both cases are in TestUpgradeCommand_Execution_ReuseValues now. PR description case counts updated accordingly.

@yxxhero
yxxhero merged commit ba5a4e9 into databus23:master Oct 8, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

helm diff should not error with --reuse-values if release doesn't exist

2 participants