Skip to content

Commit ce59ce4

Browse files
committed
fix: gate readyz on webhook TLS server startup
Add webhookServer.StartedChecker() as a readyz check so the pod Ready condition reflects actual webhook TLS availability on :9443, not just the health endpoint being up. Replace the fragile .items[0] jsonpath probe with kubectl wait which handles rolling restarts correctly. Addresses review feedback from #421. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Paolo Dettori <dettori@us.ibm.com>
1 parent 1564816 commit ce59ce4

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

kagenti-operator/cmd/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ func main() {
688688
setupLog.Error(err, "unable to set up ready check")
689689
os.Exit(1)
690690
}
691+
if err := mgr.AddReadyzCheck("webhook", webhookServer.StartedChecker()); err != nil {
692+
setupLog.Error(err, "unable to set up webhook ready check")
693+
os.Exit(1)
694+
}
691695

692696
setupLog.Info("starting manager")
693697
if err := mgr.Start(ctx); err != nil {

kagenti-operator/test/utils/utils.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -752,20 +752,18 @@ func UncommentCode(filename, target, prefix string) error {
752752
return os.WriteFile(filename, out.Bytes(), 0644)
753753
}
754754

755-
// ProbeWebhookReady checks that the controller pod is fully Ready (all
756-
// containers passing readiness probes). The manager's readiness probe gates
757-
// on full initialization including the webhook server startup.
755+
// ProbeWebhookReady checks that the controller pod is fully Ready.
756+
// The readyz endpoint gates on webhookServer.StartedChecker(), so Ready
757+
// means the webhook TLS server is accepting connections on :9443.
758758
func ProbeWebhookReady(namespace string) error {
759-
cmd := exec.Command("kubectl", "get", "pods",
760-
"-l", "control-plane=controller-manager",
759+
cmd := exec.Command("kubectl", "wait",
760+
"--for=condition=Ready",
761+
"pod", "-l", "control-plane=controller-manager",
761762
"-n", namespace,
762-
"-o", "jsonpath={.items[0].status.conditions[?(@.type==\"Ready\")].status}")
763-
output, err := Run(cmd)
763+
"--timeout=5s")
764+
_, err := Run(cmd)
764765
if err != nil {
765-
return fmt.Errorf("failed to check controller pod readiness: %w", err)
766-
}
767-
if strings.TrimSpace(output) != "True" {
768-
return fmt.Errorf("controller pod not yet Ready (status=%q)", output)
766+
return fmt.Errorf("controller pod not yet Ready: %w", err)
769767
}
770768
return nil
771769
}

0 commit comments

Comments
 (0)