@@ -74,48 +74,37 @@ func (h *WebhookHandler) Handle(ctx context.Context, req admission.Request) admi
74
74
},
75
75
}
76
76
77
- // Initialize checkers in parallel and collect all checks .
78
- checkCh := make ( chan Check )
79
- wg := & sync. WaitGroup {}
77
+ // Collect all checks in parallel.
78
+ checkerWG := & sync. WaitGroup {}
79
+ resultCh := make ( chan CheckResult )
80
80
for _ , checker := range h .checkers {
81
- wg .Add (1 )
82
- go func (ctx context.Context , checker Checker ) {
81
+ checkerWG .Add (1 )
82
+
83
+ go func (ctx context.Context , checker Checker , resultCh chan CheckResult ) {
84
+ // Initialize the checker.
83
85
checks := checker .Init (ctx , h .client , cluster )
86
+
87
+ // Run its checks in parallel.
88
+ checksWG := & sync.WaitGroup {}
84
89
for _ , check := range checks {
85
- checkCh <- check
90
+ checksWG .Add (1 )
91
+ go func (ctx context.Context , check Check , resultCh chan CheckResult ) {
92
+ result := check (ctx )
93
+ resultCh <- result
94
+ checksWG .Done ()
95
+ }(ctx , check , resultCh )
86
96
}
87
- wg .Done ()
88
- }(ctx , checker )
89
- }
97
+ checksWG .Wait ()
90
98
91
- // Close the channel when all checkers are done.
92
- go func (wg * sync.WaitGroup , checkCh chan Check ) {
93
- wg .Wait ()
94
- close (checkCh )
95
- }(wg , checkCh )
96
-
97
- // Collect all checks from the channel.
98
- checks := []Check {}
99
- for check := range checkCh {
100
- checks = append (checks , check )
99
+ checkerWG .Done ()
100
+ }(ctx , checker , resultCh )
101
101
}
102
102
103
- // Run all checks in parallel.
104
- resultCh := make (chan CheckResult )
105
- for _ , check := range checks {
106
- wg .Add (1 )
107
- go func (ctx context.Context , check Check ) {
108
- result := check (ctx )
109
- resultCh <- result
110
- wg .Done ()
111
- }(ctx , check )
112
- }
113
-
114
- // Close the channel when all checks are done.
103
+ // Close the channel when all checkers are done.
115
104
go func (wg * sync.WaitGroup , resultCh chan CheckResult ) {
116
105
wg .Wait ()
117
106
close (resultCh )
118
- }(wg , resultCh )
107
+ }(checkerWG , resultCh )
119
108
120
109
// Collect all check results from the channel.
121
110
internalError := false
0 commit comments