mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Add Watch to /pods.
This commit is contained in:
parent
053e75d8e9
commit
e40e5b53a7
@ -77,6 +77,19 @@ func (r *Registry) ListPods(selector labels.Selector) ([]api.Pod, error) {
|
||||
return filteredPods, nil
|
||||
}
|
||||
|
||||
// WatchPods begins watching for new, changed, or deleted pods.
|
||||
func (r *Registry) WatchPods(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
return r.WatchList("/registry/pods", resourceVersion, func(obj interface{}) bool {
|
||||
pod := obj.(*api.Pod)
|
||||
fields := labels.Set{
|
||||
"ID": pod.ID,
|
||||
"CurrentState.Status": string(pod.CurrentState.Status),
|
||||
"CurrentState.Host": pod.CurrentState.Host,
|
||||
}
|
||||
return label.Matches(labels.Set(pod.Labels)) && field.Matches(fields)
|
||||
})
|
||||
}
|
||||
|
||||
// GetPod gets a specific pod specified by its ID.
|
||||
func (r *Registry) GetPod(podID string) (*api.Pod, error) {
|
||||
var pod api.Pod
|
||||
|
@ -19,12 +19,15 @@ package pod
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
// Registry is an interface implemented by things that know how to store Pod objects.
|
||||
type Registry interface {
|
||||
// ListPods obtains a list of pods that match selector.
|
||||
ListPods(selector labels.Selector) ([]api.Pod, error)
|
||||
// Watch for new/changed/deleted pods
|
||||
WatchPods(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
|
||||
// Get a specific pod
|
||||
GetPod(podID string) (*api.Pod, error)
|
||||
// Create a pod based on a specification, schedule it onto a specific machine.
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
|
||||
"code.google.com/p/go-uuid/uuid"
|
||||
"github.com/golang/glog"
|
||||
@ -122,6 +123,11 @@ func (rs *RegistryStorage) List(selector labels.Selector) (interface{}, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Watch begins watching for new, changed, or deleted pods.
|
||||
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
return rs.registry.WatchPods(label, field, resourceVersion)
|
||||
}
|
||||
|
||||
func (rs RegistryStorage) New() interface{} {
|
||||
return &api.Pod{}
|
||||
}
|
||||
|
@ -17,10 +17,12 @@ limitations under the License.
|
||||
package registrytest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
type PodRegistry struct {
|
||||
@ -51,6 +53,10 @@ func (r *PodRegistry) ListPods(selector labels.Selector) ([]api.Pod, error) {
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func (r *PodRegistry) WatchPods(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
}
|
||||
|
||||
func (r *PodRegistry) GetPod(podId string) (*api.Pod, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user