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
+13 -2
View File
@@ -6,6 +6,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
@@ -33,7 +34,8 @@ type DiffKey struct {
type Helm struct {
Charts []string
Repo []string
RegistryLoginHost string // Captures the host passed to RegistryLogin
RegistryLoginHost string // Captures the host passed to RegistryLogin
PulledCharts []string // Captures the OCI chart refs passed to ChartPull
Releases []Release
Deleted []Release
Linted []Release
@@ -233,7 +235,16 @@ func (helm *Helm) TemplateRelease(name, chart string, flags ...string) error {
return nil
}
func (helm *Helm) ChartPull(chart string, path string, flags ...string) error {
return nil
helm.sync(helm.ChartsMutex, func() {
helm.PulledCharts = append(helm.PulledCharts, chart)
})
// Create a minimal chart structure so getOCIChart's findChartDirectory succeeds
chartDir := filepath.Join(path, "chart")
if err := os.MkdirAll(chartDir, 0755); err != nil {
return err
}
chartYaml := "apiVersion: v2\nname: test-chart\ndescription: A test chart\ntype: application\nversion: 0.1.0\nappVersion: \"1.0.0\"\n"
return os.WriteFile(filepath.Join(chartDir, "Chart.yaml"), []byte(chartYaml), 0644)
}
func (helm *Helm) ChartExport(chart string, path string) error {
return nil