-
Notifications
You must be signed in to change notification settings - Fork 3
🤖 feat: add WATCH support to aggregated API server storage #72
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ee2efce
feat: add watch support to aggregated storage
ThomasK33 fb9406e
test: add watch unit tests for aggregated storage
ThomasK33 a5d2309
fix: populate workspace delete watch event with delete-transition bui…
ThomasK33 cf9327b
fix: reject unsupported watch-list options
ThomasK33 d70ee1d
fix: allow defaulted legacy watch-list options
ThomasK33 faf95ad
fix: reject defaulted watch-list options
ThomasK33 7738fe2
fix: reject watch resourceVersion and avoid dropped events
ThomasK33 dc07eba
fix: make watch broadcasts async and accept resourceVersion
ThomasK33 4300487
fix: serialize watch event dispatch per storage
ThomasK33 ff88b2d
fix: keep watch enqueue non-blocking under backpressure
ThomasK33 9b13ec5
fix: use non-blocking broadcaster mode for watches
ThomasK33 2e785c2
fix: stop watch timeout goroutines when watchers stop
ThomasK33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package storage | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/fields" | ||
| "k8s.io/apimachinery/pkg/labels" | ||
| "k8s.io/apimachinery/pkg/watch" | ||
| ) | ||
|
|
||
| // watchBroadcasterQueueLen is the default queue length for watch broadcasters. | ||
| const watchBroadcasterQueueLen = 100 | ||
|
|
||
| // supportedWatchFieldSelectors lists the metadata fields supported for watch field selectors. | ||
| var supportedWatchFieldSelectors = map[string]bool{ | ||
| "metadata.name": true, | ||
| "metadata.namespace": true, | ||
| } | ||
|
|
||
| // validateFieldSelector checks that all field selector requirements use supported fields. | ||
| func validateFieldSelector(sel fields.Selector) error { | ||
| if sel == nil || sel.Empty() { | ||
| return nil | ||
| } | ||
|
|
||
| reqs := sel.Requirements() | ||
| for _, req := range reqs { | ||
| if !supportedWatchFieldSelectors[req.Field] { | ||
| return fmt.Errorf( | ||
| "field selector %q is not supported; supported fields: metadata.name, metadata.namespace", | ||
| req.Field, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // validateUnsupportedWatchListOptions rejects watch-list options that this storage | ||
| // does not implement yet. | ||
| func validateUnsupportedWatchListOptions(opts *metainternalversion.ListOptions) error { | ||
| if opts == nil { | ||
| return nil | ||
| } | ||
|
|
||
| if opts.SendInitialEvents != nil && *opts.SendInitialEvents { | ||
| return fmt.Errorf("sendInitialEvents=true is not supported for this watch endpoint") | ||
| } | ||
| if opts.ResourceVersionMatch != "" { | ||
| return fmt.Errorf( | ||
| "resourceVersionMatch %q is not supported for this watch endpoint", | ||
| opts.ResourceVersionMatch, | ||
| ) | ||
|
ThomasK33 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // filterForListOptions builds a watch.FilterFunc that applies namespace, label, and field selector filtering. | ||
| // Returns nil if no filtering is needed. | ||
| func filterForListOptions(requestNamespace string, opts *metainternalversion.ListOptions) (watch.FilterFunc, error) { | ||
| var labelSel labels.Selector | ||
| var fieldSel fields.Selector | ||
|
|
||
| if opts != nil { | ||
| if opts.LabelSelector != nil && !opts.LabelSelector.Empty() { | ||
| labelSel = opts.LabelSelector | ||
| } | ||
| if opts.FieldSelector != nil && !opts.FieldSelector.Empty() { | ||
| if err := validateFieldSelector(opts.FieldSelector); err != nil { | ||
| return nil, err | ||
| } | ||
| fieldSel = opts.FieldSelector | ||
| } | ||
| } | ||
|
|
||
| if requestNamespace == "" && labelSel == nil && fieldSel == nil { | ||
| return nil, nil | ||
| } | ||
|
|
||
| return func(in watch.Event) (watch.Event, bool) { | ||
| obj, ok := in.Object.(metav1.ObjectMetaAccessor) | ||
| if !ok { | ||
| return in, true | ||
| } | ||
|
|
||
| meta := obj.GetObjectMeta() | ||
| if requestNamespace != "" && meta.GetNamespace() != requestNamespace { | ||
| return in, false | ||
| } | ||
|
|
||
| if labelSel != nil && !labelSel.Matches(labels.Set(meta.GetLabels())) { | ||
| return in, false | ||
| } | ||
|
|
||
| if fieldSel != nil { | ||
| fieldSet := fields.Set{ | ||
| "metadata.name": meta.GetName(), | ||
| "metadata.namespace": meta.GetNamespace(), | ||
| } | ||
| if !fieldSel.Matches(fieldSet) { | ||
| return in, false | ||
| } | ||
| } | ||
|
|
||
| return in, true | ||
| }, nil | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.