Skip to content

Commit

Permalink
fix: delete plugins in parallel to avoid hitting timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-ibra committed Nov 30, 2023
1 parent 3ae7b70 commit 866b478
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions internal/controller/validatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/base64"
"fmt"
"strings"
"sync"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -273,19 +274,45 @@ func getPluginHashKey(pluginName string) string {

// deletePlugins deletes each validator plugin's Helm release
func (r *ValidatorConfigReconciler) deletePlugins(ctx context.Context, vc *v1alpha1.ValidatorConfig) error {
fmt.Println()
fmt.Println()
fmt.Println("deletePlugins called")
fmt.Println()
var wg sync.WaitGroup
errChan := make(chan error, len(vc.Spec.Plugins))

for _, p := range vc.Spec.Plugins {
release, err := r.HelmSecretsClient.Get(ctx, p.Chart.Name, vc.Namespace)
if err != nil {
if !apierrs.IsNotFound(err) {
return err
wg.Add(1)

go func(p v1alpha1.HelmRelease) {
defer wg.Done()
fmt.Println("goroutine called for plugin: ", p.Chart.Name)

release, err := r.HelmSecretsClient.Get(ctx, p.Chart.Name, vc.Namespace)
if err != nil {
if !apierrs.IsNotFound(err) {
errChan <- err
}
return

Check warning on line 296 in internal/controller/validatorconfig_controller.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/validatorconfig_controller.go#L293-L296

Added lines #L293 - L296 were not covered by tests
}
return nil
}
if release.Secret.Labels == nil || release.Secret.Labels["owner"] != "helm" {
return nil
if release.Secret.Labels == nil || release.Secret.Labels["owner"] != "helm" {
return
}

Check warning on line 300 in internal/controller/validatorconfig_controller.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/validatorconfig_controller.go#L299-L300

Added lines #L299 - L300 were not covered by tests
r.deletePlugin(vc, p.Chart.Name)
}(p)
}

go func() {
wg.Wait()
close(errChan)
}()

for err := range errChan {
if err != nil {
return err

Check warning on line 312 in internal/controller/validatorconfig_controller.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/validatorconfig_controller.go#L311-L312

Added lines #L311 - L312 were not covered by tests
}
r.deletePlugin(vc, p.Chart.Name)
}

return nil
}

Expand Down

0 comments on commit 866b478

Please sign in to comment.