-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add async reconciler that can reconcile multiple services simultaneously
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |