helmfile: helmfile template --selector not works in some cases

Hi,

I use helmfile template to the same release and filter by labels to output different manifests within the same release. However, --selector not filter the target release on master.

Here is the sample command and helmfile.yaml to reproduce this.

helmfile --selector index=1 template --output-dir "./out" 

# I also tried
helmfile --selector index=1 template --include-needs=[false|true] --output-dir "./out" 
releases:
  - name: foo
    chart: incubator/raw
    namespace: default
    labels:
      app: test
      component: raw
      index: '1'
    values:
      - resources:
          - value: 1

  - name: foo
    chart: incubator/raw
    namespace: default
    labels:
      app: test
      component: raw
      index: '2'
    values:
      - resources:
          - value: 2

expected output is this:

---
# Source: raw/templates/resources.yaml
metadata:
  labels:
    app: raw
    chart: raw-0.2.5
    heritage: Helm
    release: foo
value: 1 # same as --selector index=1

however, actual output is this:

---
# Source: raw/templates/resources.yaml
metadata:
  labels:
    app: raw
    chart: raw-0.2.5
    heritage: Helm
    release: foo
value: 2 # expected 1

It seems that selector not works and render all releases in the same namespace, so the last one win. I looked into the tree and It seems that #1772 is the one this change introduced.

UPDATE: I also try appending argument --include-needs=true|false, since #1772 mentioned about that, I still not work.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@katsew Thank you so much for testing! That’s super helpful.

I’ll go merging the mentioned PR 🤞

On the other hand, though, unselected releases are now missing in the st.Releases that results in PlanReleases failing due to needed releases are missing in st.Releases.

@katsew I’ve reread the code carefully and this turned out to be not particularly right.

PlanReleases does fail when needed releases are missing. But #1772 should have allowed that by forcing the user to provide a valid combination of --selector, --include-needs, --skip-needs to let PlanReleases receive necessary and sufficient releases and options to build the DAG. Actually, that was the primary purpose of #1772.

So, back to your finding:

I dig into this issue and I see that PlanReleases func cannot detect duplicated release name, since it convert release to id, so cannot filter the same release name even if the selector applied. How can I fix this… 🤔

As it turned out we can safely pass a subset of releases to the dag generation logic, we can safely use the deduplicated list of releases here:

https://github.com/roboll/helmfile/blob/f28ad5af2330621ac85e1ddf05c526c4147f2340/pkg/app/app.go#L1742-L1754

by changing st.Releases = allReleases to st.Releases = selectedReleasesWithNeeds .

PlanReleases remains unable to detect duplicated release names. Eliminating duplicated releases before calling it solves the issue. And it’s safe to do so since #1772.

Note that it must be selectedReleasesWithNeeds rather than selectedReleases, helm-template won’t run on releases included by --include-needs.

All these findings are reflected into #1822. I’d appreciate it if you could review it. Thanks in advance for your support!