mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-03 18:26:59 +00:00
Enable list option modification when create list watch
Kubernetes-commit: 2780b8f9e4bba0a27b44e0647a579b1c435987b1
This commit is contained in:
parent
1b825e3a78
commit
34ead21345
14
tools/cache/listwatch.go
vendored
14
tools/cache/listwatch.go
vendored
@ -63,8 +63,18 @@ type Getter interface {
|
|||||||
|
|
||||||
// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
|
// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
|
||||||
func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSelector fields.Selector) *ListWatch {
|
func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSelector fields.Selector) *ListWatch {
|
||||||
listFunc := func(options metav1.ListOptions) (runtime.Object, error) {
|
optionsModifier := func(options *metav1.ListOptions) {
|
||||||
options.FieldSelector = fieldSelector.String()
|
options.FieldSelector = fieldSelector.String()
|
||||||
|
}
|
||||||
|
return NewFilteredListWatchFromClient(c, resource, namespace, optionsModifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilteredListWatchFromClient creates a new ListWatch from the specified client, resource, namespace, and option modifier.
|
||||||
|
// Option modifier is a function takes a ListOptions and modifies the consumed ListOptions. Provide customized modifier function
|
||||||
|
// to apply modification to ListOptions with a field selector, a label selector, or any other desired options.
|
||||||
|
func NewFilteredListWatchFromClient(c Getter, resource string, namespace string, optionsModifier func(options *metav1.ListOptions)) *ListWatch {
|
||||||
|
listFunc := func(options metav1.ListOptions) (runtime.Object, error) {
|
||||||
|
optionsModifier(&options)
|
||||||
return c.Get().
|
return c.Get().
|
||||||
Namespace(namespace).
|
Namespace(namespace).
|
||||||
Resource(resource).
|
Resource(resource).
|
||||||
@ -74,7 +84,7 @@ func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSe
|
|||||||
}
|
}
|
||||||
watchFunc := func(options metav1.ListOptions) (watch.Interface, error) {
|
watchFunc := func(options metav1.ListOptions) (watch.Interface, error) {
|
||||||
options.Watch = true
|
options.Watch = true
|
||||||
options.FieldSelector = fieldSelector.String()
|
optionsModifier(&options)
|
||||||
return c.Get().
|
return c.Get().
|
||||||
Namespace(namespace).
|
Namespace(namespace).
|
||||||
Resource(resource).
|
Resource(resource).
|
||||||
|
Loading…
Reference in New Issue
Block a user