From 73f09f389eb33f3a194f0ee30b107bd1d3cd2b5e Mon Sep 17 00:00:00 2001 From: Martin Baillie Date: Tue, 18 Apr 2017 12:01:11 +1000 Subject: [PATCH] Fix Rancher API pagination limits This fix allows the Traefik Rancher provider to obtain a complete view of the environments, services and containers being managed by the Rancher deployment. --- provider/rancher.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/provider/rancher.go b/provider/rancher.go index 3b2b95e8b..6863293e6 100644 --- a/provider/rancher.go +++ b/provider/rancher.go @@ -25,6 +25,10 @@ const ( RancherDefaultWatchTime = 15 * time.Second ) +var ( + withoutPagination *rancher.ListOpts +) + var _ Provider = (*Rancher)(nil) // Rancher holds configurations of the Rancher provider. @@ -44,6 +48,12 @@ type rancherData struct { Health string } +func init() { + withoutPagination = &rancher.ListOpts{ + Filters: map[string]interface{}{"limit": 0}, + } +} + func (r rancherData) String() string { return fmt.Sprintf("{name:%s, labels:%v, containers: %v, health: %s}", r.Name, r.Labels, r.Containers, r.Health) } @@ -290,7 +300,7 @@ func listRancherEnvironments(client *rancher.RancherClient) []*rancher.Environme var environmentList = []*rancher.Environment{} - environments, err := client.Environment.List(nil) + environments, err := client.Environment.List(withoutPagination) if err != nil { log.Errorf("Cannot get Rancher Environments %+v", err) @@ -307,7 +317,7 @@ func listRancherServices(client *rancher.RancherClient) []*rancher.Service { var servicesList = []*rancher.Service{} - services, err := client.Service.List(nil) + services, err := client.Service.List(withoutPagination) if err != nil { log.Errorf("Cannot get Rancher Services %+v", err) @@ -324,7 +334,7 @@ func listRancherContainer(client *rancher.RancherClient) []*rancher.Container { containerList := []*rancher.Container{} - container, err := client.Container.List(nil) + container, err := client.Container.List(withoutPagination) log.Debugf("first container len: %i", len(container.Data))