mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 22:53:22 +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:
@@ -59,22 +59,24 @@ func makePodKey(podID string) string {
|
||||
}
|
||||
|
||||
// ListPods obtains a list of pods that match selector.
|
||||
func (r *Registry) ListPods(selector labels.Selector) ([]api.Pod, error) {
|
||||
allPods := []api.Pod{}
|
||||
filteredPods := []api.Pod{}
|
||||
if err := r.ExtractList("/registry/pods", &allPods); err != nil {
|
||||
func (r *Registry) ListPods(selector labels.Selector) (*api.PodList, error) {
|
||||
allPods := api.PodList{}
|
||||
err := r.ExtractList("/registry/pods", &allPods.Items, &allPods.ResourceVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, pod := range allPods {
|
||||
filtered := []api.Pod{}
|
||||
for _, pod := range allPods.Items {
|
||||
if selector.Matches(labels.Set(pod.Labels)) {
|
||||
// TODO: Currently nothing sets CurrentState.Host. We need a feedback loop that sets
|
||||
// the CurrentState.Host and Status fields. Here we pretend that reality perfectly
|
||||
// matches our desires.
|
||||
pod.CurrentState.Host = pod.DesiredState.Host
|
||||
filteredPods = append(filteredPods, pod)
|
||||
filtered = append(filtered, pod)
|
||||
}
|
||||
}
|
||||
return filteredPods, nil
|
||||
allPods.Items = filtered
|
||||
return &allPods, nil
|
||||
}
|
||||
|
||||
// WatchPods begins watching for new, changed, or deleted pods.
|
||||
@@ -225,9 +227,9 @@ func (r *Registry) DeletePod(podID string) error {
|
||||
}
|
||||
|
||||
// ListControllers obtains a list of ReplicationControllers.
|
||||
func (r *Registry) ListControllers() ([]api.ReplicationController, error) {
|
||||
var controllers []api.ReplicationController
|
||||
err := r.ExtractList("/registry/controllers", &controllers)
|
||||
func (r *Registry) ListControllers() (*api.ReplicationControllerList, error) {
|
||||
controllers := &api.ReplicationControllerList{}
|
||||
err := r.ExtractList("/registry/controllers", &controllers.Items, &controllers.ResourceVersion)
|
||||
return controllers, err
|
||||
}
|
||||
|
||||
@@ -283,9 +285,9 @@ func makeServiceKey(name string) string {
|
||||
}
|
||||
|
||||
// ListServices obtains a list of Services.
|
||||
func (r *Registry) ListServices() (api.ServiceList, error) {
|
||||
var list api.ServiceList
|
||||
err := r.ExtractList("/registry/services/specs", &list.Items)
|
||||
func (r *Registry) ListServices() (*api.ServiceList, error) {
|
||||
list := &api.ServiceList{}
|
||||
err := r.ExtractList("/registry/services/specs", &list.Items, &list.ResourceVersion)
|
||||
return list, err
|
||||
}
|
||||
|
||||
|
@@ -412,7 +412,7 @@ func TestEtcdEmptyListPods(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods) != 0 {
|
||||
if len(pods.Items) != 0 {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
}
|
||||
@@ -430,7 +430,7 @@ func TestEtcdListPodsNotFound(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods) != 0 {
|
||||
if len(pods.Items) != 0 {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
}
|
||||
@@ -465,11 +465,11 @@ func TestEtcdListPods(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(pods) != 2 || pods[0].ID != "foo" || pods[1].ID != "bar" {
|
||||
if len(pods.Items) != 2 || pods.Items[0].ID != "foo" || pods.Items[1].ID != "bar" {
|
||||
t.Errorf("Unexpected pod list: %#v", pods)
|
||||
}
|
||||
if pods[0].CurrentState.Host != "machine" ||
|
||||
pods[1].CurrentState.Host != "machine" {
|
||||
if pods.Items[0].CurrentState.Host != "machine" ||
|
||||
pods.Items[1].CurrentState.Host != "machine" {
|
||||
t.Errorf("Failed to populate host name.")
|
||||
}
|
||||
}
|
||||
@@ -487,7 +487,7 @@ func TestEtcdListControllersNotFound(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(controllers) != 0 {
|
||||
if len(controllers.Items) != 0 {
|
||||
t.Errorf("Unexpected controller list: %#v", controllers)
|
||||
}
|
||||
}
|
||||
@@ -534,7 +534,7 @@ func TestEtcdListControllers(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(controllers) != 2 || controllers[0].ID != "foo" || controllers[1].ID != "bar" {
|
||||
if len(controllers.Items) != 2 || controllers.Items[0].ID != "foo" || controllers.Items[1].ID != "bar" {
|
||||
t.Errorf("Unexpected controller list: %#v", controllers)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user