-
Notifications
You must be signed in to change notification settings - Fork 338
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
feat(k8s): watch specific namespaces (PoC) #12877
Closed
Closed
Conversation
This file contains 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
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Reviewer Checklist🔍 Each of these sections need to be checked by the reviewer of the PR 🔍:
|
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Closing, let's reopen when it's required |
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.
Motivation
By default, Kuma watches for changes across all namespaces. This simplifies the initial user experience, making it easier to get started. However, at some point, users may want to restrict the information available to the control plane to enhance security, or reduce unnecessary resource consumption.
Implementation information
This feature requires modifying permissions across multiple components:
ClusterRole
options intoRole
If
watchNamespaces
is set:Step 1:
I moved most namespace-scoped resources to separate
Role
objects, which are created inwatchNamespaces
and must be set up by the user before deployment. Instead of using only aClusterRole
, we now create aClusterRole
with a more limited scope, aRole
in the system namespace, andRoles
in each user-provided namespace.Step 2:
In Helm, we validate whether the user has provided specific namespaces. If so, we configure webhooks to only monitor those namespaces along with the systemNamespace.
Step 3:
We need to define a defaultNamespaces parameter for the Kubernetes cache. This cache retrieves information from the Kubernetes API and, by default, fetches resources from all namespaces. This change introduces a way to limit requests to specific namespaces: watchNamespaces, systemNamespace, and the CNI namespace.
Additionally, in many parts of the code, we perform
.List
operations, which require a namespace to be specified. Instead of adding the namespace to each request individually, I introduced a wrapper that iterates over and requests resources from each watched namespace.Since some resources are cluster-scoped, I also introduced a way to check whether a resource is cluster-scoped. If it is, the request is made for all resources. Because
defaultNamespaces
configures the default informers in the manager, we don't need to define predicates for each controller.Step 4:
We create separate informers using the Kubernetes client, which fetches resources differently from the default cache. Since there is no built-in option to list resources across multiple namespaces, we need to create an informer for each namespace.
Supporting documentation
https://medium.com/@timebertt/kubernetes-controllers-at-scale-clients-caches-conflicts-patches-explained-aa0f7a8b4332
xref: https://github.com/Kong/kong-mesh/issues/7408