Skip to content

Commit

Permalink
use the main context when (re)creating Azure client
Browse files Browse the repository at this point in the history
  • Loading branch information
christeredvartsen committed Feb 16, 2024
1 parent 68802bc commit 5ddfc87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/reconciler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func run(ctx context.Context, cfg *Config, log logrus.FieldLogger) error {

reconcilerManager := reconcilers.NewManager(ctx, client, cfg.ReconcilersToEnable, cfg.PubSub.SubscriptionID, cfg.PubSub.ProjectID, log)

azureGroupReconciler := azure_group_reconciler.New(cfg.TenantDomain, cfg.Azure.GroupNamePrefix)
azureGroupReconciler := azure_group_reconciler.New(ctx, cfg.TenantDomain, cfg.Azure.GroupNamePrefix)

githubReconciler, err := github_team_reconciler.New(ctx, cfg.GitHub.Organization, cfg.GitHub.AuthEndpoint, cfg.GoogleManagementProjectID)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions internal/reconcilers/azure/group/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (
)

type azureGroupReconciler struct {
domain string
mainCtx context.Context
domain string

lock sync.RWMutex
lastUpdated time.Time
Expand All @@ -56,8 +57,9 @@ func WithAzureClient(client azureclient.Client) OptFunc {
}
}

func New(domain, azureGroupPrefix string, opts ...OptFunc) reconcilers.Reconciler {
func New(ctx context.Context, domain, azureGroupPrefix string, opts ...OptFunc) reconcilers.Reconciler {
r := &azureGroupReconciler{
mainCtx: ctx,
domain: domain,
azureGroupPrefix: azureGroupPrefix,
}
Expand Down Expand Up @@ -286,7 +288,7 @@ func (r *azureGroupReconciler) updateClient(ctx context.Context, client *apiclie
return nil
}

aclient := conf.Client(ctx)
aclient := conf.Client(r.mainCtx)
aclient.Transport = otelhttp.NewTransport(aclient.Transport)
r.lockedAzureClient = azureclient.New(aclient)
r.lastConfig = conf
Expand Down
16 changes: 8 additions & 8 deletions internal/reconcilers/azure/group/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestAzureReconciler_Reconcile(t *testing.T) {
Once()

err := azure_group_reconciler.
New(domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
New(ctx, domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
Reconcile(ctx, client, team, log)
if err != nil {
t.Errorf("unexpected error: %s", err)
Expand All @@ -129,7 +129,7 @@ func TestAzureReconciler_Reconcile(t *testing.T) {
Once()

err := azure_group_reconciler.
New(domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
New(ctx, domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
Reconcile(ctx, client, team, log)

if err == nil {
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestAzureReconciler_Reconcile(t *testing.T) {
Once()

err := azure_group_reconciler.
New(domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
New(ctx, domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
Reconcile(ctx, client, team, log)

if err == nil {
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestAzureReconciler_Reconcile(t *testing.T) {
Once()

err := azure_group_reconciler.
New(domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
New(ctx, domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
Reconcile(ctx, client, team, log)
if err != nil {
t.Errorf("unexpected error: %s", err)
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestAzureReconciler_Reconcile(t *testing.T) {
Once()

err := azure_group_reconciler.
New(domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
New(ctx, domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(mockClient)).
Reconcile(ctx, client, team, log)
if err != nil {
t.Errorf("unexpected error: %s", err)
Expand All @@ -256,7 +256,7 @@ func TestAzureReconciler_Delete(t *testing.T) {
client, _ := apiclient.NewMockClient(t)

err := azure_group_reconciler.
New(domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(azureClient)).
New(ctx, domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(azureClient)).
Delete(ctx, client, &protoapi.Team{Slug: "some-slug"}, log)
if err != nil {
t.Errorf("unexpected error: %s", err)
Expand All @@ -273,7 +273,7 @@ func TestAzureReconciler_Delete(t *testing.T) {
Once()

err := azure_group_reconciler.
New(domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(azureClient)).
New(ctx, domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(azureClient)).
Delete(ctx, client, team, log)

if !strings.Contains(err.Error(), "delete Azure AD group with ID") {
Expand All @@ -297,7 +297,7 @@ func TestAzureReconciler_Delete(t *testing.T) {
Once()

err := azure_group_reconciler.
New(domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(azureClient)).
New(ctx, domain, groupNamePrefix, azure_group_reconciler.WithAzureClient(azureClient)).
Delete(ctx, client, team, log)
if err != nil {
t.Errorf("unexpected error: %s", err)
Expand Down

0 comments on commit 5ddfc87

Please sign in to comment.