fix: prevent duplicate isReleaseInstalled checks in DetectReleasesToBeDeletedForSync

When a release with 'installed: false' appears multiple times in the release list
(due to duplicate entries or being included via needs), the isReleaseInstalled
function was being called multiple times for the same release, resulting in
duplicate 'Listing releases' log messages.

This fix adds a deduplication check using a 'checked' map to ensure each release
is only checked once, preventing duplicate helm list calls and log messages.

This fixes the diff-args integration test where 'Listing releases matching
^uninstalled$' appeared twice in stderr output.

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2026-03-17 07:39:16 +08:00
parent 37e9ce4654
commit 7a7bdf5dc3
2 changed files with 9 additions and 2 deletions

View File

@ -850,10 +850,18 @@ func (st *HelmState) isReleaseInstalled(context helmexec.HelmContext, helm helme
func (st *HelmState) DetectReleasesToBeDeletedForSync(helm helmexec.Interface, releases []ReleaseSpec) ([]ReleaseSpec, error) {
deleted := []ReleaseSpec{}
checked := make(map[string]bool)
for i := range releases {
release := releases[i]
if !release.Desired() {
id := ReleaseToID(&release)
if checked[id] {
continue
}
checked[id] = true
installed, err := st.isReleaseInstalled(st.createHelmContext(&release, 0), helm, release)
if err != nil {
return nil, err

View File

@ -1,4 +1,3 @@
Live output is enabled
Building dependency release=installed, chart=../../../charts/httpbin
Listing releases matching ^uninstalled$
Listing releases matching ^uninstalled$
Listing releases matching ^uninstalled$