docs(resourceselector): Document namespace selection and exclusion - #663
Open
aaronmhmr wants to merge 1 commit into
Open
docs(resourceselector): Document namespace selection and exclusion#663aaronmhmr wants to merge 1 commit into
aaronmhmr wants to merge 1 commit into
Conversation
The namespaceSelector field is parsed as a full Kubernetes label selector, so it already supports set-based operators. Combined with the automatic kubernetes.io/metadata.name label, this allows namespaces to be excluded by name without any new API field. Neither namespaceSelector nor this idiom was documented. Documents the namespace and namespaceSelector fields, single-namespace and label-based selection, and the exclusion idiom, with a worked example that skips protected namespaces such as kube-system. Closes gianlucam76#373 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Amin Mohammadian <aminmhmr@gmail.com>
aaronmhmr
force-pushed
the
docs/namespace-exclusion
branch
from
July 13, 2026 09:38
5e00491 to
20d5654
Compare
Owner
|
Thank you @aminmr Good for me. @egrosdou01 covers the documentation so I added her as reviewer. Meanwhile I will address the OVS scanner issue which is unrelated to this PR |
Owner
|
@egrosdou01 can you please review this? thanks |
Collaborator
|
@gianlucam76 Only small wording issues. If @aaronmhmr does not have time to update the docu, feel free to merge it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #373.
In #373 I asked for an
excludedNamespacesfield. @gianlucam76 replied that this is already possible, and he is right — but there is a third route that is nicer than either option in that thread, and none of it is documented.The capability already exists
namespaceSelectoris declared as a plain string (api/v1alpha1/cleaner_types.go:110) and parsed withlabels.Parse()(internal/controller/executor/worker.go:501). That is the full apimachinery selector parser, so it accepts set-based operators, includingnotin. Kubernetes separately labels every namespace withkubernetes.io/metadata.name(theNamespaceDefaultLabelNameadmission plugin, default since v1.22).Put together, namespaces can be excluded by name today, with no new API field and no manual labelling:
This is more declarative than an ignore-list inside the Lua
evaluate, and needs no pre-labelling of namespaces.But it is undiscoverable
namespaceSelectorappears zero times indocs/.kubernetes.io/metadata.nameappears zero times in the repository.aggregatedSelectionand never documentsnamespaceornamespaceSelector.So this PR is documentation only — no code, no API change.
What this adds
A purely additive change to
docs/getting_started/features/resourceselector/resourceselector.md. Nothing existing is moved or reworded:namespaceandnamespaceSelectorfields, how they combine, and what happens when neither is set. Single-namespace and label-based selection.notinidiom, plus the failed-pods example from Feature Request: Add Namespace Exclusion to Cleaner Resource #373 with the namespace check removed from the Lua.resourceSelector; requires k8s >= 1.22; not applicable to cluster-scoped kinds).Both new sections land in the page ToC and search index, so no nav change was needed.
Verification
Docs build clean with the project toolchain (
zensical build→No issues found), and every snippet in the new text was executed on a kind cluster (Kubernetes v1.36.1) running k8s-cleaner frommanifest/manifest.yaml.Four identically failed pods (
Failed/Error/ exit 1, so all matching the Lua) were created inkube-system,cert-manager,my-appanddefault, then the documented Cleaner was applied. Controller log:The two protected pods were never even considered as candidates —
namespaceSelectorfiltered them out at collection time, before the Lua ran. They survived; the other two were deleted.One thing worth your call, @gianlucam76
While verifying, I hit this in
internal/controller/executor/worker.go:422:A
namespaceSelectorthat matches zero namespaces does not narrow the Cleaner to nothing — it falls back to scanning every namespace. Withaction: Delete, a typo in an exclusion selector could therefore widen its blast radius rather than shrink it.I have not treated this as a bug in the docs. The warning box states it neutrally as behaviour and gives users a
kubectlcommand to check their selector first. Whether the fail-open default itself should change is your call — happy to open a separate issue if you would like.