Add field selector to List, implement for pods.

This commit is contained in:
Daniel Smith
2014-09-16 16:15:40 -07:00
parent 3f659f7d74
commit 4e9cf2ccb4
18 changed files with 153 additions and 39 deletions

View File

@@ -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