diff --git a/test/e2e/csv_e2e_test.go b/test/e2e/csv_e2e_test.go index b76dd88487..c55ef04b06 100644 --- a/test/e2e/csv_e2e_test.go +++ b/test/e2e/csv_e2e_test.go @@ -4175,58 +4175,52 @@ var _ = Describe("ClusterServiceVersion", func() { }) var _ = Describe("Disabling copied CSVs", func() { - // Define namespace, operatorGroup, and csv upfront - ns := &corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: genName("csv-toggle-test-"), - }, - } + var ( + ns corev1.Namespace + csv operatorsv1alpha1.ClusterServiceVersion + ) - operatorGroup := operatorsv1.OperatorGroup{ - ObjectMeta: metav1.ObjectMeta{ - Name: genName("csv-toggle-test-"), - Namespace: ns.GetName(), - }, - } + BeforeEach(func() { + nsname := genName("csv-toggle-test-") + og := operatorsv1.OperatorGroup{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-operatorgroup", nsname), + Namespace: nsname, + }, + } + ns = SetupGeneratedTestNamespaceWithOperatorGroup(nsname, og) - csv := operatorsv1alpha1.ClusterServiceVersion{ - ObjectMeta: metav1.ObjectMeta{ - Name: genName("csv-toggle-test-"), - Namespace: ns.GetName(), - }, - Spec: operatorsv1alpha1.ClusterServiceVersionSpec{ - InstallStrategy: newNginxInstallStrategy(genName("csv-toggle-test-"), nil, nil), - InstallModes: []operatorsv1alpha1.InstallMode{ - { - Type: operatorsv1alpha1.InstallModeTypeAllNamespaces, - Supported: true, + csv = operatorsv1alpha1.ClusterServiceVersion{ + ObjectMeta: metav1.ObjectMeta{ + Name: genName("csv-toggle-test-"), + Namespace: nsname, + }, + Spec: operatorsv1alpha1.ClusterServiceVersionSpec{ + InstallStrategy: newNginxInstallStrategy(genName("csv-toggle-test-"), nil, nil), + InstallModes: []operatorsv1alpha1.InstallMode{ + { + Type: operatorsv1alpha1.InstallModeTypeAllNamespaces, + Supported: true, + }, }, }, - }, - } - - When("an operator is installed in AllNamespace mode", func() { - BeforeEach(func() { - Eventually(func() error { - if err := ctx.Ctx().Client().Create(context.TODO(), ns); err != nil && !k8serrors.IsAlreadyExists(err) { - ctx.Ctx().Logf("Unable to create ns: %v", err) - return err - } - - if err := ctx.Ctx().Client().Create(context.TODO(), &operatorGroup); err != nil && !k8serrors.IsAlreadyExists(err) { - ctx.Ctx().Logf("Unable to create og: %v", err) - return err - } - - if err := ctx.Ctx().Client().Create(context.TODO(), &csv); err != nil && !k8serrors.IsAlreadyExists(err) { - ctx.Ctx().Logf("Unable to create csv: %v", err) - return err - } + } + err := ctx.Ctx().Client().Create(context.Background(), &csv) + Expect(err).ShouldNot(HaveOccurred()) + }) + AfterEach(func() { + Eventually(func() error { + err := ctx.Ctx().Client().Delete(context.Background(), &csv) + if err != nil && k8serrors.IsNotFound(err) { + return err + } - return nil - }).Should(Succeed()) - }) + return nil + }).Should(Succeed()) + TeardownNamespace(ns.GetName()) + }) + When("an operator is installed in AllNamespace mode", func() { It("should have Copied CSVs in all other namespaces", func() { Eventually(func() error { requirement, err := k8slabels.NewRequirement(operatorsv1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()}) diff --git a/test/e2e/util.go b/test/e2e/util.go index 052dbc180c..7d742a4c56 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -951,7 +951,7 @@ func HaveMessage(goal string) gtypes.GomegaMatcher { }, ContainSubstring(goal)) } -func SetupGeneratedTestNamespace(name string) corev1.Namespace { +func SetupGeneratedTestNamespaceWithOperatorGroup(name string, og operatorsv1.OperatorGroup) corev1.Namespace { ns := corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -961,15 +961,6 @@ func SetupGeneratedTestNamespace(name string) corev1.Namespace { return ctx.Ctx().Client().Create(context.Background(), &ns) }).Should(Succeed()) - og := operatorsv1.OperatorGroup{ - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-operatorgroup", ns.GetName()), - Namespace: ns.GetName(), - }, - Spec: operatorsv1.OperatorGroupSpec{ - TargetNamespaces: []string{ns.GetName()}, - }, - } Eventually(func() error { return ctx.Ctx().Client().Create(context.Background(), &og) }).Should(Succeed()) @@ -979,6 +970,20 @@ func SetupGeneratedTestNamespace(name string) corev1.Namespace { return ns } +func SetupGeneratedTestNamespace(name string) corev1.Namespace { + og := operatorsv1.OperatorGroup{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-operatorgroup", name), + Namespace: name, + }, + Spec: operatorsv1.OperatorGroupSpec{ + TargetNamespaces: []string{name}, + }, + } + + return SetupGeneratedTestNamespaceWithOperatorGroup(name, og) +} + func TeardownNamespace(ns string) { log := ctx.Ctx().Logf