mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 11:27:32 +00:00
Remove the use of error channel from go routine
This commit is contained in:
@@ -33,40 +33,24 @@ func (r *InfisicalSecretReconciler) ReconcileDeploymentsWithManagedSecrets(ctx c
|
|||||||
return 0, fmt.Errorf("unable to fetch Kubernetes secret to update deployment: %v", err)
|
return 0, fmt.Errorf("unable to fetch Kubernetes secret to update deployment: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a channel to receive errors from goroutines
|
var wg sync.WaitGroup
|
||||||
errChan := make(chan error, len(listOfDeployments.Items))
|
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
wg.Add(len(listOfDeployments.Items))
|
|
||||||
go func() {
|
|
||||||
wg.Wait()
|
|
||||||
close(errChan)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Iterate over the deployments and check if they use the managed secret
|
// Iterate over the deployments and check if they use the managed secret
|
||||||
for _, deployment := range listOfDeployments.Items {
|
for _, deployment := range listOfDeployments.Items {
|
||||||
if deployment.Annotations[AUTO_RELOAD_DEPLOYMENT_ANNOTATION] == "true" && r.IsDeploymentUsingManagedSecret(deployment, infisicalSecret) {
|
if deployment.Annotations[AUTO_RELOAD_DEPLOYMENT_ANNOTATION] == "true" && r.IsDeploymentUsingManagedSecret(deployment, infisicalSecret) {
|
||||||
// Start a goroutine to reconcile the deployment
|
// Start a goroutine to reconcile the deployment
|
||||||
|
wg.Add(1)
|
||||||
go func(d v1.Deployment, s corev1.Secret) {
|
go func(d v1.Deployment, s corev1.Secret) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := r.ReconcileDeployment(ctx, d, s); err != nil {
|
if err := r.ReconcileDeployment(ctx, d, s); err != nil {
|
||||||
errChan <- err
|
fmt.Printf("unable to reconcile deployment with [name=%v]. Will try next requeue", deployment.ObjectMeta.Name)
|
||||||
}
|
}
|
||||||
}(deployment, *managedKubeSecret)
|
}(deployment, *managedKubeSecret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect any errors that were sent through the channel
|
wg.Wait()
|
||||||
var errs []error
|
|
||||||
for err := range errChan {
|
|
||||||
errs = append(errs, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(errs) > 0 {
|
return 0, nil
|
||||||
return 0, fmt.Errorf("unable to reconcile some deployments: %v", errs)
|
|
||||||
}
|
|
||||||
|
|
||||||
return len(listOfDeployments.Items), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the deployment uses managed secrets
|
// Check if the deployment uses managed secrets
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ func (r *InfisicalSecretReconciler) Reconcile(ctx context.Context, req ctrl.Requ
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sync again after the specified time
|
// Sync again after the specified time
|
||||||
|
fmt.Printf("Operator will requeue after [%v] \n", requeueTime)
|
||||||
return ctrl.Result{
|
return ctrl.Result{
|
||||||
RequeueAfter: requeueTime,
|
RequeueAfter: requeueTime,
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user