Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 e2e-tests: fix/cleanup and add test to validate webhooks outside of the manager namespace #4167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions test/e2e/v4/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,26 +312,32 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, hasMetrics bool,
ExpectWithOffset(1, count).To(BeNumerically("==", 5))
}

if hasWebhook && hasNetworkPolicies {
By("validating that webhooks from namespace without the label will fail")

// Define the namespace name and CR sample file path
namespace := "test-namespace-without-webhook-label"
sampleFile := "path/to/your/sample-file.yaml"

// Create the namespace
By("creating a namespace without the webhook: enabled label")
if hasWebhook {
By("creating a namespace")
namespace := "test-webhooks"
_, err := kbc.Kubectl.Command("create", "namespace", namespace)
Expect(err).NotTo(HaveOccurred(), "namespace should be created successfully")

// Apply the Custom Resource in the new namespace and expect it to fail
By("applying the CR in the namespace without the webhook: enabled label and expecting it to fail")
By("applying the CR in the created namespace")
EventuallyWithOffset(1, func() error {
_, err = kbc.Kubectl.Apply(false, "-n", namespace, "-f", sampleFile)
_, err := kbc.Kubectl.Apply(false, "-n", namespace, "-f", sampleFile)
return err
}, time.Minute, time.Second).Should(HaveOccurred(), "applying the CR should fail due to webhook call timeout")
}, 2*time.Minute, time.Second).ShouldNot(HaveOccurred(),
"apply in test-webhooks ns should not fail")

By("validating that mutating webhooks are working fine outside of the manager's namespace")
cnt, err := kbc.Kubectl.Get(
false,
"-n", namespace,
"-f", sampleFile,
"-o", "go-template={{ .spec.count }}")
ExpectWithOffset(1, err).NotTo(HaveOccurred())

count, err := strconv.Atoi(cnt)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
ExpectWithOffset(1, count).To(BeNumerically("==", 5),
"the mutating webhook should set the count to 5")

// Cleanup: Remove the namespace
By("removing the namespace")
_, err = kbc.Kubectl.Command("delete", "namespace", namespace)
Expect(err).NotTo(HaveOccurred(), "namespace should be removed successfully")
Expand Down
Loading