Skip to content

Commit 75d8fbe

Browse files
committed
fix(e2e): Run each test in CRD suite in separate namespace
Signed-off-by: Vu Dinh <[email protected]>
1 parent 80515d1 commit 75d8fbe

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

test/e2e/crd_e2e_test.go

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,31 @@ import (
1212
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
1313
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
1414

15+
corev1 "k8s.io/api/core/v1"
1516
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
1617
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1718
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920
)
2021

2122
var _ = Describe("CRD Versions", func() {
22-
AfterEach(func() { TearDown(testNamespace) }, float64(30))
23+
var (
24+
ns corev1.Namespace
25+
generatedNamespace string
26+
)
27+
BeforeEach(func() {
28+
generatedNamespace, ns = SetUpGeneratedTestNamespace(testNamespace)
29+
})
30+
31+
AfterEach(func() {
32+
TearDown(testNamespace)
33+
TearDown(generatedNamespace)
34+
Eventually(func() error {
35+
return ctx.Ctx().Client().Delete(context.Background(), &ns)
36+
}).Should(Succeed())
37+
},
38+
float64(30),
39+
)
2340

2441
It("creates v1 CRDs with a v1 schema successfully", func() {
2542
By("v1 crds with a valid openapiv3 schema should be created successfully by OLM")
@@ -55,7 +72,7 @@ var _ = Describe("CRD Versions", func() {
5572
},
5673
}
5774

58-
mainCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), nil, nil, nil)
75+
mainCSV := newCSV(mainPackageStable, generatedNamespace, "", semver.MustParse("0.1.0"), nil, nil, nil)
5976
mainCatalogName := genName("mock-ocs-main-update2-")
6077
mainManifests := []registry.PackageManifest{
6178
{
@@ -68,18 +85,18 @@ var _ = Describe("CRD Versions", func() {
6885
}
6986

7087
// Create the catalog sources
71-
_, cleanupMainCatalogSource := createV1CRDInternalCatalogSource(GinkgoT(), c, crc, mainCatalogName, testNamespace, mainManifests, []apiextensionsv1.CustomResourceDefinition{v1crd}, []operatorsv1alpha1.ClusterServiceVersion{mainCSV})
88+
_, cleanupMainCatalogSource := createV1CRDInternalCatalogSource(GinkgoT(), c, crc, mainCatalogName, generatedNamespace, mainManifests, []apiextensionsv1.CustomResourceDefinition{v1crd}, []operatorsv1alpha1.ClusterServiceVersion{mainCSV})
7289
defer cleanupMainCatalogSource()
7390

7491
// Attempt to get the catalog source before creating install plan
75-
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
92+
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, generatedNamespace, catalogSourceRegistryPodSynced)
7693
Expect(err).ToNot(HaveOccurred())
7794

7895
subscriptionName := genName("sub-nginx-update2-")
79-
subscriptionCleanup := createSubscriptionForCatalog(crc, testNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
96+
subscriptionCleanup := createSubscriptionForCatalog(crc, generatedNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
8097
defer subscriptionCleanup()
8198

82-
subscription, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
99+
subscription, err := fetchSubscription(crc, generatedNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
83100
Expect(err).ToNot(HaveOccurred())
84101
Expect(subscription).ToNot(Equal(nil))
85102
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
@@ -88,7 +105,7 @@ var _ = Describe("CRD Versions", func() {
88105
installPlanName := subscription.Status.InstallPlanRef.Name
89106

90107
// Wait for InstallPlan to be status: Complete before checking resource presence
91-
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
108+
fetchedInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, installPlanName, generatedNamespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
92109
Expect(err).ToNot(HaveOccurred())
93110
GinkgoT().Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase)
94111
Expect(fetchedInstallPlan.Status.Phase).To(Equal(operatorsv1alpha1.InstallPlanPhaseComplete))
@@ -188,8 +205,8 @@ var _ = Describe("CRD Versions", func() {
188205
},
189206
}
190207

191-
oldCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{oldCRD}, nil, nil)
192-
newCSV := newCSV(mainPackageAlpha, testNamespace, mainPackageStable, semver.MustParse("0.1.1"), []apiextensions.CustomResourceDefinition{newCRD}, nil, nil)
208+
oldCSV := newCSV(mainPackageStable, generatedNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{oldCRD}, nil, nil)
209+
newCSV := newCSV(mainPackageAlpha, generatedNamespace, mainPackageStable, semver.MustParse("0.1.1"), []apiextensions.CustomResourceDefinition{newCRD}, nil, nil)
193210
mainCatalogName := genName("mock-ocs-main-update2-")
194211
mainManifests := []registry.PackageManifest{
195212
{
@@ -203,18 +220,18 @@ var _ = Describe("CRD Versions", func() {
203220
}
204221

205222
// Create the catalog sources
206-
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, testNamespace, mainManifests, []apiextensions.CustomResourceDefinition{oldCRD, newCRD}, []operatorsv1alpha1.ClusterServiceVersion{oldCSV, newCSV})
223+
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, generatedNamespace, mainManifests, []apiextensions.CustomResourceDefinition{oldCRD, newCRD}, []operatorsv1alpha1.ClusterServiceVersion{oldCSV, newCSV})
207224
defer cleanupMainCatalogSource()
208225

209226
// Attempt to get the catalog source before creating install plan
210-
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
227+
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, generatedNamespace, catalogSourceRegistryPodSynced)
211228
Expect(err).ToNot(HaveOccurred())
212229

213230
subscriptionName := genName("sub-nginx-update2-")
214-
subscriptionCleanup := createSubscriptionForCatalog(crc, testNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
231+
subscriptionCleanup := createSubscriptionForCatalog(crc, generatedNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
215232
defer subscriptionCleanup()
216233

217-
subscription, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
234+
subscription, err := fetchSubscription(crc, generatedNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
218235
Expect(err).ToNot(HaveOccurred())
219236
Expect(subscription).ToNot(BeNil())
220237
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
@@ -223,7 +240,7 @@ var _ = Describe("CRD Versions", func() {
223240
installPlanName := subscription.Status.InstallPlanRef.Name
224241

225242
// Wait for InstallPlan to be status: Complete before checking resource presence
226-
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
243+
fetchedInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, installPlanName, generatedNamespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
227244
Expect(err).ToNot(HaveOccurred())
228245
GinkgoT().Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase)
229246
Expect(fetchedInstallPlan.Status.Phase).To(Equal(operatorsv1alpha1.InstallPlanPhaseComplete))
@@ -242,14 +259,14 @@ var _ = Describe("CRD Versions", func() {
242259
}
243260

244261
// fetch new subscription
245-
s, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
262+
s, err := fetchSubscription(crc, generatedNamespace, subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
246263
Expect(err).ToNot(HaveOccurred())
247264
Expect(s).ToNot(BeNil())
248265
Expect(s.Status.InstallPlanRef).ToNot(Equal(nil))
249266

250267
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version
251268
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
252-
return crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
269+
return crc.OperatorsV1alpha1().InstallPlans(generatedNamespace).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
253270
}).Should(And(
254271
WithTransform(
255272
func(v *operatorsv1alpha1.InstallPlan) operatorsv1alpha1.InstallPlanPhase {
@@ -378,7 +395,7 @@ var _ = Describe("CRD Versions", func() {
378395
mainPackageName := genName("nginx-update2-")
379396
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
380397
stableChannel := "stable"
381-
catalogCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{catalogCRD}, nil, nil)
398+
catalogCSV := newCSV(mainPackageStable, generatedNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{catalogCRD}, nil, nil)
382399

383400
mainCatalogName := genName("mock-ocs-main-update2-")
384401
mainManifests := []registry.PackageManifest{
@@ -392,17 +409,17 @@ var _ = Describe("CRD Versions", func() {
392409
}
393410

394411
// Create the catalog sources
395-
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, testNamespace, mainManifests, []apiextensions.CustomResourceDefinition{catalogCRD}, []operatorsv1alpha1.ClusterServiceVersion{catalogCSV})
412+
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, generatedNamespace, mainManifests, []apiextensions.CustomResourceDefinition{catalogCRD}, []operatorsv1alpha1.ClusterServiceVersion{catalogCSV})
396413
defer cleanupMainCatalogSource()
397414

398415
// Attempt to get the catalog source before creating install plan
399-
_, err = fetchCatalogSourceOnStatus(crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
416+
_, err = fetchCatalogSourceOnStatus(crc, mainCatalogName, generatedNamespace, catalogSourceRegistryPodSynced)
400417
Expect(err).ToNot(HaveOccurred())
401418

402419
subscriptionName := genName("sub-nginx-update2-")
403-
_ = createSubscriptionForCatalog(crc, testNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
420+
_ = createSubscriptionForCatalog(crc, generatedNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
404421

405-
subscription, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
422+
subscription, err := fetchSubscription(crc, generatedNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
406423
Expect(err).ToNot(HaveOccurred())
407424
Expect(subscription).ToNot(BeNil())
408425
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
@@ -411,7 +428,7 @@ var _ = Describe("CRD Versions", func() {
411428
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version (v1alpha1)
412429
Eventually(
413430
func() (*operatorsv1alpha1.InstallPlan, error) {
414-
return crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.GetOptions{})
431+
return crc.OperatorsV1alpha1().InstallPlans(generatedNamespace).Get(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.GetOptions{})
415432
},
416433
90*time.Second, // exhaust retries
417434
).Should(WithTransform(
@@ -429,36 +446,36 @@ var _ = Describe("CRD Versions", func() {
429446

430447
// install should now succeed
431448
oldInstallPlanRef := subscription.Status.InstallPlanRef.Name
432-
err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Delete(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.DeleteOptions{})
449+
err = crc.OperatorsV1alpha1().InstallPlans(generatedNamespace).Delete(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.DeleteOptions{})
433450
Expect(err).ToNot(HaveOccurred(), "error deleting failed install plan")
434451
// remove old subscription
435-
err = crc.OperatorsV1alpha1().Subscriptions(testNamespace).Delete(context.TODO(), subscription.GetName(), metav1.DeleteOptions{})
452+
err = crc.OperatorsV1alpha1().Subscriptions(generatedNamespace).Delete(context.TODO(), subscription.GetName(), metav1.DeleteOptions{})
436453
Expect(err).ToNot(HaveOccurred(), "error deleting old subscription")
437454
// remove old csv
438-
crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).Delete(context.TODO(), mainPackageStable, metav1.DeleteOptions{})
455+
crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace).Delete(context.TODO(), mainPackageStable, metav1.DeleteOptions{})
439456
Expect(err).ToNot(HaveOccurred(), "error deleting old subscription")
440457

441458
// recreate subscription
442459
subscriptionNameNew := genName("sub-nginx-update2-new-")
443-
_ = createSubscriptionForCatalog(crc, testNamespace, subscriptionNameNew, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
460+
_ = createSubscriptionForCatalog(crc, generatedNamespace, subscriptionNameNew, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
444461

445-
subscription, err = fetchSubscription(crc, testNamespace, subscriptionNameNew, subscriptionHasInstallPlanChecker)
462+
subscription, err = fetchSubscription(crc, generatedNamespace, subscriptionNameNew, subscriptionHasInstallPlanChecker)
446463
Expect(err).ToNot(HaveOccurred())
447464
Expect(subscription).ToNot(BeNil())
448465
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
449466
Expect(catalogCSV.GetName()).To(Equal(subscription.Status.CurrentCSV))
450467

451468
// eventually the subscription should create a new install plan
452469
Eventually(func() bool {
453-
sub, _ := crc.OperatorsV1alpha1().Subscriptions(testNamespace).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
470+
sub, _ := crc.OperatorsV1alpha1().Subscriptions(generatedNamespace).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
454471
GinkgoT().Logf("waiting for subscription %s to generate a new install plan...", subscription.GetName())
455472
return sub.Status.InstallPlanRef.Name != oldInstallPlanRef
456473
}, 5*time.Minute, 10*time.Second).Should(BeTrue())
457474

458475
// eventually the new installplan should succeed
459476
Eventually(func() bool {
460-
sub, _ := crc.OperatorsV1alpha1().Subscriptions(testNamespace).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
461-
ip, err := crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), sub.Status.InstallPlanRef.Name, metav1.GetOptions{})
477+
sub, _ := crc.OperatorsV1alpha1().Subscriptions(generatedNamespace).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
478+
ip, err := crc.OperatorsV1alpha1().InstallPlans(generatedNamespace).Get(context.TODO(), sub.Status.InstallPlanRef.Name, metav1.GetOptions{})
462479
if k8serrors.IsNotFound(err) {
463480
return false
464481
}

0 commit comments

Comments
 (0)