Skip to content

Commit

Permalink
feat(client): parallelize IsBootstrap function
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshal101 authored and christophenne committed Feb 28, 2024
1 parent 3b8a07b commit 8d8559e
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions pkg/bootstrap/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bootstrap
import (
"context"
"fmt"
"sync"

"github.com/glasskube/glasskube/api/v1alpha1"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
Expand All @@ -16,14 +17,32 @@ func IsBootstrapped(ctx context.Context, cfg *rest.Config) (bool, error) {
if err != nil {
return false, err
}
pkgsExist, err := crdExists(ctx, cs, "packages")
if err != nil {
return false, err

var wg sync.WaitGroup
wg.Add(2)

var pkgsExist, pisExist bool
var pkgsErr, pisErr error

go func() {
defer wg.Done()
pkgsExist, pkgsErr = crdExists(ctx, cs, "packages")
}()

go func() {
defer wg.Done()
pisExist, pisErr = crdExists(ctx, cs, "packageinfos")
}()

wg.Wait()

if pkgsErr != nil {
return false, pkgsErr
}
pisExist, err := crdExists(ctx, cs, "packageinfos")
if err != nil {
return false, err
if pisErr != nil {
return false, pisErr
}

return pkgsExist && pisExist, nil
}

Expand Down

0 comments on commit 8d8559e

Please sign in to comment.