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
- Deduplicate releases when templating with --selector fixes: #1818 — committed to katsew/helmfile by katsew 3 years ago
- Fix --selector results to correctly deduplicate releases Fixes #1818 — committed to roboll/helmfile by mumoshu 3 years ago
- Fix --selector results to correctly deduplicate releases (#1822) Fixes #1818 — committed to roboll/helmfile by mumoshu 3 years ago
- Fix --selector results to correctly deduplicate releases Fixes #1818 — committed to roboll/helmfile by mumoshu 3 years ago
- Fix broken selector and DAG calculation logic after --{include,skip}-needs addition with correct Release IDs (#1823) #1772 broke `--selector` with `needs` in many ways. The two biggest problems I'... — committed to roboll/helmfile by mumoshu 3 years ago
@katsew Thank you so much for testing! That’s super helpful.
I’ll go merging the mentioned PR 🤞
@katsew I’ve reread the code carefully and this turned out to be not particularly right.
PlanReleasesdoes 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-needsto letPlanReleasesreceive necessary and sufficient releases and options to build the DAG. Actually, that was the primary purpose of #1772.So, back to your finding:
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 = allReleasestost.Releases = selectedReleasesWithNeeds.PlanReleasesremains 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
selectedReleasesWithNeedsrather thanselectedReleases,helm-templatewon’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!