fix: ensure OCI charts are prepared for needed releases with --include-needs (#2663)

fix: ensure OCI charts are prepared for needed releases with --include-needs (#923)

When using --include-needs with a selector, releases included via needs
must have their charts prepared (pulled/exported) before diff/sync/apply
can process them. The core fix (ChartPrepareOptions.IncludeTransitiveNeeds
= c.IncludeNeeds()) was already in place, but ForEachState calls in
Diff/Template/Lint/Unittest/Sync/Apply still passed c.IncludeTransitiveNeeds()
instead of c.IncludeNeeds(), creating an inconsistency that would resurface
if SetFilter(true) were ever added.

Changes:
- Use c.IncludeNeeds() in ForEachState for all commands supporting
  --include-needs (Diff, Template, Lint, Unittest, Sync, Apply, Doctor)
- Doctor is the only command with SetFilter(true), so this fixes a real
  bug: helmfile doctor --include-needs was silently ignored for filtering
- Add explanatory doc comment on ForEachState parameter semantics
- Enhance exectest.Helm.ChartPull to create minimal chart files and track
  pulls, enabling OCI chart testing
- Add resetChartCacheForTest() for test isolation from global chart cache
- Add regression tests for issue #923

Signed-off-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2026-06-25 14:36:50 +08:00
committed by GitHub
parent 09587dd53d
commit 08d70bc9a7
5 changed files with 235 additions and 9 deletions
+14 -6
View File
@@ -208,7 +208,7 @@ func (a *App) Diff(c DiffConfigProvider) error {
}
return matched, criticalErrs
}, c.IncludeTransitiveNeeds())
}, c.IncludeNeeds())
if err != nil {
return err
@@ -264,7 +264,7 @@ func (a *App) Template(c TemplateConfigProvider) error {
}
return
}, c.IncludeTransitiveNeeds())
}, c.IncludeNeeds())
}
func (a *App) WriteValues(c WriteValuesConfigProvider) error {
@@ -343,7 +343,7 @@ func (a *App) Lint(c LintConfigProvider) error {
}
return
}, c.IncludeTransitiveNeeds())
}, c.IncludeNeeds())
if err != nil {
return err
@@ -385,7 +385,7 @@ func (a *App) Unittest(c UnittestConfigProvider) error {
}
return
}, c.IncludeTransitiveNeeds())
}, c.IncludeNeeds())
if err != nil {
return err
@@ -526,7 +526,7 @@ func (a *App) Sync(c SyncConfigProvider) error {
}
return
}, c.IncludeTransitiveNeeds())
}, c.IncludeNeeds())
if err != nil {
return err
@@ -582,7 +582,7 @@ func (a *App) Apply(c ApplyConfigProvider) error {
}
return
}, c.IncludeTransitiveNeeds(), opts...)
}, c.IncludeNeeds(), opts...)
if err != nil {
return err
@@ -1356,6 +1356,14 @@ var (
}
)
// ForEachState iterates over each loaded state file and invokes do.
//
// includeTransitiveNeeds controls whether releases reachable via "needs" are
// un-filtered when SetFilter(true) is used. Despite the name, passing true
// unmarks ALL needs (both direct and transitive) via collectNeedsWithTransitives.
// Callers that support --include-needs should pass c.IncludeNeeds() (which is
// true for both --include-needs and --include-transitive-needs) so that chart
// preparation and early filtering stay consistent. See issue #923.
func (a *App) ForEachState(do func(*Run) (bool, []error), includeTransitiveNeeds bool, o ...LoadOption) error {
ctx := NewContext()
err := a.visitStatesWithSelectorsAndRemoteSupportWithContext(a.FileOrDir, func(st *state.HelmState) (bool, []error) {
+1 -1
View File
@@ -196,7 +196,7 @@ func (a *App) peekDoctorContext(c DoctorConfigProvider) (llm.Config, []string, e
}
}
return false, nil
}, c.IncludeTransitiveNeeds(), SetFilter(true))
}, c.IncludeNeeds(), SetFilter(true))
return yamlLLM, releases, err
}