helmfile/pkg/helmexec
yxxhero b17c5be9cf Fix 2337 helm4 stale repo indexes (#2369)
* fix: add --force-update flag for Helm 4 to prevent stale repository indexes

Fixes #2337

Problem:
Helmfile with Helm v4 doesn't update repository indexes when adding repos,
leading to stale indexes and errors like:
  "chart matching version not found in example index. (try 'helm repo update')"

This happens because Helm 4 changed behavior compared to Helm 3:
- Helm 3: Always downloads index when running "helm repo add", even if repo exists
- Helm 4: Skips downloading index if repo already exists with same config
  (see: https://github.com/helm/helm/blob/v4.0.4/pkg/cmd/repo_add.go#L200)

Without --force-update, helmfile only works initially because Helm 4
downloads index on fresh repo setup, but subsequent "helmfile repos"
commands result in stale indexes.

Root Cause:
The code only added --force-update for Helm 3.3.2+, but not for Helm 4,
since it was believed to be default behavior in Helm 4. However, Helm 4
requires explicit --force-update flag to update indexes for existing repos.

Solution:
Add --force-update flag for Helm 4 in AddRepo function to ensure
repository indexes are updated even when repository already exists.

Refactoring:
Simplified the conditional logic from nested if statements to a single
readable condition using existing IsVersionAtLeast() helper:
  if !helm.options.DisableForceUpdate &&
     (helm.IsHelm4() || helm.IsVersionAtLeast("3.3.2")) {
    args = append(args, "--force-update")
  }

Changes:
- pkg/helmexec/exec.go: Add --force-update for Helm 4
- pkg/helmexec/exec_test.go: Update test expectations for both Helm 3.3.2+ and Helm 4
- AGENTS.md: Add development guide for the repository

Testing:
- All helmexec package tests pass
- Verified build succeeds
- Tested against Helm 3.2.0 (no force-update)
- Tested against Helm 3.3.2+ (with force-update)
- Tested against Helm 4.0.1 (with force-update)

Signed-off-by: opencode <opencode@users.noreply.github.com>
Signed-off-by: yxxhero <aiopsclub@163.com>

* test: update expected output for Helm 4 repo add message

Update integration test expectations to match Helm 4 behavior with --force-update flag.
When --force-update is used, Helm 4 now outputs "has been added to your
repositories" instead of "already exists with the same configuration, skipping",
because it forcibly updates the repository index.

Related to #2337

Signed-off-by: opencode <opencode@users.noreply.github.com>
Signed-off-by: yxxhero <aiopsclub@163.com>

---------

Signed-off-by: opencode <opencode@users.noreply.github.com>
Signed-off-by: yxxhero <aiopsclub@163.com>
2026-01-25 18:15:20 +08:00
..
testdata fix: support large output with --enable-live-ouput (#1139) 2023-11-12 06:45:08 +08:00
context.go Drop Helm v2 support (#613) 2023-01-17 09:24:47 +09:00
exec.go Fix 2337 helm4 stale repo indexes (#2369) 2026-01-25 18:15:20 +08:00
exec_flag_filtering_test.go feat: add Helm 4 support while maintaining Helm 3 compatibility (#2262) 2025-11-19 07:49:30 +08:00
exec_test.go Fix 2337 helm4 stale repo indexes (#2369) 2026-01-25 18:15:20 +08:00
exit_error.go Feat: add --strip-args-values-on-exit-error (#887) 2023-06-07 14:39:38 +08:00
exit_error_test.go Feat: add --strip-args-values-on-exit-error (#887) 2023-06-07 14:39:38 +08:00
helmexec.go feat: add Helm 4 support while maintaining Helm 3 compatibility (#2262) 2025-11-19 07:49:30 +08:00
id.go Print command output in line (#1354) 2020-08-29 14:47:22 +09:00
id_test.go Add unittest for newExecutionID 2022-04-24 13:55:28 +08:00
log.go Fix snapshot tests to pass regardless of helm version (#572) 2022-12-10 10:54:03 +08:00
runner.go Fix panic when helm isn't installed (#2169) 2025-09-09 07:15:46 +08:00
runner_test.go fix: support large output with --enable-live-ouput (#1139) 2023-11-12 06:45:08 +08:00