@@ -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 {
237242func 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