-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: main
Are you sure you want to change the base?
✨ add namespace filtering #11370
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
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 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. |
Welcome @marek-veber! |
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 Once the patch is verified, the new status will be reflected by the 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. |
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:
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. |
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 |
bootstrap/kubeadm/main.go
Outdated
@@ -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", "", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used
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) | ||
}, | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
84ef63f
to
beba100
Compare
beba100
to
bbd7909
Compare
bootstrap/kubeadm/main.go
Outdated
@@ -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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
/hold |
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:
that means for a NS to be watched it must be in the --namespace list. |
We also need the following behavior (I’ve split it into two separate PRs):
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. |
bbd7909
to
4c5ea6f
Compare
+1 to what @sbueringer said |
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. |
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