Skip to content

Commit fbbda25

Browse files
authored
Move crd e2e to one namespace per spec (#2706)
Signed-off-by: perdasilva <[email protected]>
1 parent c970cc6 commit fbbda25

File tree

4 files changed

+88
-62
lines changed

4 files changed

+88
-62
lines changed

test/e2e/crd_e2e_test.go

+56-30
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1212
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
1313
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
14+
corev1 "k8s.io/api/core/v1"
1415

1516
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
1617
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -19,7 +20,18 @@ import (
1920
)
2021

2122
var _ = Describe("CRD Versions", func() {
22-
AfterEach(func() { TearDown(testNamespace) }, float64(30))
23+
24+
var (
25+
ns corev1.Namespace
26+
)
27+
28+
BeforeEach(func() {
29+
ns = SetupGeneratedTestNamespace(genName("crd-e2e-"))
30+
})
31+
32+
AfterEach(func() {
33+
TeardownNamespace(ns.GetName())
34+
})
2335

2436
// issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2640
2537
It("[FLAKE] creates v1 CRDs with a v1 schema successfully", func() {
@@ -56,7 +68,7 @@ var _ = Describe("CRD Versions", func() {
5668
},
5769
}
5870

59-
mainCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), nil, nil, nil)
71+
mainCSV := newCSV(mainPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), nil, nil, nil)
6072
mainCatalogName := genName("mock-ocs-main-update2-")
6173
mainManifests := []registry.PackageManifest{
6274
{
@@ -69,18 +81,22 @@ var _ = Describe("CRD Versions", func() {
6981
}
7082

7183
// Create the catalog sources
72-
_, cleanupMainCatalogSource := createV1CRDInternalCatalogSource(GinkgoT(), c, crc, mainCatalogName, testNamespace, mainManifests, []apiextensionsv1.CustomResourceDefinition{v1crd}, []operatorsv1alpha1.ClusterServiceVersion{mainCSV})
84+
_, cleanupMainCatalogSource := createV1CRDInternalCatalogSource(GinkgoT(), c, crc, mainCatalogName, ns.GetName(), mainManifests, []apiextensionsv1.CustomResourceDefinition{v1crd}, []operatorsv1alpha1.ClusterServiceVersion{mainCSV})
7385
defer cleanupMainCatalogSource()
86+
defer func() {
87+
_ = crc.OperatorsV1alpha1().ClusterServiceVersions(ns.GetName()).Delete(context.TODO(), mainCSV.GetName(), metav1.DeleteOptions{})
88+
_ = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), v1crd.GetName(), metav1.DeleteOptions{})
89+
}()
7490

7591
// Attempt to get the catalog source before creating install plan
76-
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
92+
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
7793
Expect(err).ToNot(HaveOccurred())
7894

7995
subscriptionName := genName("sub-nginx-update2-")
80-
subscriptionCleanup := createSubscriptionForCatalog(crc, testNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
96+
subscriptionCleanup := createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
8197
defer subscriptionCleanup()
8298

83-
subscription, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
99+
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker)
84100
Expect(err).ToNot(HaveOccurred())
85101
Expect(subscription).ToNot(Equal(nil))
86102
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
@@ -89,7 +105,7 @@ var _ = Describe("CRD Versions", func() {
89105
installPlanName := subscription.Status.InstallPlanRef.Name
90106

91107
// Wait for InstallPlan to be status: Complete before checking resource presence
92-
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
108+
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, ns.GetName(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
93109
Expect(err).ToNot(HaveOccurred())
94110
GinkgoT().Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase)
95111
Expect(fetchedInstallPlan.Status.Phase).To(Equal(operatorsv1alpha1.InstallPlanPhaseComplete))
@@ -190,8 +206,8 @@ var _ = Describe("CRD Versions", func() {
190206
},
191207
}
192208

193-
oldCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{oldCRD}, nil, nil)
194-
newCSV := newCSV(mainPackageAlpha, testNamespace, mainPackageStable, semver.MustParse("0.1.1"), []apiextensions.CustomResourceDefinition{newCRD}, nil, nil)
209+
oldCSV := newCSV(mainPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{oldCRD}, nil, nil)
210+
newCSV := newCSV(mainPackageAlpha, ns.GetName(), mainPackageStable, semver.MustParse("0.1.1"), []apiextensions.CustomResourceDefinition{newCRD}, nil, nil)
195211
mainCatalogName := genName("mock-ocs-main-update2-")
196212
mainManifests := []registry.PackageManifest{
197213
{
@@ -205,18 +221,24 @@ var _ = Describe("CRD Versions", func() {
205221
}
206222

207223
// Create the catalog sources
208-
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, testNamespace, mainManifests, []apiextensions.CustomResourceDefinition{oldCRD, newCRD}, []operatorsv1alpha1.ClusterServiceVersion{oldCSV, newCSV})
224+
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, ns.GetName(), mainManifests, []apiextensions.CustomResourceDefinition{oldCRD, newCRD}, []operatorsv1alpha1.ClusterServiceVersion{oldCSV, newCSV})
209225
defer cleanupMainCatalogSource()
226+
defer func() {
227+
_ = crc.OperatorsV1alpha1().ClusterServiceVersions(ns.GetName()).Delete(context.TODO(), oldCSV.GetName(), metav1.DeleteOptions{})
228+
_ = crc.OperatorsV1alpha1().ClusterServiceVersions(ns.GetName()).Delete(context.TODO(), newCSV.GetName(), metav1.DeleteOptions{})
229+
_ = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), oldCRD.GetName(), metav1.DeleteOptions{})
230+
_ = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), newCRD.GetName(), metav1.DeleteOptions{})
231+
}()
210232

211233
// Attempt to get the catalog source before creating install plan
212-
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
234+
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
213235
Expect(err).ToNot(HaveOccurred())
214236

215237
subscriptionName := genName("sub-nginx-update2-")
216-
subscriptionCleanup := createSubscriptionForCatalog(crc, testNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
238+
subscriptionCleanup := createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
217239
defer subscriptionCleanup()
218240

219-
subscription, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
241+
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker)
220242
Expect(err).ToNot(HaveOccurred())
221243
Expect(subscription).ToNot(BeNil())
222244
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
@@ -225,7 +247,7 @@ var _ = Describe("CRD Versions", func() {
225247
installPlanName := subscription.Status.InstallPlanRef.Name
226248

227249
// Wait for InstallPlan to be status: Complete before checking resource presence
228-
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
250+
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, ns.GetName(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
229251
Expect(err).ToNot(HaveOccurred())
230252
GinkgoT().Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase)
231253
Expect(fetchedInstallPlan.Status.Phase).To(Equal(operatorsv1alpha1.InstallPlanPhaseComplete))
@@ -244,14 +266,14 @@ var _ = Describe("CRD Versions", func() {
244266
}
245267

246268
// fetch new subscription
247-
s, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
269+
s, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
248270
Expect(err).ToNot(HaveOccurred())
249271
Expect(s).ToNot(BeNil())
250272
Expect(s.Status.InstallPlanRef).ToNot(Equal(nil))
251273

252274
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version
253275
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
254-
return crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
276+
return crc.OperatorsV1alpha1().InstallPlans(ns.GetName()).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
255277
}).Should(And(
256278
WithTransform(
257279
func(v *operatorsv1alpha1.InstallPlan) operatorsv1alpha1.InstallPlanPhase {
@@ -380,7 +402,11 @@ var _ = Describe("CRD Versions", func() {
380402
mainPackageName := genName("nginx-update2-")
381403
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
382404
stableChannel := "stable"
383-
catalogCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{catalogCRD}, nil, nil)
405+
catalogCSV := newCSV(mainPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{catalogCRD}, nil, nil)
406+
defer func() {
407+
_ = crc.OperatorsV1alpha1().ClusterServiceVersions(ns.GetName()).Delete(context.TODO(), catalogCSV.GetName(), metav1.DeleteOptions{})
408+
_ = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), catalogCRD.GetName(), metav1.DeleteOptions{})
409+
}()
384410

385411
mainCatalogName := genName("mock-ocs-main-update2-")
386412
mainManifests := []registry.PackageManifest{
@@ -394,17 +420,17 @@ var _ = Describe("CRD Versions", func() {
394420
}
395421

396422
// Create the catalog sources
397-
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, testNamespace, mainManifests, []apiextensions.CustomResourceDefinition{catalogCRD}, []operatorsv1alpha1.ClusterServiceVersion{catalogCSV})
423+
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, ns.GetName(), mainManifests, []apiextensions.CustomResourceDefinition{catalogCRD}, []operatorsv1alpha1.ClusterServiceVersion{catalogCSV})
398424
defer cleanupMainCatalogSource()
399425

400426
// Attempt to get the catalog source before creating install plan
401-
_, err = fetchCatalogSourceOnStatus(crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
427+
_, err = fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
402428
Expect(err).ToNot(HaveOccurred())
403429

404430
subscriptionName := genName("sub-nginx-update2-")
405-
_ = createSubscriptionForCatalog(crc, testNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
431+
_ = createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
406432

407-
subscription, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
433+
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker)
408434
Expect(err).ToNot(HaveOccurred())
409435
Expect(subscription).ToNot(BeNil())
410436
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
@@ -413,7 +439,7 @@ var _ = Describe("CRD Versions", func() {
413439
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version (v1alpha1)
414440
Eventually(
415441
func() (*operatorsv1alpha1.InstallPlan, error) {
416-
return crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.GetOptions{})
442+
return crc.OperatorsV1alpha1().InstallPlans(ns.GetName()).Get(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.GetOptions{})
417443
},
418444
90*time.Second, // exhaust retries
419445
).Should(WithTransform(
@@ -431,36 +457,36 @@ var _ = Describe("CRD Versions", func() {
431457

432458
// install should now succeed
433459
oldInstallPlanRef := subscription.Status.InstallPlanRef.Name
434-
err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Delete(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.DeleteOptions{})
460+
err = crc.OperatorsV1alpha1().InstallPlans(ns.GetName()).Delete(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.DeleteOptions{})
435461
Expect(err).ToNot(HaveOccurred(), "error deleting failed install plan")
436462
// remove old subscription
437-
err = crc.OperatorsV1alpha1().Subscriptions(testNamespace).Delete(context.TODO(), subscription.GetName(), metav1.DeleteOptions{})
463+
err = crc.OperatorsV1alpha1().Subscriptions(ns.GetName()).Delete(context.TODO(), subscription.GetName(), metav1.DeleteOptions{})
438464
Expect(err).ToNot(HaveOccurred(), "error deleting old subscription")
439465
// remove old csv
440-
crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).Delete(context.TODO(), mainPackageStable, metav1.DeleteOptions{})
466+
crc.OperatorsV1alpha1().ClusterServiceVersions(ns.GetName()).Delete(context.TODO(), mainPackageStable, metav1.DeleteOptions{})
441467
Expect(err).ToNot(HaveOccurred(), "error deleting old subscription")
442468

443469
// recreate subscription
444470
subscriptionNameNew := genName("sub-nginx-update2-new-")
445-
_ = createSubscriptionForCatalog(crc, testNamespace, subscriptionNameNew, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
471+
_ = createSubscriptionForCatalog(crc, ns.GetName(), subscriptionNameNew, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
446472

447-
subscription, err = fetchSubscription(crc, testNamespace, subscriptionNameNew, subscriptionHasInstallPlanChecker)
473+
subscription, err = fetchSubscription(crc, ns.GetName(), subscriptionNameNew, subscriptionHasInstallPlanChecker)
448474
Expect(err).ToNot(HaveOccurred())
449475
Expect(subscription).ToNot(BeNil())
450476
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
451477
Expect(catalogCSV.GetName()).To(Equal(subscription.Status.CurrentCSV))
452478

453479
// eventually the subscription should create a new install plan
454480
Eventually(func() bool {
455-
sub, _ := crc.OperatorsV1alpha1().Subscriptions(testNamespace).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
481+
sub, _ := crc.OperatorsV1alpha1().Subscriptions(ns.GetName()).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
456482
GinkgoT().Logf("waiting for subscription %s to generate a new install plan...", subscription.GetName())
457483
return sub.Status.InstallPlanRef.Name != oldInstallPlanRef
458484
}, 5*time.Minute, 10*time.Second).Should(BeTrue())
459485

460486
// eventually the new installplan should succeed
461487
Eventually(func() bool {
462-
sub, _ := crc.OperatorsV1alpha1().Subscriptions(testNamespace).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
463-
ip, err := crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), sub.Status.InstallPlanRef.Name, metav1.GetOptions{})
488+
sub, _ := crc.OperatorsV1alpha1().Subscriptions(ns.GetName()).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
489+
ip, err := crc.OperatorsV1alpha1().InstallPlans(ns.GetName()).Get(context.TODO(), sub.Status.InstallPlanRef.Name, metav1.GetOptions{})
464490
if k8serrors.IsNotFound(err) {
465491
return false
466492
}

test/e2e/gc_e2e_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ var _ = Describe("Garbage collection for dependent resources", func() {
372372
installPlanRef = sub.Status.InstallPlanRef.Name
373373

374374
// Wait for the installplan to complete (5 minute timeout)
375-
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
375+
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, testNamespace, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
376376
Expect(err).ToNot(HaveOccurred(), "could not get installplan at complete phase")
377377

378378
ctx.Ctx().Logf("install plan %s completed", installPlanRef)
@@ -486,7 +486,7 @@ var _ = Describe("Garbage collection for dependent resources", func() {
486486
installPlanRef = sub.Status.InstallPlanRef.Name
487487

488488
// Wait for the installplan to complete (5 minute timeout)
489-
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
489+
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, testNamespace, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
490490
Expect(err).ToNot(HaveOccurred(), "could not get installplan at complete phase")
491491

492492
Eventually(func() error {
@@ -522,7 +522,7 @@ var _ = Describe("Garbage collection for dependent resources", func() {
522522
installPlanRef = sub.Status.InstallPlanRef.Name
523523

524524
// Wait for the installplan to complete (5 minute timeout)
525-
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
525+
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, testNamespace, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
526526
Expect(err).ToNot(HaveOccurred(), "could not get installplan at complete phase")
527527

528528
// Ensure the new csv is installed
@@ -599,7 +599,7 @@ var _ = Describe("Garbage collection for dependent resources", func() {
599599
installPlanRef = sub.Status.InstallPlanRef.Name
600600

601601
// Wait for the installplan to complete (5 minute timeout)
602-
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
602+
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, testNamespace, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
603603
Expect(err).ToNot(HaveOccurred(), "could not get installplan at complete phase")
604604

605605
Eventually(func() error {
@@ -636,7 +636,7 @@ var _ = Describe("Garbage collection for dependent resources", func() {
636636
installPlanRef = sub.Status.InstallPlanRef.Name
637637

638638
// Wait for the installplan to complete (5 minute timeout)
639-
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
639+
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, testNamespace, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
640640
Expect(err).ToNot(HaveOccurred(), "could not get installplan at complete phase")
641641

642642
// Ensure the new csv is installed

0 commit comments

Comments
 (0)