From a948b6e1d0aaeb557b419da58fd74e5557c27ceb Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Thu, 28 May 2020 10:16:42 +0200 Subject: [PATCH] Remove azure resourceGroupClient from backend initialisation. Several advantages : - less dependencies to init backend. (Will need to work more on this to make login command not need an existing subscription ID) - backend does not get login token at init time. For a long running process (grace server) this would cause issues with token lifetime - we benefit from the client config (polling options especially) set in aci.go, without duplicating stuff --- azure/backend.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/azure/backend.go b/azure/backend.go index 5f678d524..4b249d5da 100644 --- a/azure/backend.go +++ b/azure/backend.go @@ -46,22 +46,17 @@ func New(ctx context.Context) (backend.Service, error) { return nil, err } - auth, _ := login.NewAuthorizerFromLogin() - containerGroupsClient := containerinstance.NewContainerGroupsClient(aciContext.SubscriptionID) - containerGroupsClient.Authorizer = auth - - return getAciAPIService(containerGroupsClient, aciContext) + return getAciAPIService(aciContext) } -func getAciAPIService(cgc containerinstance.ContainerGroupsClient, aciCtx store.AciContext) (*aciAPIService, error) { +func getAciAPIService(aciCtx store.AciContext) (*aciAPIService, error) { service, err := login.NewAzureLoginService() if err != nil { return nil, err } return &aciAPIService{ aciContainerService: aciContainerService{ - containerGroupsClient: cgc, - ctx: aciCtx, + ctx: aciCtx, }, aciComposeService: aciComposeService{ ctx: aciCtx, @@ -91,13 +86,16 @@ func (a *aciAPIService) CloudService() cloud.Service { } type aciContainerService struct { - containerGroupsClient containerinstance.ContainerGroupsClient - ctx store.AciContext + ctx store.AciContext } func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.Container, error) { + groupsClient, err := getContainerGroupsClient(cs.ctx.SubscriptionID) + if err != nil { + return nil, err + } var containerGroups []containerinstance.ContainerGroup - result, err := cs.containerGroupsClient.ListByResourceGroup(ctx, cs.ctx.ResourceGroup) + result, err := groupsClient.ListByResourceGroup(ctx, cs.ctx.ResourceGroup) if err != nil { return []containers.Container{}, err } @@ -111,7 +109,7 @@ func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.C var res []containers.Container for _, containerGroup := range containerGroups { - group, err := cs.containerGroupsClient.Get(ctx, cs.ctx.ResourceGroup, *containerGroup.Name) + group, err := groupsClient.Get(ctx, cs.ctx.ResourceGroup, *containerGroup.Name) if err != nil { return []containers.Container{}, err }