mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Enable list option modification when create list watch
This commit is contained in:
parent
da9a4d5da9
commit
2780b8f9e4
@ -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