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
This commit is contained in:
Guillaume Tardif 2020-05-28 10:16:42 +02:00
parent e630ace677
commit a948b6e1d0
1 changed files with 10 additions and 12 deletions

View File

@ -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
}