Skip to content

Commit

Permalink
Simplify List() signature in clients.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-t committed Dec 3, 2015
1 parent 800012d commit 6dcb689
Show file tree
Hide file tree
Showing 141 changed files with 532 additions and 650 deletions.
12 changes: 6 additions & 6 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
endpointcontroller "k8s.io/kubernetes/pkg/controller/endpoint"
nodecontroller "k8s.io/kubernetes/pkg/controller/node"
replicationcontroller "k8s.io/kubernetes/pkg/controller/replication"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
"k8s.io/kubernetes/pkg/kubelet/cm"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
Expand Down Expand Up @@ -273,7 +272,8 @@ func makeTempDirOrDie(prefix string, baseDir string) string {
func podsOnNodes(c *client.Client, podNamespace string, labelSelector labels.Selector) wait.ConditionFunc {
// Wait until all pods are running on the node.
return func() (bool, error) {
pods, err := c.Pods(podNamespace).List(labelSelector, fields.Everything(), unversioned.ListOptions{})
options := unversioned.ListOptions{LabelSelector: unversioned.LabelSelector{labelSelector}}
pods, err := c.Pods(podNamespace).List(options)
if err != nil {
glog.Infof("Unable to get pods to list: %v", err)
return false, nil
Expand Down Expand Up @@ -399,7 +399,7 @@ containers:
namespace := kubetypes.NamespaceDefault
if err := wait.Poll(time.Second, longTestTimeout,
podRunning(c, namespace, podName)); err != nil {
if pods, err := c.Pods(namespace).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{}); err == nil {
if pods, err := c.Pods(namespace).List(unversioned.ListOptions{}); err == nil {
for _, pod := range pods.Items {
glog.Infof("pod found: %s/%s", namespace, pod.Name)
}
Expand Down Expand Up @@ -507,7 +507,7 @@ func runSelfLinkTestOnNamespace(c *client.Client, namespace string) {
glog.Fatalf("Failed listing service with supplied self link '%v': %v", svc.SelfLink, err)
}

svcList, err := services.List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
svcList, err := services.List(unversioned.ListOptions{})
if err != nil {
glog.Fatalf("Failed listing services: %v", err)
}
Expand Down Expand Up @@ -728,7 +728,7 @@ func runPatchTest(c *client.Client) {

func runMasterServiceTest(client *client.Client) {
time.Sleep(12 * time.Second)
svcList, err := client.Services(api.NamespaceDefault).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
svcList, err := client.Services(api.NamespaceDefault).List(unversioned.ListOptions{})
if err != nil {
glog.Fatalf("Unexpected error listing services: %v", err)
}
Expand Down Expand Up @@ -855,7 +855,7 @@ func runServiceTest(client *client.Client) {
glog.Fatalf("FAILED: service in other namespace should have no endpoints: %v", err)
}

svcList, err := client.Services(api.NamespaceAll).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
svcList, err := client.Services(api.NamespaceAll).List(unversioned.ListOptions{})
if err != nil {
glog.Fatalf("Failed to list services across namespaces: %v", err)
}
Expand Down
6 changes: 2 additions & 4 deletions contrib/mesos/pkg/scheduler/components/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ import (
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/kubelet/container"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/sets"
)

Expand Down Expand Up @@ -652,7 +650,7 @@ func (k *framework) makeTaskRegistryReconciler() taskreconciler.Action {
// tasks identified by annotations in the Kubernetes pod registry.
func (k *framework) makePodRegistryReconciler() taskreconciler.Action {
return taskreconciler.Action(func(drv bindings.SchedulerDriver, cancel <-chan struct{}) <-chan error {
podList, err := k.client.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
podList, err := k.client.Pods(api.NamespaceAll).List(unversioned.ListOptions{})
if err != nil {
return proc.ErrorChanf("failed to reconcile pod registry: %v", err)
}
Expand Down Expand Up @@ -728,7 +726,7 @@ func (k *framework) explicitlyReconcileTasks(driver bindings.SchedulerDriver, ta
}

func (ks *framework) recoverTasks() error {
podList, err := ks.client.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
podList, err := ks.client.Pods(api.NamespaceAll).List(unversioned.ListOptions{})
if err != nil {
log.V(1).Infof("failed to recover pod registry, madness may ensue: %v", err)
return err
Expand Down
7 changes: 3 additions & 4 deletions contrib/mesos/pkg/service/endpoints_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
kservice "k8s.io/kubernetes/pkg/controller/endpoint"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
Expand Down Expand Up @@ -60,7 +59,7 @@ func NewEndpointController(client *client.Client) *endpointController {
e.serviceStore.Store, e.serviceController = framework.NewInformer(
&cache.ListWatch{
ListFunc: func() (runtime.Object, error) {
return e.client.Services(api.NamespaceAll).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
return e.client.Services(api.NamespaceAll).List(unversioned.ListOptions{})
},
WatchFunc: func(options unversioned.ListOptions) (watch.Interface, error) {
return e.client.Services(api.NamespaceAll).Watch(options)
Expand All @@ -80,7 +79,7 @@ func NewEndpointController(client *client.Client) *endpointController {
e.podStore.Store, e.podController = framework.NewInformer(
&cache.ListWatch{
ListFunc: func() (runtime.Object, error) {
return e.client.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
return e.client.Pods(api.NamespaceAll).List(unversioned.ListOptions{})
},
WatchFunc: func(options unversioned.ListOptions) (watch.Interface, error) {
return e.client.Pods(api.NamespaceAll).Watch(options)
Expand Down Expand Up @@ -386,7 +385,7 @@ func (e *endpointController) syncService(key string) {
// some stragglers could have been left behind if the endpoint controller
// reboots).
func (e *endpointController) checkLeftoverEndpoints() {
list, err := e.client.Endpoints(api.NamespaceAll).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
list, err := e.client.Endpoints(api.NamespaceAll).List(unversioned.ListOptions{})
if err != nil {
glog.Errorf("Unable to list endpoints (%v); orphaned endpoints will not be cleaned up. (They're pretty harmless, but you can restart this component if you want another attempt made.)", err)
return
Expand Down
12 changes: 5 additions & 7 deletions pkg/client/unversioned/componentstatuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package unversioned

import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/api/unversioned"
)

type ComponentStatusesInterface interface {
Expand All @@ -28,11 +27,11 @@ type ComponentStatusesInterface interface {

// ComponentStatusInterface contains methods to retrieve ComponentStatus
type ComponentStatusInterface interface {
List(label labels.Selector, field fields.Selector) (*api.ComponentStatusList, error)
List(opts unversioned.ListOptions) (*api.ComponentStatusList, error)
Get(name string) (*api.ComponentStatus, error)

// TODO: It'd be nice to have watch support at some point
//Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
//Watch(opts unversioned.ListOptions) (watch.Interface, error)
}

// componentStatuses implements ComponentStatusesInterface
Expand All @@ -44,12 +43,11 @@ func newComponentStatuses(c *Client) *componentStatuses {
return &componentStatuses{c}
}

func (c *componentStatuses) List(label labels.Selector, field fields.Selector) (result *api.ComponentStatusList, err error) {
func (c *componentStatuses) List(opts unversioned.ListOptions) (result *api.ComponentStatusList, err error) {
result = &api.ComponentStatusList{}
err = c.client.Get().
Resource("componentStatuses").
LabelsSelectorParam(label).
FieldsSelectorParam(field).
VersionedParams(&opts, api.Scheme).
Do().
Into(result)

Expand Down
8 changes: 3 additions & 5 deletions pkg/client/unversioned/daemon_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
)

Expand All @@ -31,7 +29,7 @@ type DaemonSetsNamespacer interface {
}

type DaemonSetInterface interface {
List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (*extensions.DaemonSetList, error)
List(opts unversioned.ListOptions) (*extensions.DaemonSetList, error)
Get(name string) (*extensions.DaemonSet, error)
Create(ctrl *extensions.DaemonSet) (*extensions.DaemonSet, error)
Update(ctrl *extensions.DaemonSet) (*extensions.DaemonSet, error)
Expand All @@ -53,9 +51,9 @@ func newDaemonSets(c *ExtensionsClient, namespace string) *daemonSets {
// Ensure statically that daemonSets implements DaemonSetsInterface.
var _ DaemonSetInterface = &daemonSets{}

func (c *daemonSets) List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (result *extensions.DaemonSetList, err error) {
func (c *daemonSets) List(opts unversioned.ListOptions) (result *extensions.DaemonSetList, err error) {
result = &extensions.DaemonSetList{}
err = c.r.Get().Namespace(c.ns).Resource("daemonsets").VersionedParams(&opts, api.Scheme).LabelsSelectorParam(label).FieldsSelectorParam(field).Do().Into(result)
err = c.r.Get().Namespace(c.ns).Resource("daemonsets").VersionedParams(&opts, api.Scheme).Do().Into(result)
return
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/client/unversioned/daemon_sets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)

func getDSResourceName() string {
Expand Down Expand Up @@ -57,7 +55,7 @@ func TestListDaemonSets(t *testing.T) {
},
},
}
receivedDSs, err := c.Setup(t).Extensions().DaemonSets(ns).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
receivedDSs, err := c.Setup(t).Extensions().DaemonSets(ns).List(unversioned.ListOptions{})
c.Validate(t, receivedDSs, err)

}
Expand Down
8 changes: 3 additions & 5 deletions pkg/client/unversioned/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
)

Expand All @@ -32,7 +30,7 @@ type DeploymentsNamespacer interface {

// DeploymentInterface has methods to work with Deployment resources.
type DeploymentInterface interface {
List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (*extensions.DeploymentList, error)
List(opts unversioned.ListOptions) (*extensions.DeploymentList, error)
Get(name string) (*extensions.Deployment, error)
Delete(name string, options *api.DeleteOptions) error
Create(*extensions.Deployment) (*extensions.Deployment, error)
Expand All @@ -56,9 +54,9 @@ func newDeployments(c *ExtensionsClient, namespace string) *deployments {
}

// List takes label and field selectors, and returns the list of Deployments that match those selectors.
func (c *deployments) List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (result *extensions.DeploymentList, err error) {
func (c *deployments) List(opts unversioned.ListOptions) (result *extensions.DeploymentList, err error) {
result = &extensions.DeploymentList{}
err = c.client.Get().Namespace(c.ns).Resource("deployments").VersionedParams(&opts, api.Scheme).LabelsSelectorParam(label).FieldsSelectorParam(field).Do().Into(result)
err = c.client.Get().Namespace(c.ns).Resource("deployments").VersionedParams(&opts, api.Scheme).Do().Into(result)
return
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/client/unversioned/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)

func getDeploymentsResoureName() string {
Expand Down Expand Up @@ -100,7 +98,7 @@ func TestDeploymentList(t *testing.T) {
},
Response: Response{StatusCode: 200, Body: deploymentList},
}
response, err := c.Setup(t).Deployments(ns).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
response, err := c.Setup(t).Deployments(ns).List(unversioned.ListOptions{})
c.Validate(t, response, err)
}

Expand Down
8 changes: 2 additions & 6 deletions pkg/client/unversioned/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
)

Expand All @@ -34,7 +32,7 @@ type EndpointsNamespacer interface {
// EndpointsInterface has methods to work with Endpoints resources
type EndpointsInterface interface {
Create(endpoints *api.Endpoints) (*api.Endpoints, error)
List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (*api.EndpointsList, error)
List(opts unversioned.ListOptions) (*api.EndpointsList, error)
Get(name string) (*api.Endpoints, error)
Delete(name string) error
Update(endpoints *api.Endpoints) (*api.Endpoints, error)
Expand All @@ -60,14 +58,12 @@ func (c *endpoints) Create(endpoints *api.Endpoints) (*api.Endpoints, error) {
}

// List takes a selector, and returns the list of endpoints that match that selector
func (c *endpoints) List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (result *api.EndpointsList, err error) {
func (c *endpoints) List(opts unversioned.ListOptions) (result *api.EndpointsList, err error) {
result = &api.EndpointsList{}
err = c.r.Get().
Namespace(c.ns).
Resource("endpoints").
VersionedParams(&opts, api.Scheme).
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Do().
Into(result)
return
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/unversioned/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)

func TestListEndpoints(t *testing.T) {
Expand All @@ -44,7 +42,7 @@ func TestListEndpoints(t *testing.T) {
},
},
}
receivedEndpointsList, err := c.Setup(t).Endpoints(ns).List(labels.Everything(), fields.Everything(), unversioned.ListOptions{})
receivedEndpointsList, err := c.Setup(t).Endpoints(ns).List(unversioned.ListOptions{})
c.Validate(t, receivedEndpointsList, err)
}

Expand Down
9 changes: 3 additions & 6 deletions pkg/client/unversioned/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/watch"
)
Expand All @@ -37,7 +36,7 @@ type EventInterface interface {
Create(event *api.Event) (*api.Event, error)
Update(event *api.Event) (*api.Event, error)
Patch(event *api.Event, data []byte) (*api.Event, error)
List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (*api.EventList, error)
List(opts unversioned.ListOptions) (*api.EventList, error)
Get(name string) (*api.Event, error)
Watch(opts unversioned.ListOptions) (watch.Interface, error)
// Search finds events about the specified object
Expand Down Expand Up @@ -117,14 +116,12 @@ func (e *events) Patch(incompleteEvent *api.Event, data []byte) (*api.Event, err
}

// List returns a list of events matching the selectors.
func (e *events) List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (*api.EventList, error) {
func (e *events) List(opts unversioned.ListOptions) (*api.EventList, error) {
result := &api.EventList{}
err := e.client.Get().
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
Resource("events").
VersionedParams(&opts, api.Scheme).
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Do().
Into(result)
return result, err
Expand Down Expand Up @@ -174,7 +171,7 @@ func (e *events) Search(objOrRef runtime.Object) (*api.EventList, error) {
refUID = &stringRefUID
}
fieldSelector := e.GetFieldSelector(&ref.Name, &ref.Namespace, refKind, refUID)
return e.List(labels.Everything(), fieldSelector, unversioned.ListOptions{})
return e.List(unversioned.ListOptions{FieldSelector: unversioned.FieldSelector{fieldSelector}})
}

// Delete deletes an existing event.
Expand Down
5 changes: 1 addition & 4 deletions pkg/client/unversioned/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)

func TestEventSearch(t *testing.T) {
Expand Down Expand Up @@ -166,8 +164,7 @@ func TestEventList(t *testing.T) {
},
Response: Response{StatusCode: 200, Body: eventList},
}
response, err := c.Setup(t).Events(ns).List(labels.Everything(),
fields.Everything(), unversioned.ListOptions{})
response, err := c.Setup(t).Events(ns).List(unversioned.ListOptions{})

if err != nil {
t.Errorf("%#v should be nil.", err)
Expand Down
8 changes: 3 additions & 5 deletions pkg/client/unversioned/horizontalpodautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
)

Expand All @@ -32,7 +30,7 @@ type HorizontalPodAutoscalersNamespacer interface {

// HorizontalPodAutoscalerInterface has methods to work with HorizontalPodAutoscaler resources.
type HorizontalPodAutoscalerInterface interface {
List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (*extensions.HorizontalPodAutoscalerList, error)
List(opts unversioned.ListOptions) (*extensions.HorizontalPodAutoscalerList, error)
Get(name string) (*extensions.HorizontalPodAutoscaler, error)
Delete(name string, options *api.DeleteOptions) error
Create(horizontalPodAutoscaler *extensions.HorizontalPodAutoscaler) (*extensions.HorizontalPodAutoscaler, error)
Expand All @@ -56,9 +54,9 @@ func newHorizontalPodAutoscalers(c *ExtensionsClient, namespace string) *horizon
}

// List takes label and field selectors, and returns the list of horizontalPodAutoscalers that match those selectors.
func (c *horizontalPodAutoscalers) List(label labels.Selector, field fields.Selector, opts unversioned.ListOptions) (result *extensions.HorizontalPodAutoscalerList, err error) {
func (c *horizontalPodAutoscalers) List(opts unversioned.ListOptions) (result *extensions.HorizontalPodAutoscalerList, err error) {
result = &extensions.HorizontalPodAutoscalerList{}
err = c.client.Get().Namespace(c.ns).Resource("horizontalPodAutoscalers").VersionedParams(&opts, api.Scheme).LabelsSelectorParam(label).FieldsSelectorParam(field).Do().Into(result)
err = c.client.Get().Namespace(c.ns).Resource("horizontalPodAutoscalers").VersionedParams(&opts, api.Scheme).Do().Into(result)
return
}

Expand Down
Loading

0 comments on commit 6dcb689

Please sign in to comment.