mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +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
|
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.
|
// GetPod gets a specific pod specified by its ID.
|
||||||
func (r *Registry) GetPod(podID string) (*api.Pod, error) {
|
func (r *Registry) GetPod(podID string) (*api.Pod, error) {
|
||||||
var pod api.Pod
|
var pod api.Pod
|
||||||
|
@ -19,12 +19,15 @@ package pod
|
|||||||
import (
|
import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"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.
|
// Registry is an interface implemented by things that know how to store Pod objects.
|
||||||
type Registry interface {
|
type Registry interface {
|
||||||
// ListPods obtains a list of pods that match selector.
|
// ListPods obtains a list of pods that match selector.
|
||||||
ListPods(selector labels.Selector) ([]api.Pod, error)
|
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
|
// Get a specific pod
|
||||||
GetPod(podID string) (*api.Pod, error)
|
GetPod(podID string) (*api.Pod, error)
|
||||||
// Create a pod based on a specification, schedule it onto a specific machine.
|
// 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/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||||
|
|
||||||
"code.google.com/p/go-uuid/uuid"
|
"code.google.com/p/go-uuid/uuid"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@ -122,6 +123,11 @@ func (rs *RegistryStorage) List(selector labels.Selector) (interface{}, error) {
|
|||||||
return result, err
|
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{} {
|
func (rs RegistryStorage) New() interface{} {
|
||||||
return &api.Pod{}
|
return &api.Pod{}
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,12 @@ limitations under the License.
|
|||||||
package registrytest
|
package registrytest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PodRegistry struct {
|
type PodRegistry struct {
|
||||||
@ -51,6 +53,10 @@ func (r *PodRegistry) ListPods(selector labels.Selector) ([]api.Pod, error) {
|
|||||||
return filtered, nil
|
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) {
|
func (r *PodRegistry) GetPod(podId string) (*api.Pod, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user