helmfile/pkg/app
yxxhero 5368ab8d95
fix: skip subhelmfiles when selectors conflict with CLI selectors (#2545)
* fix: skip subhelmfiles when selectors conflict with CLI selectors (#2544)

When CLI selectors are provided (e.g. -l name=b), subhelmfiles whose
explicit selectors are provably incompatible are now skipped entirely,
avoiding unnecessary YAML loading and template rendering.

Two selector sets are incompatible when every pair has a positive label
conflict: same key with different values (e.g. name=b vs name=a).
Negative labels are not compared.

Fixes #2544

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

* fix: address PR review comments - use CLI selectors, fix doc comment, add malformed selector test

Agent-Logs-Url: https://github.com/helmfile/helmfile/sessions/1f1c33ce-e50d-4781-85b8-d606b5d4ca54

Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>

* fix: add debug logging, unit tests, docs, and fix integration test for subhelmfile selector skip

- Add debug log when skipping subhelmfile due to selector conflict
- Add TestSubhelmfileSelectorsConflict with 11 cases for direct unit coverage
- Document the selector-based subhelmfile skip optimization in docs/index.md
- Fix integration test: use 'app' label key instead of reserved 'name' key
  (GetReleasesWithLabels overwrites labels["name"] with the release name)

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

* refactor: avoid map allocation in positiveLabelsCompatibleWith

Compare positive label slices directly instead of allocating a map per
comparison, as label counts are typically small (1-3 entries).

Addresses Copilot review comment on PR #2545.

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

* docs: clarify subhelmfile selector docs per Copilot review feedback

Reword the first two bullets to avoid the contradiction between
'CLI selectors are ignored' and the new skip optimization.

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

* fix: address Copilot review comments round 3

- Log parse errors from SelectorsAreCompatible at debug level instead of
  silently discarding them
- Hoist regex compilation to package-level vars in ParseLabels to avoid
  repeated compilation per selector
- Replace EXIT traps with explicit cleanup calls in integration test to
  avoid interfering with the parent runner's trap

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

---------

Signed-off-by: yxxhero <aiopsclub@163.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-04-25 17:18:39 +08:00
..
testdata fix: pass --timeout flag through to helm for sync and apply (#2495) 2026-03-22 07:34:33 +08:00
version feat: optimize version output (#412) 2022-10-08 14:26:15 +09:00
app.go fix: skip subhelmfiles when selectors conflict with CLI selectors (#2545) 2026-04-25 17:18:39 +08:00
app_apply_hooks_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
app_apply_nokubectx_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
app_apply_test.go fix: pass --timeout flag through to helm for sync and apply (#2495) 2026-03-22 07:34:33 +08:00
app_diff_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
app_gethelm_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
app_lint_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
app_list_test.go fix: helmfile list now reflects version from helmfile.lock (#2486) 2026-03-19 14:25:03 +08:00
app_parallel_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
app_sequential_test.go fix: use absolute baseDir in sequential helmfiles for correct values path resolution (#2425) 2026-02-26 07:47:39 +08:00
app_sync_test.go fix: pass --timeout flag through to helm for sync and apply (#2495) 2026-03-22 07:34:33 +08:00
app_template_test.go fix: pass --kube-context to helm template when using jsonPatches (#2363) 2026-01-16 20:32:33 +08:00
app_test.go fix: skip subhelmfiles when selectors conflict with CLI selectors (#2545) 2026-04-25 17:18:39 +08:00
app_unittest_test.go feat: add `helmfile unittest` command for helm-unittest integration (#2400) 2026-02-16 09:45:10 +08:00
ask.go build(deps): bump golangci/golangci-lint-action from 6 to 7 (#1975) 2025-03-28 07:52:06 +08:00
cleanup_hooks_error_test.go fix: cleanup hooks not receiving error signal (#2475) 2026-03-21 14:29:32 +08:00
config.go feat: add an arg that passing description to `helm upgrade` command (#2497) 2026-03-24 21:01:44 +08:00
constants.go Remove all v0.x references (#1919) 2025-03-08 07:43:21 -06:00
constants_test.go fix lint error 2022-08-13 07:40:32 +08:00
context.go perf(app): Parallelize helmfile.d rendering and eliminate chdir race conditions (#2261) 2025-11-15 16:19:41 +08:00
context_test.go perf(app): Parallelize helmfile.d rendering and eliminate chdir race conditions (#2261) 2025-11-15 16:19:41 +08:00
dag_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
desired_state_file_loader.go fix: helmDefaults.postRendererArgs not passed to helm commands (#2510) 2026-04-16 11:08:15 +08:00
destroy_nokubectx_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
destroy_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
diff_nokubectx_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
diff_test.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
errors.go feat: Opt-out dep-builds and repo-updates (#463) 2019-02-04 12:07:25 +09:00
errors_test.go add unittest for error.go in pkg/app 2022-04-28 09:01:02 +08:00
formatters.go 🐛 Fix four critical issues: environment merging, kubeVersion detection, lookup() with kustomize, and Helm 4 color flags (#2276) 2025-11-21 08:32:54 +08:00
formatters_test.go cleanup: remove panic in testutil (#890) 2023-06-13 13:44:32 +08:00
init.go Fix helmfile init failing to update outdated helm plugins with Helm v4 (#2554) 2026-04-25 11:04:23 +08:00
init_test.go Fix helmfile init failing to update outdated helm plugins with Helm v4 (#2554) 2026-04-25 11:04:23 +08:00
load_opts.go fix: update state values files handling to replace arrays instead of merging (#2537) 2026-04-13 19:46:15 +08:00
load_opts_test.go fix: update state values files handling to replace arrays instead of merging (#2537) 2026-04-13 19:46:15 +08:00
print_env.go feat: add print-env command (#2279) 2025-11-28 08:46:37 +08:00
print_env_test.go feat: add print-env command (#2279) 2025-11-28 08:46:37 +08:00
run.go fix: cleanup hooks not receiving error signal (#2475) 2026-03-21 14:29:32 +08:00
snapshot_test.go Use log capturing helper in TestApply_hooks 2022-11-13 08:20:13 +00:00
two_pass_renderer.go build(deps): bump golangci/golangci-lint-action from 6 to 7 (#1975) 2025-03-28 07:52:06 +08:00
two_pass_renderer_test.go Remove all v0.x references (#1919) 2025-03-08 07:43:21 -06:00
validate_config.go add Go lint 2022-07-16 20:21:11 +08:00
validate_config_test.go add unittest for ValidateConfig 2022-04-27 07:38:22 +08:00