@@ -211,6 +211,41 @@ var _ = Describe("Manager", Ordered, func() {
211211 }
212212 Eventually (verifyMetricsServerStarted ).Should (Succeed ())
213213
214+ By ("waiting for webhook service to be ready if webhooks are configured" )
215+ verifyWebhookServiceReady := func (g Gomega ) {
216+ // Check if webhook service exists first
217+ cmd := exec .Command ("kubectl" , "get" , "service" , "project-v4-with-plugins-webhook-service" , "-n" , namespace )
218+ _ , err := utils .Run (cmd )
219+ if err != nil {
220+ // No webhook service found, skip webhook checks
221+ return
222+ }
223+
224+ // Check if webhook server is ready by verifying pod readiness
225+ cmd = exec .Command ("kubectl" , "get" , "pods" , "-l" , "control-plane=controller-manager" ,
226+ "-n" , namespace , "-o" , "jsonpath={.items[0].status.conditions[?(@.type=='Ready')].status}" )
227+ output , err := utils .Run (cmd )
228+ g .Expect (err ).NotTo (HaveOccurred ())
229+ g .Expect (output ).To (Equal ("True" ),
230+ "Controller manager pod not ready (webhook server may not be accepting connections)" )
231+
232+ // Check if webhook service endpoints are available
233+ cmd = exec .Command ("kubectl" , "get" , "endpoints" , "project-v4-with-plugins-webhook-service" ,
234+ "-n" , namespace , "-o" , "jsonpath={.subsets[*].addresses[*].ip}" )
235+ output , err = utils .Run (cmd )
236+ g .Expect (err ).NotTo (HaveOccurred ())
237+ g .Expect (output ).NotTo (BeEmpty (), "Webhook service endpoints are not ready" )
238+
239+ // Test webhook connectivity by checking if webhook server port is responding
240+ cmd = exec .Command ("kubectl" , "run" , "webhook-test" , "--rm" , "-i" , "--restart=Never" ,
241+ "--image=curlimages/curl:latest" , "--" ,
242+ "curl" , "-k" , "--connect-timeout" , "5" ,
243+ "https://project-v4-with-plugins-webhook-service." + namespace + ".svc:443/readyz" )
244+ _ , err = utils .Run (cmd )
245+ g .Expect (err ).NotTo (HaveOccurred (), "Webhook server not responding on port 443" )
246+ }
247+ Eventually (verifyWebhookServiceReady , 2 * time .Minute ).Should (Succeed ())
248+
214249 By ("creating the curl-metrics pod to access the metrics endpoint" )
215250 cmd = exec .Command ("kubectl" , "run" , "curl-metrics" , "--restart=Never" ,
216251 "--namespace" , namespace ,
0 commit comments