Skip to content

Commit

Permalink
Use given context
Browse files Browse the repository at this point in the history
  • Loading branch information
baurmatt committed Dec 10, 2024
1 parent 01234f4 commit 7b4fb49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions internal/openstackclient/openstackclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ type client struct {
image *gophercloud.ServiceClient
}

func New(authConfig AuthConfig) (Client, error) {
func New(ctx context.Context, authConfig AuthConfig) (Client, error) {
if authConfig.NovaMicroversion == "" {
authConfig.NovaMicroversion = "2.79" // Train+
}

providerClient, endpointOps, err := newProviderClient(authConfig)
providerClient, endpointOps, err := newProviderClient(ctx, authConfig)
if err != nil {
return nil, err
}
Expand All @@ -81,7 +81,7 @@ func New(authConfig AuthConfig) (Client, error) {
return nil, err
}

_computeClient, err := utils.RequireMicroversion(context.TODO(), *computeClient, authConfig.NovaMicroversion)
_computeClient, err := utils.RequireMicroversion(ctx, *computeClient, authConfig.NovaMicroversion)
if err != nil {
return nil, fmt.Errorf("failed to request microversion %s for OpenStack Nova: %w", authConfig.NovaMicroversion, err)
}
Expand All @@ -99,7 +99,7 @@ func New(authConfig AuthConfig) (Client, error) {
}, nil
}

func newProviderClient(authConfig AuthConfig) (*gophercloud.ProviderClient, gophercloud.EndpointOpts, error) {
func newProviderClient(ctx context.Context, authConfig AuthConfig) (*gophercloud.ProviderClient, gophercloud.EndpointOpts, error) {
var endpointOps gophercloud.EndpointOpts
var authOptions gophercloud.AuthOptions
var providerClient *gophercloud.ProviderClient
Expand All @@ -113,7 +113,7 @@ func newProviderClient(authConfig AuthConfig) (*gophercloud.ProviderClient, goph
}
authOptions.AllowReauth = true

providerClient, err = openstack.AuthenticatedClient(context.Background(), authOptions)
providerClient, err = openstack.AuthenticatedClient(ctx, authOptions)
if err != nil {
return nil, gophercloud.EndpointOpts{}, fmt.Errorf("failed to connect to OpenStack Keystone: %w", err)
}
Expand All @@ -133,7 +133,7 @@ func newProviderClient(authConfig AuthConfig) (*gophercloud.ProviderClient, goph
// plugin is a long running process. force allow reauth
authOptions.AllowReauth = true

providerClient, err = config.NewProviderClient(context.TODO(), authOptions, config.WithTLSConfig(tlsCfg))
providerClient, err = config.NewProviderClient(ctx, authOptions, config.WithTLSConfig(tlsCfg))
if err != nil {
return nil, gophercloud.EndpointOpts{}, fmt.Errorf("failed to connect to OpenStack Keystone: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (g *InstanceGroup) Init(ctx context.Context, log hclog.Logger, settings pro
g.log.Debug("Initializing fleeting-plugin-openstack")

var err error
g.client, err = newClient(openstackclient.AuthConfig{
g.client, err = newClient(ctx, openstackclient.AuthConfig{
AuthFromEnv: g.AuthFromEnv,
Cloud: g.Cloud,
CloudsConfig: g.CloudsConfig,
Expand Down

0 comments on commit 7b4fb49

Please sign in to comment.