From 90c744fc9ee23d8a18dad96f2a677a9d1a54222c Mon Sep 17 00:00:00 2001 From: Vladimir Ermakov Date: Tue, 13 Feb 2024 12:29:43 +0100 Subject: [PATCH] use ParseOption, pass context to servers listing --- provider.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/provider.go b/provider.go index 1dbc947..fe80ba8 100644 --- a/provider.go +++ b/provider.go @@ -5,7 +5,6 @@ import ( "context" "errors" "fmt" - "os" "path" "sync/atomic" "time" @@ -42,12 +41,12 @@ type InstanceGroup struct { } func (g *InstanceGroup) Init(ctx context.Context, log hclog.Logger, settings provider.Settings) (provider.ProviderInfo, error) { - // XXX clouds.WithLocations() hard to make conditional, as cloudOpts unexported and there no type suitable to make array + pOpts := []clouds.ParseOption{clouds.WithCloudName(g.Cloud)} if g.CloudsConfig != "" { - os.Setenv("OS_CLIENT_CONFIG_FILE", g.CloudsConfig) + pOpts = append(pOpts, clouds.WithLocations(g.CloudsConfig)) } - ao, eo, tlsCfg, err := clouds.Parse(clouds.WithCloudName(g.Cloud)) + ao, eo, tlsCfg, err := clouds.Parse(pOpts...) if err != nil { return provider.ProviderInfo{}, fmt.Errorf("Failed to parse clouds.yaml: %w", err) } @@ -188,7 +187,7 @@ func (g *InstanceGroup) Decrease(ctx context.Context, instances []string) (succe } func (g *InstanceGroup) getInstances(ctx context.Context, initial bool) ([]servers.Server, error) { - page, err := servers.List(g.computeClient, nil).AllPages() + page, err := servers.List(g.computeClient, nil).AllPagesWithContext(ctx) if err != nil { return nil, fmt.Errorf("Server listing error: %w", err) }