mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 13:14:05 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user