Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add namespace filtering #11370

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marek-veber
Copy link

@marek-veber marek-veber commented Nov 4, 2024

What this PR does / why we need it:
This PR adds an option --excluded-namespace=<comma separated list of namespaces>

Which issue(s) this PR fixes:
Fixes #11193

/area/clusterresourceset

Copy link

linux-foundation-easycla bot commented Nov 4, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: marek-veber / name: Marek Veber (4c5ea6f)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign fabriziopandini for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the do-not-merge/needs-area PR is missing an area label label Nov 4, 2024
@k8s-ci-robot
Copy link
Contributor

This PR is currently missing an area label, which is used to identify the modified component when generating release notes.

Area labels can be added by org members by writing /area ${COMPONENT} in a comment

Please see the labels list for possible areas.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

Welcome @marek-veber!

It looks like this is your first PR to kubernetes-sigs/cluster-api 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Nov 4, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @marek-veber. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 4, 2024
@sbueringer
Copy link
Member

I don't have time to contribute to this now / until code freeze / PTO / .. but let's please make sure we have a very clear understanding how whatever filtering we do works across:

  • the cache
  • the cached client (mgr.GetClient)
  • all our controllers (event filtering)
  • ClusterCache
  • every other part of Cluster API that is affected

I think something like the cache and the event filtering in our controller watches and especially all the calls we do on the cached client have to be carefully orchestrated with each other. Today we have a lot of options for performance improvements, these might go away if we surface the wrong configuration options to end users.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 4, 2024
@fabriziopandini
Copy link
Member

fabriziopandini commented Nov 4, 2024

Let's also try to get a better understanding of the use case we are trying to address, because our current stance is that support for running multiple instances of Cluster API is should be considered best-effort + the issue linked above are not really well harmonised in term of requirements and proposed solution.

BTW, above statement, and the fact that as @sbueringer noted this is way trickier than it could appear at first sight, are the same reason why we have a few other long standing feature request in this area

@@ -122,6 +125,9 @@ func InitFlags(fs *pflag.FlagSet) {
fs.StringVar(&watchFilterValue, "watch-filter", "",
fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel))

fs.StringVar(&watchFilterExcludedNamespaces, "excluded-namespaces", "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a StringSliceVar? We are using pflag so I think there is

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used

Comment on lines 183 to 199
func ResourceHasFilterExcludeNamespaces(scheme *runtime.Scheme, logger logr.Logger, excludedNamespaces []string) predicate.Funcs {
return predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
return processIfNamespaceExcluded(scheme, logger.WithValues("predicate", "ResourceHasFilterExcludeNamespaces", "eventType", "update"), e.ObjectNew, excludedNamespaces)
},
CreateFunc: func(e event.CreateEvent) bool {
return processIfNamespaceExcluded(scheme, logger.WithValues("predicate", "ResourceHasFilterExcludeNamespaces", "eventType", "create"), e.Object, excludedNamespaces)
},
DeleteFunc: func(e event.DeleteEvent) bool {
return processIfNamespaceExcluded(scheme, logger.WithValues("predicate", "ResourceHasFilterExcludeNamespaces", "eventType", "delete"), e.Object, excludedNamespaces)
},
GenericFunc: func(e event.GenericEvent) bool {
return processIfNamespaceExcluded(scheme, logger.WithValues("predicate", "ResourceHasFilterExcludeNamespaces", "eventType", "generic"), e.Object, excludedNamespaces)
},
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right approach to solving this issue. The suggestion in #11193 uses the FieldSelector concept of an API request to filter resources at the API server level, rather than the controller level.

Given the scale potential here, I think we want to follow that suggestion and move the filtering to the API server where possible.

I'm not sure if that approach also has RBAC advantages, perhaps we don't need permissions on the excluded namespace? But that could also be an advantage of the approach as suggested by Alberto

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @JoelSpeed! Please take a look at the new approach in this PR.

@marek-veber marek-veber changed the title add namespace filtering ✨ (:sparkles:) add namespace filtering Nov 6, 2024
@marek-veber marek-veber changed the title (:sparkles:) add namespace filtering ✨ add namespace filtering Nov 6, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 6, 2024
@@ -122,6 +124,9 @@ func InitFlags(fs *pflag.FlagSet) {
fs.StringVar(&watchFilterValue, "watch-filter", "",
fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel))

fs.StringSliceVar(&watchFilterExcludedNamespaces, "excluded-namespaces", nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be excluded-namespace (singular, but still a comma separated list) to match the existing flag namespace, which cannot be changed to namespaces without a breaking change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed --excluded-namespaces -> --excluded-namespace

@sbueringer
Copy link
Member

sbueringer commented Nov 11, 2024

/hold
xref: #11370 (comment) #11370 (comment)
(just to make sure these comments are not getting missed)

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 11, 2024
@neolit123
Copy link
Member

neolit123 commented Nov 11, 2024

i recall recent discussions in core k8s on a KEP somewhere that this pattern is not preferred i.e. adding both an allow list and a deny list flag at the same time.

how about keeping this simple and doing the following:

  • --namespace not specified == watch all NS
  • --namespace specifies some NS as a comma separated list == only watch those NS

that means for a NS to be watched it must be in the --namespace list.
downside of that is that a controller restart is needed every time a new NS must be watched.
then again, same goes for anytime you need to exclude a certain NS.

@marek-veber
Copy link
Author

marek-veber commented Nov 11, 2024

We also need the following behavior (I’ve split it into two separate PRs):

  • If --namespace is not specified, it defaults to watching all namespaces.
  • Use --exclude-namespace=ns1,ns2,... to watch all namespaces except specified ones (e.g., ns1, ns2).

Additionally, there’s a more flexible option, see: #7775 (comment) that allows for more complex conditions. However, it doesn’t seem to support using a direct "positive" list of namespaces to watch.

@fabriziopandini
Copy link
Member

+1 to what @sbueringer said
we should not add flags until we have a clear idea of what we want to achieve.
also, as written in a few comments, this is not as simple as adding a flag.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 21, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/needs-area PR is missing an area label needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enabling option to ignore namespaces
6 participants