digitalocean: use a safer pagination method (#7498)

this method is documented here: https://github.com/digitalocean/godo

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2020-07-02 00:13:39 +02:00 committed by GitHub
parent 578f2b7974
commit aa452d8ab4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -176,7 +176,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
func (d *Discovery) listDroplets() ([]godo.Droplet, error) {
var (
droplets []godo.Droplet
opts = &godo.ListOptions{Page: 1}
opts = &godo.ListOptions{}
)
for {
paginatedDroplets, resp, err := d.client.Droplets.List(context.Background(), opts)
@ -187,7 +187,13 @@ func (d *Discovery) listDroplets() ([]godo.Droplet, error) {
if resp.Links == nil || resp.Links.IsLastPage() {
break
}
opts.Page++
page, err := resp.Links.CurrentPage()
if err != nil {
return nil, err
}
opts.Page = page + 1
}
return droplets, nil
}