Skip to content

Commit

Permalink
add async reconciler that can reconcile multiple services simultaneously
Browse files Browse the repository at this point in the history
  • Loading branch information
shysank committed May 4, 2021
1 parent 660a35f commit bcb51e3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions controllers/async_reconciler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package controllers

import (
"context"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"sigs.k8s.io/cluster-api-provider-azure/azure"
)

type asyncReconciler struct {
results chan error
}

func NewAsyncReconciler() asyncReconciler {
return asyncReconciler{}
}

func (ar *asyncReconciler) submit(ctx context.Context, task azure.Reconciler) {
go func() {
ar.results <- task.Reconcile(ctx)

}()
}

func (ar *asyncReconciler) wait() error {
var errs []error
for r := range ar.results {
if r != nil {
errs = append(errs, r)
}
}

if len(errs) > 0 {
return kerrors.NewAggregate(errs)
}

return nil
}

0 comments on commit bcb51e3

Please sign in to comment.