@@ -312,26 +312,32 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, hasMetrics bool,
312312 ExpectWithOffset (1 , count ).To (BeNumerically ("==" , 5 ))
313313 }
314314
315- if hasWebhook && hasNetworkPolicies {
316- By ("validating that webhooks from namespace without the label will fail" )
317-
318- // Define the namespace name and CR sample file path
319- namespace := "test-namespace-without-webhook-label"
320- sampleFile := "path/to/your/sample-file.yaml"
321-
322- // Create the namespace
323- By ("creating a namespace without the webhook: enabled label" )
315+ if hasWebhook {
316+ By ("creating a namespace" )
317+ namespace := "test-webhooks"
324318 _ , err := kbc .Kubectl .Command ("create" , "namespace" , namespace )
325319 Expect (err ).NotTo (HaveOccurred (), "namespace should be created successfully" )
326320
327- // Apply the Custom Resource in the new namespace and expect it to fail
328- By ("applying the CR in the namespace without the webhook: enabled label and expecting it to fail" )
321+ By ("applying the CR in the created namespace" )
329322 EventuallyWithOffset (1 , func () error {
330- _ , err = kbc .Kubectl .Apply (false , "-n" , namespace , "-f" , sampleFile )
323+ _ , err : = kbc .Kubectl .Apply (false , "-n" , namespace , "-f" , sampleFile )
331324 return err
332- }, time .Minute , time .Second ).Should (HaveOccurred (), "applying the CR should fail due to webhook call timeout" )
325+ }, 2 * time .Minute , time .Second ).ShouldNot (HaveOccurred (),
326+ "apply in test-webhooks ns should not fail" )
327+
328+ By ("validating that mutating webhooks are working fine outside of the manager's namespace" )
329+ cnt , err := kbc .Kubectl .Get (
330+ false ,
331+ "-n" , namespace ,
332+ "-f" , sampleFile ,
333+ "-o" , "go-template={{ .spec.count }}" )
334+ ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
335+
336+ count , err := strconv .Atoi (cnt )
337+ ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
338+ ExpectWithOffset (1 , count ).To (BeNumerically ("==" , 5 ),
339+ "the mutating webhook should set the count to 5" )
333340
334- // Cleanup: Remove the namespace
335341 By ("removing the namespace" )
336342 _ , err = kbc .Kubectl .Command ("delete" , "namespace" , namespace )
337343 Expect (err ).NotTo (HaveOccurred (), "namespace should be removed successfully" )
0 commit comments