Add the resource version to api.*List items from etcd

Allows clients to watch more easily (can invoke Get, then
Watch).
This commit is contained in:
Clayton Coleman
2014-08-28 20:48:07 -04:00
parent c380dd0426
commit bafc422ac0
17 changed files with 120 additions and 89 deletions

View File

@@ -24,10 +24,10 @@ import (
// TODO: Why do we have this AND MemoryRegistry?
type ControllerRegistry struct {
Err error
Controllers []api.ReplicationController
Controllers *api.ReplicationControllerList
}
func (r *ControllerRegistry) ListControllers() ([]api.ReplicationController, error) {
func (r *ControllerRegistry) ListControllers() (*api.ReplicationControllerList, error) {
return r.Controllers, r.Err
}

View File

@@ -27,32 +27,34 @@ import (
type PodRegistry struct {
Err error
Pod *api.Pod
Pods []api.Pod
Pods *api.PodList
sync.Mutex
mux *watch.Mux
}
func NewPodRegistry(pods []api.Pod) *PodRegistry {
func NewPodRegistry(pods *api.PodList) *PodRegistry {
return &PodRegistry{
Pods: pods,
mux: watch.NewMux(0),
}
}
func (r *PodRegistry) ListPods(selector labels.Selector) ([]api.Pod, error) {
func (r *PodRegistry) ListPods(selector labels.Selector) (*api.PodList, error) {
r.Lock()
defer r.Unlock()
if r.Err != nil {
return r.Pods, r.Err
return nil, r.Err
}
var filtered []api.Pod
for _, pod := range r.Pods {
for _, pod := range r.Pods.Items {
if selector.Matches(labels.Set(pod.Labels)) {
filtered = append(filtered, pod)
}
}
return filtered, nil
pods := *r.Pods
pods.Items = filtered
return &pods, nil
}
func (r *PodRegistry) WatchPods(resourceVersion uint64, filter func(*api.Pod) bool) (watch.Interface, error) {

View File

@@ -37,8 +37,8 @@ type ServiceRegistry struct {
UpdatedID string
}
func (r *ServiceRegistry) ListServices() (api.ServiceList, error) {
return r.List, r.Err
func (r *ServiceRegistry) ListServices() (*api.ServiceList, error) {
return &r.List, r.Err
}
func (r *ServiceRegistry) CreateService(svc api.Service) error {