Skip to content

Commit edf6e7b

Browse files
fix disable copied csv e2e test failure (#2543)
Signed-off-by: akihikokuroda <[email protected]>
1 parent 5c4c67a commit edf6e7b

File tree

2 files changed

+55
-56
lines changed

2 files changed

+55
-56
lines changed

Diff for: test/e2e/csv_e2e_test.go

+40-46
Original file line numberDiff line numberDiff line change
@@ -4175,58 +4175,52 @@ var _ = Describe("ClusterServiceVersion", func() {
41754175
})
41764176

41774177
var _ = Describe("Disabling copied CSVs", func() {
4178-
// Define namespace, operatorGroup, and csv upfront
4179-
ns := &corev1.Namespace{
4180-
ObjectMeta: metav1.ObjectMeta{
4181-
Name: genName("csv-toggle-test-"),
4182-
},
4183-
}
4178+
var (
4179+
ns corev1.Namespace
4180+
csv operatorsv1alpha1.ClusterServiceVersion
4181+
)
41844182

4185-
operatorGroup := operatorsv1.OperatorGroup{
4186-
ObjectMeta: metav1.ObjectMeta{
4187-
Name: genName("csv-toggle-test-"),
4188-
Namespace: ns.GetName(),
4189-
},
4190-
}
4183+
BeforeEach(func() {
4184+
nsname := genName("csv-toggle-test-")
4185+
og := operatorsv1.OperatorGroup{
4186+
ObjectMeta: metav1.ObjectMeta{
4187+
Name: fmt.Sprintf("%s-operatorgroup", nsname),
4188+
Namespace: nsname,
4189+
},
4190+
}
4191+
ns = SetupGeneratedTestNamespaceWithOperatorGroup(nsname, og)
41914192

4192-
csv := operatorsv1alpha1.ClusterServiceVersion{
4193-
ObjectMeta: metav1.ObjectMeta{
4194-
Name: genName("csv-toggle-test-"),
4195-
Namespace: ns.GetName(),
4196-
},
4197-
Spec: operatorsv1alpha1.ClusterServiceVersionSpec{
4198-
InstallStrategy: newNginxInstallStrategy(genName("csv-toggle-test-"), nil, nil),
4199-
InstallModes: []operatorsv1alpha1.InstallMode{
4200-
{
4201-
Type: operatorsv1alpha1.InstallModeTypeAllNamespaces,
4202-
Supported: true,
4193+
csv = operatorsv1alpha1.ClusterServiceVersion{
4194+
ObjectMeta: metav1.ObjectMeta{
4195+
Name: genName("csv-toggle-test-"),
4196+
Namespace: nsname,
4197+
},
4198+
Spec: operatorsv1alpha1.ClusterServiceVersionSpec{
4199+
InstallStrategy: newNginxInstallStrategy(genName("csv-toggle-test-"), nil, nil),
4200+
InstallModes: []operatorsv1alpha1.InstallMode{
4201+
{
4202+
Type: operatorsv1alpha1.InstallModeTypeAllNamespaces,
4203+
Supported: true,
4204+
},
42034205
},
42044206
},
4205-
},
4206-
}
4207-
4208-
When("an operator is installed in AllNamespace mode", func() {
4209-
BeforeEach(func() {
4210-
Eventually(func() error {
4211-
if err := ctx.Ctx().Client().Create(context.TODO(), ns); err != nil && !k8serrors.IsAlreadyExists(err) {
4212-
ctx.Ctx().Logf("Unable to create ns: %v", err)
4213-
return err
4214-
}
4215-
4216-
if err := ctx.Ctx().Client().Create(context.TODO(), &operatorGroup); err != nil && !k8serrors.IsAlreadyExists(err) {
4217-
ctx.Ctx().Logf("Unable to create og: %v", err)
4218-
return err
4219-
}
4220-
4221-
if err := ctx.Ctx().Client().Create(context.TODO(), &csv); err != nil && !k8serrors.IsAlreadyExists(err) {
4222-
ctx.Ctx().Logf("Unable to create csv: %v", err)
4223-
return err
4224-
}
4207+
}
4208+
err := ctx.Ctx().Client().Create(context.Background(), &csv)
4209+
Expect(err).ShouldNot(HaveOccurred())
4210+
})
4211+
AfterEach(func() {
4212+
Eventually(func() error {
4213+
err := ctx.Ctx().Client().Delete(context.Background(), &csv)
4214+
if err != nil && k8serrors.IsNotFound(err) {
4215+
return err
4216+
}
42254217

4226-
return nil
4227-
}).Should(Succeed())
4228-
})
4218+
return nil
4219+
}).Should(Succeed())
4220+
TeardownNamespace(ns.GetName())
4221+
})
42294222

4223+
When("an operator is installed in AllNamespace mode", func() {
42304224
It("should have Copied CSVs in all other namespaces", func() {
42314225
Eventually(func() error {
42324226
requirement, err := k8slabels.NewRequirement(operatorsv1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()})

Diff for: test/e2e/util.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ func HaveMessage(goal string) gtypes.GomegaMatcher {
951951
}, ContainSubstring(goal))
952952
}
953953

954-
func SetupGeneratedTestNamespace(name string) corev1.Namespace {
954+
func SetupGeneratedTestNamespaceWithOperatorGroup(name string, og operatorsv1.OperatorGroup) corev1.Namespace {
955955
ns := corev1.Namespace{
956956
ObjectMeta: metav1.ObjectMeta{
957957
Name: name,
@@ -961,15 +961,6 @@ func SetupGeneratedTestNamespace(name string) corev1.Namespace {
961961
return ctx.Ctx().Client().Create(context.Background(), &ns)
962962
}).Should(Succeed())
963963

964-
og := operatorsv1.OperatorGroup{
965-
ObjectMeta: metav1.ObjectMeta{
966-
Name: fmt.Sprintf("%s-operatorgroup", ns.GetName()),
967-
Namespace: ns.GetName(),
968-
},
969-
Spec: operatorsv1.OperatorGroupSpec{
970-
TargetNamespaces: []string{ns.GetName()},
971-
},
972-
}
973964
Eventually(func() error {
974965
return ctx.Ctx().Client().Create(context.Background(), &og)
975966
}).Should(Succeed())
@@ -979,6 +970,20 @@ func SetupGeneratedTestNamespace(name string) corev1.Namespace {
979970
return ns
980971
}
981972

973+
func SetupGeneratedTestNamespace(name string) corev1.Namespace {
974+
og := operatorsv1.OperatorGroup{
975+
ObjectMeta: metav1.ObjectMeta{
976+
Name: fmt.Sprintf("%s-operatorgroup", name),
977+
Namespace: name,
978+
},
979+
Spec: operatorsv1.OperatorGroupSpec{
980+
TargetNamespaces: []string{name},
981+
},
982+
}
983+
984+
return SetupGeneratedTestNamespaceWithOperatorGroup(name, og)
985+
}
986+
982987
func TeardownNamespace(ns string) {
983988
log := ctx.Ctx().Logf
984989

0 commit comments

Comments
 (0)