open-cluster-management.io/governance-policy-propagator@v0.13.0/test/e2e/case4_unexpected_policy_test.go (about) 1 // Copyright (c) 2021 Red Hat, Inc. 2 // Copyright Contributors to the Open Cluster Management project 3 4 package e2e 5 6 import ( 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 11 "open-cluster-management.io/governance-policy-propagator/test/utils" 12 ) 13 14 var _ = Describe("Test unexpect policy handling", func() { 15 const ( 16 case4PolicyName string = "case4-test-policy" 17 case4PolicyYaml string = "../resources/case4_unexpected_policy/case4-test-policy.yaml" 18 ) 19 20 It("Unexpected root policy in cluster namespace should be deleted", func() { 21 By("Creating " + case4PolicyYaml + "in cluster namespace: managed1") 22 out, err := utils.KubectlWithOutput("apply", 23 "-f", case4PolicyYaml, 24 "-n", "managed1", 25 "--kubeconfig="+kubeconfigHub) 26 Expect(err).ShouldNot(HaveOccurred()) 27 Expect(out).Should(ContainSubstring(case4PolicyName + " created")) 28 Eventually(func() interface{} { 29 return utils.GetWithTimeout( 30 clientHubDynamic, gvrPolicy, case4PolicyName, "managed1", false, defaultTimeoutSeconds, 31 ) 32 }, defaultTimeoutSeconds, 1).Should(BeNil()) 33 }) 34 It("Unexpected replicated policy in cluster namespace should be deleted", func() { 35 const plcYaml string = "../resources/case4_unexpected_policy/case4-test-replicated-policy.yaml" 36 By("Creating " + plcYaml + " in cluster namespace: managed1") 37 out, err := utils.KubectlWithOutput("apply", 38 "-f", plcYaml, 39 "-n", "managed1", 40 "--kubeconfig="+kubeconfigHub) 41 Expect(err).ShouldNot(HaveOccurred()) 42 Expect(out).Should(ContainSubstring("policy-propagator-test.case4-test-policy created")) 43 Eventually(func() interface{} { 44 return utils.GetWithTimeout( 45 clientHubDynamic, 46 gvrPolicy, 47 "policy-propagator-test.case4-test-policy", 48 "managed1", 49 false, 50 defaultTimeoutSeconds, 51 ) 52 }, defaultTimeoutSeconds, 1).Should(BeNil()) 53 }) 54 It("Unexpected replicated policy in non-cluster namespace should be skipped", func() { 55 const plcYaml string = "../resources/case4_unexpected_policy/case4-test-replicated-policy-out-of-cluster.yaml" 56 By("Creating " + plcYaml + " in non-cluster namespace: leaf-hub1") 57 out, err := utils.KubectlWithOutput("apply", 58 "-f", plcYaml, 59 "-n", "leaf-hub1", 60 "--kubeconfig="+kubeconfigHub) 61 Expect(err).ShouldNot(HaveOccurred()) 62 Expect(out).Should(ContainSubstring("policy-propagator-test.case4-test-policy created")) 63 utils.Pause(2) 64 plc := utils.GetWithTimeout( 65 clientHubDynamic, gvrPolicy, "policy-propagator-test.case4-test-policy", 66 "leaf-hub1", true, defaultTimeoutSeconds, 67 ) 68 Expect(plc).NotTo(BeNil()) 69 }) 70 It("should clean up the non-cluster policy", func() { 71 utils.Kubectl("delete", 72 "-f", "../resources/case4_unexpected_policy/case4-test-replicated-policy-out-of-cluster.yaml", 73 "-n", "leaf-hub1", "--kubeconfig="+kubeconfigHub) 74 utils.ListWithTimeout(clientHubDynamic, gvrPolicy, metav1.ListOptions{}, 0, false, 10) 75 }) 76 })