From cee69d8d5a51f043526b967ce7b3383a436be975 Mon Sep 17 00:00:00 2001 From: Alan Date: Tue, 21 May 2024 12:15:56 +0200 Subject: [PATCH] fix(layer): issues with parallel deletes --- internal/controllers/terraformlayer/run.go | 33 ++-------------------- 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/internal/controllers/terraformlayer/run.go b/internal/controllers/terraformlayer/run.go index a2b4f26d..4933a7af 100644 --- a/internal/controllers/terraformlayer/run.go +++ b/internal/controllers/terraformlayer/run.go @@ -4,11 +4,9 @@ import ( "context" "fmt" "strings" - "sync" configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1" "github.com/padok-team/burrito/internal/annotations" - log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/selection" @@ -89,35 +87,10 @@ func (r *Reconciler) getAllRuns(ctx context.Context, layer *configv1alpha1.Terra } func deleteAll(ctx context.Context, c client.Client, objs []*configv1alpha1.TerraformRun) error { - var wg sync.WaitGroup - errorCh := make(chan error, len(objs)) - - deleteObject := func(obj *configv1alpha1.TerraformRun) { - defer wg.Done() - err := c.Delete(ctx, obj) - if err != nil { - errorCh <- fmt.Errorf("error deleting %s: %v", obj.Name, err) - } else { - log.Infof("deleted run %s", obj.Name) - } - } - for _, obj := range objs { - wg.Add(1) - go deleteObject(obj) - } - - go func() { - wg.Wait() - close(errorCh) - }() - - var ret error = nil - for err := range errorCh { - if err != nil { - ret = err + if err := c.Delete(ctx, obj); err != nil { + return err } } - - return ret + return nil }