diff --git a/go.mod b/go.mod index d573b4e..a882d13 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( gotest.tools/v3 v3.3.0 knative.dev/client/pkg v0.0.0-20251013022316-b9b74c22e298 knative.dev/hack v0.0.0-20251013111017-49bc1be5f373 - ) require ( diff --git a/pkg/install/install.go b/pkg/install/install.go index c32931a..7db9365 100644 --- a/pkg/install/install.go +++ b/pkg/install/install.go @@ -132,6 +132,11 @@ func Serving(registries string) error { fmt.Println(" Core installed...") + // Wait for webhook to be ready before attempting to patch configmaps + if err := waitForWebhookReady(); err != nil { + return fmt.Errorf("webhook: %w", err) + } + if registries != "" { configPatch := fmt.Sprintf(`{"data":{"registries-skipping-tag-resolving":"%s"}}`, registries) ignoreRegistry := exec.Command("kubectl", "patch", "configmap", "-n", "knative-serving", "config-deployment", "-p", configPatch) @@ -237,3 +242,31 @@ func waitForCRDsEstablished() error { func waitForPodsReady(ns string) error { return runCommand(exec.Command("kubectl", "wait", "pod", "--timeout=10m", "--for=condition=Ready", "-l", "!job-name", "-n", ns)) } + +// waitForWebhookReady waits for the Knative Serving webhook to be ready. +func waitForWebhookReady() error { + fmt.Println(" Waiting for webhook to be ready...") + + // Retry for up to 2 minutes (12 attempts with 10s intervals) + for i := 0; i < 12; i++ { + // Check if the webhook pod is ready by looking specifically for the webhook deployment + checkWebhookDeployment := exec.Command("kubectl", "get", "deployment", "webhook", "-n", "knative-serving", "-o", "jsonpath={.status.readyReplicas}") + + output, err := checkWebhookDeployment.CombinedOutput() + if err == nil { + // Convert output to string and trim whitespace + readyReplicas := strings.TrimSpace(string(output)) + + // If we have at least one ready replica, the webhook is considered ready + if readyReplicas != "" && readyReplicas != "0" { + fmt.Println(" Webhook is ready...") + return nil + } + } + + fmt.Println(" Webhook not ready yet, waiting...") + time.Sleep(10 * time.Second) + } + + return fmt.Errorf("timeout waiting for webhook to be ready") +}