@@ -11,6 +11,7 @@ import (
11
11
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
12
12
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
13
13
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
14
+ corev1 "k8s.io/api/core/v1"
14
15
15
16
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
16
17
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -19,7 +20,18 @@ import (
19
20
)
20
21
21
22
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
+ })
23
35
24
36
// issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2640
25
37
It ("[FLAKE] creates v1 CRDs with a v1 schema successfully" , func () {
@@ -56,7 +68,7 @@ var _ = Describe("CRD Versions", func() {
56
68
},
57
69
}
58
70
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 )
60
72
mainCatalogName := genName ("mock-ocs-main-update2-" )
61
73
mainManifests := []registry.PackageManifest {
62
74
{
@@ -69,18 +81,22 @@ var _ = Describe("CRD Versions", func() {
69
81
}
70
82
71
83
// 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 })
73
85
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
+ }()
74
90
75
91
// 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 )
77
93
Expect (err ).ToNot (HaveOccurred ())
78
94
79
95
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 )
81
97
defer subscriptionCleanup ()
82
98
83
- subscription , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
99
+ subscription , err := fetchSubscription (crc , ns . GetName () , subscriptionName , subscriptionHasInstallPlanChecker )
84
100
Expect (err ).ToNot (HaveOccurred ())
85
101
Expect (subscription ).ToNot (Equal (nil ))
86
102
Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
@@ -89,7 +105,7 @@ var _ = Describe("CRD Versions", func() {
89
105
installPlanName := subscription .Status .InstallPlanRef .Name
90
106
91
107
// 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 ))
93
109
Expect (err ).ToNot (HaveOccurred ())
94
110
GinkgoT ().Logf ("Install plan %s fetched with status %s" , fetchedInstallPlan .GetName (), fetchedInstallPlan .Status .Phase )
95
111
Expect (fetchedInstallPlan .Status .Phase ).To (Equal (operatorsv1alpha1 .InstallPlanPhaseComplete ))
@@ -190,8 +206,8 @@ var _ = Describe("CRD Versions", func() {
190
206
},
191
207
}
192
208
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 )
195
211
mainCatalogName := genName ("mock-ocs-main-update2-" )
196
212
mainManifests := []registry.PackageManifest {
197
213
{
@@ -205,18 +221,24 @@ var _ = Describe("CRD Versions", func() {
205
221
}
206
222
207
223
// 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 })
209
225
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
+ }()
210
232
211
233
// 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 )
213
235
Expect (err ).ToNot (HaveOccurred ())
214
236
215
237
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 )
217
239
defer subscriptionCleanup ()
218
240
219
- subscription , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
241
+ subscription , err := fetchSubscription (crc , ns . GetName () , subscriptionName , subscriptionHasInstallPlanChecker )
220
242
Expect (err ).ToNot (HaveOccurred ())
221
243
Expect (subscription ).ToNot (BeNil ())
222
244
Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
@@ -225,7 +247,7 @@ var _ = Describe("CRD Versions", func() {
225
247
installPlanName := subscription .Status .InstallPlanRef .Name
226
248
227
249
// 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 ))
229
251
Expect (err ).ToNot (HaveOccurred ())
230
252
GinkgoT ().Logf ("Install plan %s fetched with status %s" , fetchedInstallPlan .GetName (), fetchedInstallPlan .Status .Phase )
231
253
Expect (fetchedInstallPlan .Status .Phase ).To (Equal (operatorsv1alpha1 .InstallPlanPhaseComplete ))
@@ -244,14 +266,14 @@ var _ = Describe("CRD Versions", func() {
244
266
}
245
267
246
268
// fetch new subscription
247
- s , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionAtLatestWithDifferentInstallPlan )
269
+ s , err := fetchSubscription (crc , ns . GetName () , subscriptionName , subscriptionAtLatestWithDifferentInstallPlan )
248
270
Expect (err ).ToNot (HaveOccurred ())
249
271
Expect (s ).ToNot (BeNil ())
250
272
Expect (s .Status .InstallPlanRef ).ToNot (Equal (nil ))
251
273
252
274
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version
253
275
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 {})
255
277
}).Should (And (
256
278
WithTransform (
257
279
func (v * operatorsv1alpha1.InstallPlan ) operatorsv1alpha1.InstallPlanPhase {
@@ -380,7 +402,11 @@ var _ = Describe("CRD Versions", func() {
380
402
mainPackageName := genName ("nginx-update2-" )
381
403
mainPackageStable := fmt .Sprintf ("%s-stable" , mainPackageName )
382
404
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
+ }()
384
410
385
411
mainCatalogName := genName ("mock-ocs-main-update2-" )
386
412
mainManifests := []registry.PackageManifest {
@@ -394,17 +420,17 @@ var _ = Describe("CRD Versions", func() {
394
420
}
395
421
396
422
// 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 })
398
424
defer cleanupMainCatalogSource ()
399
425
400
426
// 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 )
402
428
Expect (err ).ToNot (HaveOccurred ())
403
429
404
430
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 )
406
432
407
- subscription , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
433
+ subscription , err := fetchSubscription (crc , ns . GetName () , subscriptionName , subscriptionHasInstallPlanChecker )
408
434
Expect (err ).ToNot (HaveOccurred ())
409
435
Expect (subscription ).ToNot (BeNil ())
410
436
Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
@@ -413,7 +439,7 @@ var _ = Describe("CRD Versions", func() {
413
439
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version (v1alpha1)
414
440
Eventually (
415
441
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 {})
417
443
},
418
444
90 * time .Second , // exhaust retries
419
445
).Should (WithTransform (
@@ -431,36 +457,36 @@ var _ = Describe("CRD Versions", func() {
431
457
432
458
// install should now succeed
433
459
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 {})
435
461
Expect (err ).ToNot (HaveOccurred (), "error deleting failed install plan" )
436
462
// 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 {})
438
464
Expect (err ).ToNot (HaveOccurred (), "error deleting old subscription" )
439
465
// 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 {})
441
467
Expect (err ).ToNot (HaveOccurred (), "error deleting old subscription" )
442
468
443
469
// recreate subscription
444
470
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 )
446
472
447
- subscription , err = fetchSubscription (crc , testNamespace , subscriptionNameNew , subscriptionHasInstallPlanChecker )
473
+ subscription , err = fetchSubscription (crc , ns . GetName () , subscriptionNameNew , subscriptionHasInstallPlanChecker )
448
474
Expect (err ).ToNot (HaveOccurred ())
449
475
Expect (subscription ).ToNot (BeNil ())
450
476
Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
451
477
Expect (catalogCSV .GetName ()).To (Equal (subscription .Status .CurrentCSV ))
452
478
453
479
// eventually the subscription should create a new install plan
454
480
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 {})
456
482
GinkgoT ().Logf ("waiting for subscription %s to generate a new install plan..." , subscription .GetName ())
457
483
return sub .Status .InstallPlanRef .Name != oldInstallPlanRef
458
484
}, 5 * time .Minute , 10 * time .Second ).Should (BeTrue ())
459
485
460
486
// eventually the new installplan should succeed
461
487
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 {})
464
490
if k8serrors .IsNotFound (err ) {
465
491
return false
466
492
}
0 commit comments