Skip to content

Commit 858e6fd

Browse files
committed
fixup! feat: Add preflight checks framework
Run checks in parallel
1 parent 24c9d45 commit 858e6fd

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkg/webhook/preflight/preflight.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package preflight
55
import (
66
"context"
77
"net/http"
8+
"sync"
89

910
admissionv1 "k8s.io/api/admission/v1"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -97,10 +98,20 @@ func (h *WebhookHandler) Handle(ctx context.Context, req admission.Request) admi
9798
}
9899

99100
// Run all checks and collect results.
100-
// TODO Parallelize checks.
101+
resultCh := make(chan CheckResult, len(checks))
102+
wg := &sync.WaitGroup{}
101103
for _, check := range checks {
102-
result := check(ctx)
104+
wg.Add(1)
105+
go func(ctx context.Context, check Check) {
106+
result := check(ctx)
107+
resultCh <- result
108+
wg.Done()
109+
}(ctx, check)
110+
}
111+
wg.Wait()
112+
close(resultCh)
103113

114+
for result := range resultCh {
104115
if result.Error {
105116
resp.Allowed = false
106117
resp.Result.Code = http.StatusForbidden

0 commit comments

Comments
 (0)