-
Notifications
You must be signed in to change notification settings - Fork 465
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: Watch Namespaces based on labels and label selectors #9976
Conversation
@@ -1,11 +1,10 @@ | |||
package clients | |||
package vault |
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.
Moved this file to prevent an import cycle
Visit the preview URL for this PR (updated for commit 19bcb53): https://gloo-edge--pr9976-watch-namespace-sele-twteibok.web.app (expires Tue, 01 Oct 2024 18:58:43 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 77c2b86e287749579b7ff9cadb81e099042ef677 |
Issues linked to changelog: |
func HandleResourceDeletion(snapshot *v1snap.ApiSnapshot, resource resources.Resource) error { | ||
if _, ok := resource.(*sk_kubernetes.KubeNamespace); ok { | ||
// Special case to handle namespace deletion | ||
snapshot.RemoveAllResourcesInNamespace(resource.GetMetadata().GetName()) | ||
return nil | ||
} else { | ||
return snapshot.RemoveFromResourceList(resource) | ||
} | ||
} | ||
|
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.
Would change to
diff --git a/projects/gloo/pkg/validation/server.go b/projects/gloo/pkg/validation/server.go
index 7621d7433..630086eae 100644
--- a/projects/gloo/pkg/validation/server.go
+++ b/projects/gloo/pkg/validation/server.go
@@ -210,7 +210,9 @@ func (s *validator) Validate(ctx context.Context, req *validation.GlooValidation
func HandleResourceDeletion(snapshot *v1snap.ApiSnapshot, resource resources.Resource) error {
if _, ok := resource.(*sk_kubernetes.KubeNamespace); ok {
// Special case to handle namespace deletion
- snapshot.RemoveAllResourcesInNamespace(resource.GetMetadata().GetName())
+ snapshot.RemoveMatches(func(metadata *core.Metadata) bool {
+ return resource.GetMetadata().GetNamespace() == metadata.GetNamespace()
+ })
return nil
} else {
return snapshot.RemoveFromResourceList(resource)
after the solo-kit bump
pkg/utils/namespaces/namespaces.go
Outdated
|
||
resp, err := clientset.AuthorizationV1().SelfSubjectAccessReviews().Create(ctx, &selfCheck, metav1.CreateOptions{}) | ||
if err != nil { | ||
return &FakeKubeNamespaceWatcher{} |
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.
For example, if we failed here and just silently returned a no-op, it would not be clear to a user or dev that we may be running into some RBAC issues. Returning a nil client and an error would lead to better debugging I think
projects/gateway/pkg/services/k8sadmission/validating_admission_webhook.go
Show resolved
Hide resolved
// Kubernetes' Secrets and namespace deletions are the only non-Solo API resource operations we support validation requests for. | ||
// For a these resources, we want to skip validation on operations we don't support. We only support DELETEs. |
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.
// Kubernetes' Secrets and namespace deletions are the only non-Solo API resource operations we support validation requests for. | |
// For a these resources, we want to skip validation on operations we don't support. We only support DELETEs. | |
// Kubernetes Secrets and Namespace are the only non-Solo API resources we support validation requests for. | |
// For a these resources, we want to skip validation on operations we don't support. For Namespaces, we | |
// support DELETE and UPDATE. For Secrets, we support DELETE. |
@@ -49,6 +49,8 @@ type BaseTestingSuite struct { | |||
|
|||
func NewBaseTestingSuite(ctx context.Context, testInst *e2e.TestInstallation, testHelper *helper.SoloTestHelper, setup SimpleTestCase, testCase map[string]*TestCase) *BaseTestingSuite { | |||
namespace = testInst.Metadata.InstallNamespace | |||
ctx = context.WithValue(ctx, "namespace", namespace) |
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.
The provider has a reference to the gloogateway.Context
which has the InstallationNamespace
closing in favour of solo-io#10104 |
Description
The watchNamespaces setting allows users to restrict the namespaces in which Edge watches resources. Since this is a static list, users need to update it when they need to modify namespaces to watch
This feature aims to dynamically determine the list of namespaces to watch by defining labels on namespaces or filtering namespaces based on a label expression.
This feature identifies namespaces with label selectors. These can be :
This will introduce a new setting to select namespaces :
API changes
watchNamespaceSelectors
to the settings CRCCode changes
Added a KubeNamespaceWatcher to the setup snapshot emitter. This will trigger a new snapshot if any namespace has been created / deleted / modified and not necessarily if the namespace belongs to the list we watch. The syncer will determine whether to sync based on whether :
Context
Watch Namespaces based on labels and label selectors
Design doc
Interesting decisions
Testing steps
Added kubernetes e2e tests
Notes for reviewers
Checklist: