Repository navigation
feat: dir= selector for path-based release filtering and traversal skip - #2609
Conversation
|
@yxxhero Thoughts? I'm not emotional regarding the concrete solution, but working in that opendesk downstream project is pretty painful for me right now. Not only can I deploy simple charts in 17 seconds now, I can deploy some at all instead of only waiting 130 seconds until something breaks and I can't deploy it at all 😂 |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
I'm still willing to work on this, just waiting for feedback 🙃 |
|
@dschmidt Really nice write-up, thanks for thinking through all the edge cases up front. I went and read the existing traversal code to double-check the premise — happy to confirm there's no CLI-side way today to skip sub-helmfile traversal by path. Wandering through your seven points — mostly nodding, a couple where I'd love to hear what you think:
Two things I wanted to raise, both open to discussion:
Minor nits, feel free to ignore: Happy to keep iterating on any of the above. |
yxxhero
left a comment
There was a problem hiding this comment.
Left a few line-level notes below — all open suggestions, nothing I'd block on. The broader design thoughts (shape, naming, dir=. semantics, inheritance interaction) are in the comment above.
Overall I think the direction is solid; the main thing I'd like to chew on is the reserved-dir breaking change in pkg/state/state.go.
|
|
||
| if rootDir != "" && !remote.IsRemote(m.Path) { | ||
| if dirTargets := extractDirSelectorTargets(effectiveSelectors); len(dirTargets) > 0 { | ||
| if !shouldDescendForDirFilter(rootDir, stateDir, m.Path, dirTargets) { |
There was a problem hiding this comment.
Nice — guarding with !remote.IsRemote(m.Path) and falling back to "descend" whenever shouldDescendForDirFilter can't reason about a path is the right conservative default.
Small ask: the e2e fixtures cover the happy path well, but would you mind adding a direct unit test of processNestedHelmfiles exercising the three states in one place — match descends, sibling skipped, remote entry never short-circuited? Easier to localize regressions than going through the full ForEachState chain.
| // called from the top-level entry of each command, before within() or any | ||
| // goroutine spawn. | ||
| func (a *App) resolveRootHelmfileDir() { | ||
| if a.rootHelmfileDirResolved { |
There was a problem hiding this comment.
Tiny nit, feel free to skip: resolveRootHelmfileDir + the rootHelmfileDirResolved flag is safe today because it runs before any fan-out, but sync.Once would express the intent a touch more clearly and keeps RootHelmfileDir()'s unlocked read obviously correct for future readers.
| // validateReservedLabels rejects user-defined labels that collide with keys | ||
| // the selector machinery auto-populates. Without this check, a user-defined | ||
| // "dir" label would be silently shadowed at match time. | ||
| func (st *HelmState) validateReservedLabels() error { |
There was a problem hiding this comment.
This is the one I wanted to flag most. Hard-failing on a user-defined dir label is technically a breaking change for anyone who happened to use that key. validateReservedLabels makes the failure loud (good), but name/namespace/chart are also implicit selectors and aren't validated — is there a reason dir needs to be stricter? If you're open to it, a deprecation warning for one release before hard-failing would smooth the upgrade. Happy either way, just wanted to raise it.
| "--selector tier=frontend,tier!=proxy --selector tier=backend" will match all frontend, non-proxy releases AND all backend releases. | ||
| The name of a release can be used as a label: "--selector name=myrelease"`) | ||
| The name of a release can be used as a label: "--selector name=myrelease". | ||
| The "dir" selector key is special: it matches by directory prefix against the location of the defining helmfile, relative to the root helmfile. Used as "--selector dir=apps/opencloud", it ALSO short-circuits sub-helmfile traversal so non-matching branches are not parsed or templated. The negative form "dir!=apps/opencloud" filters releases post-load but does not skip traversal.`) |
There was a problem hiding this comment.
The expanded -l help is getting long enough to wrap awkwardly in a terminal. Would you be open to trimming this to one line and pointing at the new docs/index.md#the-dir-selector section?
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Still willing to work on it, just had no time recently :) but I'm using it daily and it works fine for me |
ad45f0a to
e544554
Compare
|
Thanks for the thorough review! Rebased onto current main and addressed the line comments:
On the shape ( |
|
@dschmidt please fix DCO |
e544554 to
057e4c6
Compare
It's been a while, I forgot about that 😁 |
…l skip Introduce a new selector key `dir=<path>` to the -l/--selector flag with two effects: it filters releases by the directory of their defining helmfile relative to the root helmfile (using directory-prefix matching, so dir=apps/foo matches both apps/foo and apps/foo/sub), and it short-circuits sub-helmfile traversal when paired with positive dir= constraints, so non-matching branches in the helmfiles: tree are not parsed, templated, or fetched. The motivation is consuming aggregator-style upstreams that the operator does not control (opendesk being the immediate example), where the user cannot restructure the helmfile layout but still wants to act on a subset. The dir label is auto-populated at filter time only; user-facing label output is unchanged. The label key "dir" is reserved at state load. Selectors that escape the root via .. or absolute paths, and the bare ".", are rejected at parse time. Signed-off-by: Dominik Schmidt <[email protected]>
…lter Add a unit test covering the per-entry skip decision: match descends, sibling skipped, remote never short-circuited. Signed-off-by: Dominik Schmidt <[email protected]>
Signed-off-by: Dominik Schmidt <[email protected]>
…ir label Signed-off-by: Dominik Schmidt <[email protected]>
Hard-failing on an existing dir label is a breaking change. Log a deprecation warning for now and turn it into an error in a later release. Signed-off-by: Dominik Schmidt <[email protected]>
057e4c6 to
2438129
Compare
Upstream CI now fails when go fix would rewrite code. Use maps.Copy in injectLabel and drop the explicit embedded ReleaseSetSpec in test literals. Signed-off-by: Dominik Schmidt <[email protected]>
- Always shadow a user-defined dir label at match time, also when the release has no auto-populated value (remote or outside-root helmfiles). Previously the user value was matched there despite the warning. - Skip sibling helmfiles entries that are directories, not only files. - Warn about a dir label declared in a release template, and warn only once when it comes from a bases file. - Share the root-relative path and at-or-below checks between the release filter and the traversal skip; a directory whose name merely starts with two dots is no longer treated as escaping the root. - Log when the root directory cannot be resolved. - Tests: require for setup steps, t.Chdir, shared app fixture. Signed-off-by: Dominik Schmidt <[email protected]>
…ption docs/cli.md still carried the long help text. Also spell out what the dir value is relative to, that the traversal skip assumes nested helmfiles stay below their parent's directory, and that user-defined dir labels are ignored for releases without an auto-populated value as well. Signed-off-by: Dominik Schmidt <[email protected]>
Completion listed directories relative to the working directory, while dir values are relative to the root helmfile directory. Resolve the root from -f or HELMFILE_FILE_PATH with the same logic the app uses, and offer nothing for values the selector would reject (absolute paths, paths that escape the root) or for a remote root helmfile. Signed-off-by: Dominik Schmidt <[email protected]>
…and matching
- LabelFilter.Match: extract labelMatches helper; positive/negative loops
become single-level guards. Also removes the pre-existing empty
then-branch (if !ok {} else if) in the negative-label loop and the
redundant len()>0 guards around the loops
- positiveLabelsCompatibleWith: extract positiveLabelPairCompatible so the
double loop holds one guard instead of a nested if chain
- ParseLabels: extract parseOneLabel (separator detection, dir= value
validation, split) so the three-level regex/dir/error nesting becomes
flat; drop the vestigial trailing 'var err error' return
No behavior change; state/app/cmd tests incl. -race and golangci-lint pass.
Signed-off-by: yxxhero <[email protected]>
|
Niiice, thanks! |
…) (#902) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [aqua:helmfile/helmfile](https://github.com/helmfile/helmfile) | tools | patch | `1.8.1` → `1.8.2` | --- ### Release Notes <details> <summary>helmfile/helmfile (aqua:helmfile/helmfile)</summary> ### [`v1.8.2`](https://github.com/helmfile/helmfile/releases/tag/v1.8.2) [Compare Source](helmfile/helmfile@v1.8.1...v1.8.2) #### What's Changed - fix: support escaped commas in --state-values-set by [@​ban11111](https://github.com/ban11111) in [#​2813](helmfile/helmfile#2813) - add trackLogsUntilReady flag by [@​pznamensky](https://github.com/pznamensky) in [#​2814](helmfile/helmfile#2814) - feat: dir= selector for path-based release filtering and traversal skip by [@​dschmidt](https://github.com/dschmidt) in [#​2609](helmfile/helmfile#2609) - build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.113.4 to 1.114.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2818](helmfile/helmfile#2818) - build(deps): bump github.com/sashabaranov/go-openai from 1.42.1 to 1.43.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2819](helmfile/helmfile#2819) - build(deps): bump go.opentelemetry.io/otel/sdk/metric from 1.46.0 to 1.47.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2815](helmfile/helmfile#2815) - build(deps): bump gitpython from 3.1.59 to 3.1.62 in /docs by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2820](helmfile/helmfile#2820) - build(deps): bump golang.org/x/sync from 0.23.0 to 0.24.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2827](helmfile/helmfile#2827) - add trackLogsInterval option by [@​pznamensky](https://github.com/pznamensky) in [#​2825](helmfile/helmfile#2825) - build(deps): bump github.com/hashicorp/go-getter/v2 from 2.2.4 to 2.2.5 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2821](helmfile/helmfile#2821) - build(deps): bump go.opentelemetry.io/proto/otlp from 1.11.0 to 1.11.1 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2822](helmfile/helmfile#2822) - build(deps): bump go.opentelemetry.io/contrib/exporters/autoexport from 0.71.0 to 0.72.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2823](helmfile/helmfile#2823) - build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.114.0 to 1.114.3 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2828](helmfile/helmfile#2828) - build(deps): bump github.com/mattn/go-runewidth from 0.0.30 to 0.0.31 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2829](helmfile/helmfile#2829) - build(deps): bump golang.org/x/term from 0.46.0 to 0.47.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2830](helmfile/helmfile#2830) - build(deps): bump github.com/aws/aws-sdk-go-v2/config from 1.33.6 to 1.33.9 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2831](helmfile/helmfile#2831) - build(deps): bump github.com/gookit/color from 1.6.1 to 1.6.2 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2833](helmfile/helmfile#2833) - fix: skip recreatePods on Helm 4, which removed --recreate-pods by [@​Cayan](https://github.com/Cayan) in [#​2832](helmfile/helmfile#2832) - chore: bump Helm to v3.22.1 and v4.3.1 by [@​yxxhero](https://github.com/yxxhero) in [#​2834](helmfile/helmfile#2834) - fix: propagate --oci-plain-http to chartify for all chart-preparing commands by [@​yxxhero](https://github.com/yxxhero) in [#​2826](helmfile/helmfile#2826) **Full Changelog**: <helmfile/helmfile@v1.8.1...v1.8.2> </details> --- ### Configuration 📅 **Schedule**: (in timezone Europe/London) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNjcuNSIsInVwZGF0ZWRJblZlciI6IjQ0LjE2Ny41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.hayden.moe/hayden/phoebe/pulls/902
Why I am posting this
I was looking for a way to make
helmfile syncfast on a setup that consumes openDesk (ZenDiS' sovereign workplace). openDesk'shelmfile_generic.yaml.gotmpllists ~13 services as nested helmfile entries. To act on a single service today,helmfile -l name=foo syncstill parses and template-evaluates all 13 service branches before filtering, because the only existing short-circuit (subhelmfileSelectorsConflictinpkg/app/app.go) requires the sub-helmfile entry to carry explicitselectors:that conflict with the CLI ones, which the upstream entries don't.Since I cannot restructure openDesk's helmfile tree (frozen upstream), the lever has to live on the CLI side. This PR is one shape of that lever; I would like to know if there is a better one, or if something equivalent already exists that I missed.
What this adds
A new selector key,
dir=<path>, on the existing-l/--selectorflag with two effects:dir=apps/foomatches bothapps/fooandapps/foo/sub. Unlike other selector keys this is not strict equality; this is the part that feels most like a semantic carve-out and I'd value input on it.dir=constraints. For eachhelmfiles:entry, the newshouldDescendForDirFilterpredicate decides whether the branch could possibly contain a matching release before it is loaded. Branches that cannot are skipped entirely; no parse, no templating, no fetch.The dir label is injected at match time only inside
markExcludedReleasesand the original release labels stay untouched, sohelmfile listoutput is unaffected by the auto-population. The label keydiris reserved at state load (a user-definedcommonLabels: {dir: …}or per-releaselabels: {dir: …}fails the load with a clear message).Example
Things I am explicitly looking for feedback on
dir=.. I went through three drafts: matching everything (no-op, useless), matching only root-level releases (useful for "only my custom overlay, none of the upstream's services" but a semantic outlier), and the current behavior of rejecting.at parse time so the user has to omit-l dir=to mean "everything". I am not married to the reject; the root-only semantic genuinely has a use case in the frozen-upstream context, but it conflicts with the prefix-matching nature of every other dir value.ParseLabelsrejectsdir=,dir=.,dir=/abs,dir=... Other selector keys do not get this kind of value validation. Comfortable making dir= the exception?subhelmfileSelectorsConflict×dir=. I extendedpositiveLabelsCompatibleWithso twodir=values are considered compatible when one is a directory-prefix of the other (dir=appsvsdir=apps/foo), to match the prefix matching used elsewhere. Pre-existing behavior would have flagged them as conflicting and falsely pruned the sub-helmfile.selectors:(and does not opt into inheritance), the CLIdir=no longer governs that sub-tree per the existing selector-inheritance model. The PR honors that model:processNestedHelmfilescomputes effective selectors per-level and uses those for the skip decision. Worth documenting more loudly?dir=was the shortest thing that read naturally; the alternative I considered wasdir_prefix=to signal the non-strict semantics, but it is awkward to type and the prefix behavior can be documented. Open to renaming.pkg/app/dir_filter_test.go) drive the fullForEachStatechain through a fake FS and assert that only the matching branch is opened. Unit-level tests cover the helpers, the rejection of./absolute/..values, and the validation hook in state load. Coverage ofprocessNestedHelmfilesitself is via the integration tests rather than direct mocking.Known limitations / out of scope
git::,http://, etc. always descend.dir=group cannot skip traversal if any other-lgroup in the same invocation has nodir=constraint, since that group could match releases anywhere.needs:across pruned branches behave the same as under the existingsubhelmfileSelectorsConflictoptimization: pruned branches don't get loaded so their releases cannot satisfy aneeds:from outside. Use adir=covering both subtrees.helmfiles: apps/**/helmfile.yaml) and themissingFileHandlerhappen at parent load time, before the skip check. A missing path in an entry the dir filter would have skipped still errors the parent load unlessmissingFileHandler: Warnis set.bases:inherit the including helmfile's directory for the auto label, not the base file's.