discovery/digitalocean: make do api be aware of discovery context. (#10281)

Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
johncming 2022-02-11 16:23:51 +08:00 committed by GitHub
parent 579331446a
commit 37c6ef9661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -138,7 +138,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
Source: "DigitalOcean",
}
droplets, err := d.listDroplets()
droplets, err := d.listDroplets(ctx)
if err != nil {
return nil, err
}
@ -196,13 +196,13 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
return []*targetgroup.Group{tg}, nil
}
func (d *Discovery) listDroplets() ([]godo.Droplet, error) {
func (d *Discovery) listDroplets(ctx context.Context) ([]godo.Droplet, error) {
var (
droplets []godo.Droplet
opts = &godo.ListOptions{}
)
for {
paginatedDroplets, resp, err := d.client.Droplets.List(context.Background(), opts)
paginatedDroplets, resp, err := d.client.Droplets.List(ctx, opts)
if err != nil {
return nil, fmt.Errorf("error while listing droplets page %d: %w", opts.Page, err)
}