Skip to content

Commit

Permalink
Rename ListPods methods to List.
Browse files Browse the repository at this point in the history
For greater similarity to pkg/client.
Does not cover registry's ListPods.
Fix an example in a comment.
  • Loading branch information
erictune committed Jan 10, 2015
1 parent 6cd3763 commit 00c0505
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
11 changes: 6 additions & 5 deletions pkg/client/cache/listers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ import (
//
// Example:
// s := cache.NewStore()
// XXX NewReflector(... s ...)
// lw := cache.ListWatch{Client: c, FieldSelector: sel, Resource: "pods"}
// r := cache.NewReflector(lw, &api.Pod{}, s).Run()
// l := StoreToPodLister{s}
// l.List()
type StoreToPodLister struct {
Store
}

// TODO Get rid of the selector because that is confusing because the user might not realize that there has already been
// some selection at the caching stage. Also, consistency will facilitate code generation.
// TODO: Rename to List() instead of ListPods() for consistency with other resources and with pkg/client..
func (s *StoreToPodLister) ListPods(selector labels.Selector) (pods []api.Pod, err error) {
for _, m := range s.List() {
// some selection at the caching stage. Also, consistency will facilitate code generation. However, the pkg/client
// is inconsistent too.
func (s *StoreToPodLister) List(selector labels.Selector) (pods []api.Pod, err error) {
for _, m := range s.Store.List() {
pod := m.(*api.Pod)
if selector.Matches(labels.Set(pod.Labels)) {
pods = append(pods, *pod)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/cache/listers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestStoreToPodLister(t *testing.T) {
spl := StoreToPodLister{store}

for _, id := range ids {
got, err := spl.ListPods(labels.Set{"name": id}.AsSelector())
got, err := spl.List(labels.Set{"name": id}.AsSelector())
if err != nil {
t.Errorf("Unexpected error: %v", err)
continue
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Most consumers should use the Config object to create a Client:
if err != nil {
// handle error
}
client.ListPods()
client.Pods(ns).List()
More advanced consumers may wish to provide their own transport via a http.RoundTripper:
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newPods(c *Client, namespace string) *pods {
}
}

// ListPods takes a selector, and returns the list of pods that match that selector.
// List takes a selector, and returns the list of pods that match that selector.
func (c *pods) List(selector labels.Selector) (result *api.PodList, err error) {
result = &api.PodList{}
err = c.r.Get().Namespace(c.ns).Resource("pods").SelectorParam("labels", selector).Do().Into(result)
Expand Down
2 changes: 1 addition & 1 deletion pkg/clientauth/clientauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Example:
clientConfig.Host = "example.com:4901"
clientConfig = info.MergeWithConfig()
client := client.New(clientConfig)
client.ListPods()
client.Pods(ns).List()
*/
package clientauth

Expand Down
8 changes: 4 additions & 4 deletions pkg/scheduler/listers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func (f FakeMinionLister) List() (api.NodeList, error) {

// PodLister interface represents anything that can list pods for a scheduler.
type PodLister interface {
// TODO: make this exactly the same as client's ListPods() method...
ListPods(labels.Selector) ([]api.Pod, error)
// TODO: make this exactly the same as client's Pods(ns).List() method, by returning a api.PodList
List(labels.Selector) ([]api.Pod, error)
}

// FakePodLister implements PodLister on an []api.Pods for test purposes.
type FakePodLister []api.Pod

// ListPods returns []api.Pod matching a query.
func (f FakePodLister) ListPods(s labels.Selector) (selected []api.Pod, err error) {
// List returns []api.Pod matching a query.
func (f FakePodLister) List(s labels.Selector) (selected []api.Pod, err error) {
for _, pod := range f {
if s.Matches(labels.Set(pod.Labels)) {
selected = append(selected, pod)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func getUsedPorts(pods ...api.Pod) map[int]bool {
func MapPodsToMachines(lister PodLister) (map[string][]api.Pod, error) {
machineToPods := map[string][]api.Pod{}
// TODO: perform more targeted query...
pods, err := lister.ListPods(labels.Everything())
pods, err := lister.List(labels.Everything())
if err != nil {
return map[string][]api.Pod{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/spreading.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// may not provide optimal spreading for the members of that Service.
// TODO: consider if we want to include Service label sets in the scheduling priority.
func CalculateSpreadPriority(pod api.Pod, podLister PodLister, minionLister MinionLister) (HostPriorityList, error) {
pods, err := podLister.ListPods(labels.SelectorFromSet(pod.Labels))
pods, err := podLister.List(labels.SelectorFromSet(pod.Labels))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 00c0505

Please sign in to comment.