Skip to content

Commit 766ac60

Browse files
Wei WengWei Weng
authored andcommitted
better readiness check
Signed-off-by: Wei Weng <Wei.Weng@microsoft.com>
1 parent ecd2a58 commit 766ac60

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

cmd/hubagent/main.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"flag"
2121
"fmt"
2222
"math"
23-
"net/http"
2423
"os"
2524
"strings"
2625
"sync"
@@ -151,20 +150,7 @@ func main() {
151150
klog.ErrorS(err, "unable to set up health check")
152151
exitWithErrorFunc()
153152
}
154-
// Add a readiness check that verifies ResourceInformer is ready
155-
// This prevents webhook from accepting requests before discovery cache is populated
156-
if err := mgr.AddReadyzCheck("readyz", func(req *http.Request) error {
157-
// First check basic health
158-
if err := healthz.Ping(req); err != nil {
159-
return err
160-
}
161-
// Then verify ResourceInformer cache is synced (if webhook is enabled)
162-
// This prevents webhook from accepting requests before discovery cache is populated
163-
if opts.EnableWebhook && validator.ResourceInformer != nil {
164-
return webhook.ResourceInformerReadinessChecker(validator.ResourceInformer)(req)
165-
}
166-
return nil
167-
}); err != nil {
153+
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
168154
klog.ErrorS(err, "unable to set up ready check")
169155
exitWithErrorFunc()
170156
}
@@ -179,10 +165,19 @@ func main() {
179165

180166
ctx := ctrl.SetupSignalHandler()
181167
if err := workload.SetupControllers(ctx, &wg, mgr, config, opts); err != nil {
182-
klog.ErrorS(err, "unable to set up ready check")
168+
klog.ErrorS(err, "unable to set up controllers")
183169
exitWithErrorFunc()
184170
}
185171

172+
// Add webhook readiness check AFTER controllers are set up (when ResourceInformer is initialized)
173+
// This prevents webhook from accepting requests before discovery cache is populated
174+
if opts.EnableWebhook {
175+
if err := mgr.AddReadyzCheck("webhook-cache", webhook.ResourceInformerReadinessChecker(validator.ResourceInformer)); err != nil {
176+
klog.ErrorS(err, "unable to set up webhook readiness check")
177+
exitWithErrorFunc()
178+
}
179+
}
180+
186181
// +kubebuilder:scaffold:builder
187182

188183
wg.Add(1)

0 commit comments

Comments
 (0)