Skip to content

Commit a8965f6

Browse files
authored
add webhook readiness check to serving install (#607)
Signed-off-by: Paul S. Schweigert <[email protected]>
1 parent 52fe1ba commit a8965f6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
gotest.tools/v3 v3.3.0
1111
knative.dev/client/pkg v0.0.0-20251013022316-b9b74c22e298
1212
knative.dev/hack v0.0.0-20251013111017-49bc1be5f373
13-
1413
)
1514

1615
require (

pkg/install/install.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ func Serving(registries string) error {
132132

133133
fmt.Println(" Core installed...")
134134

135+
// Wait for webhook to be ready before attempting to patch configmaps
136+
if err := waitForWebhookReady(); err != nil {
137+
return fmt.Errorf("webhook: %w", err)
138+
}
139+
135140
if registries != "" {
136141
configPatch := fmt.Sprintf(`{"data":{"registries-skipping-tag-resolving":"%s"}}`, registries)
137142
ignoreRegistry := exec.Command("kubectl", "patch", "configmap", "-n", "knative-serving", "config-deployment", "-p", configPatch)
@@ -237,3 +242,31 @@ func waitForCRDsEstablished() error {
237242
func waitForPodsReady(ns string) error {
238243
return runCommand(exec.Command("kubectl", "wait", "pod", "--timeout=10m", "--for=condition=Ready", "-l", "!job-name", "-n", ns))
239244
}
245+
246+
// waitForWebhookReady waits for the Knative Serving webhook to be ready.
247+
func waitForWebhookReady() error {
248+
fmt.Println(" Waiting for webhook to be ready...")
249+
250+
// Retry for up to 2 minutes (12 attempts with 10s intervals)
251+
for i := 0; i < 12; i++ {
252+
// Check if the webhook pod is ready by looking specifically for the webhook deployment
253+
checkWebhookDeployment := exec.Command("kubectl", "get", "deployment", "webhook", "-n", "knative-serving", "-o", "jsonpath={.status.readyReplicas}")
254+
255+
output, err := checkWebhookDeployment.CombinedOutput()
256+
if err == nil {
257+
// Convert output to string and trim whitespace
258+
readyReplicas := strings.TrimSpace(string(output))
259+
260+
// If we have at least one ready replica, the webhook is considered ready
261+
if readyReplicas != "" && readyReplicas != "0" {
262+
fmt.Println(" Webhook is ready...")
263+
return nil
264+
}
265+
}
266+
267+
fmt.Println(" Webhook not ready yet, waiting...")
268+
time.Sleep(10 * time.Second)
269+
}
270+
271+
return fmt.Errorf("timeout waiting for webhook to be ready")
272+
}

0 commit comments

Comments
 (0)