mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-09 13:12:20 +00:00
Add field selector to List, implement for pods.
This commit is contained in:
@@ -40,7 +40,7 @@ func NewPodRegistry(pods *api.PodList) *PodRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PodRegistry) ListPods(selector labels.Selector) (*api.PodList, error) {
|
||||
func (r *PodRegistry) ListPodsPredicate(filter func(*api.Pod) bool) (*api.PodList, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
if r.Err != nil {
|
||||
@@ -48,7 +48,7 @@ func (r *PodRegistry) ListPods(selector labels.Selector) (*api.PodList, error) {
|
||||
}
|
||||
var filtered []api.Pod
|
||||
for _, pod := range r.Pods.Items {
|
||||
if selector.Matches(labels.Set(pod.Labels)) {
|
||||
if filter(&pod) {
|
||||
filtered = append(filtered, pod)
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,12 @@ func (r *PodRegistry) ListPods(selector labels.Selector) (*api.PodList, error) {
|
||||
return &pods, nil
|
||||
}
|
||||
|
||||
func (r *PodRegistry) ListPods(selector labels.Selector) (*api.PodList, error) {
|
||||
return r.ListPodsPredicate(func(pod *api.Pod) bool {
|
||||
return selector.Matches(labels.Set(pod.Labels))
|
||||
})
|
||||
}
|
||||
|
||||
func (r *PodRegistry) WatchPods(resourceVersion uint64, filter func(*api.Pod) bool) (watch.Interface, error) {
|
||||
// TODO: wire filter down into the mux; it needs access to current and previous state :(
|
||||
return r.mux.Watch(), nil
|
||||
|
Reference in New Issue
Block a user