@@ -12,14 +12,31 @@ import (
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
14
15
+ corev1 "k8s.io/api/core/v1"
15
16
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
16
17
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
17
18
k8serrors "k8s.io/apimachinery/pkg/api/errors"
18
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19
20
)
20
21
21
22
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
+ )
23
40
24
41
It ("creates v1 CRDs with a v1 schema successfully" , func () {
25
42
By ("v1 crds with a valid openapiv3 schema should be created successfully by OLM" )
@@ -55,7 +72,7 @@ var _ = Describe("CRD Versions", func() {
55
72
},
56
73
}
57
74
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 )
59
76
mainCatalogName := genName ("mock-ocs-main-update2-" )
60
77
mainManifests := []registry.PackageManifest {
61
78
{
@@ -68,18 +85,18 @@ var _ = Describe("CRD Versions", func() {
68
85
}
69
86
70
87
// 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 })
72
89
defer cleanupMainCatalogSource ()
73
90
74
91
// Attempt to get the catalog source before creating install plan
75
- _ , err := fetchCatalogSourceOnStatus (crc , mainCatalogName , testNamespace , catalogSourceRegistryPodSynced )
92
+ _ , err := fetchCatalogSourceOnStatus (crc , mainCatalogName , generatedNamespace , catalogSourceRegistryPodSynced )
76
93
Expect (err ).ToNot (HaveOccurred ())
77
94
78
95
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 )
80
97
defer subscriptionCleanup ()
81
98
82
- subscription , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
99
+ subscription , err := fetchSubscription (crc , generatedNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
83
100
Expect (err ).ToNot (HaveOccurred ())
84
101
Expect (subscription ).ToNot (Equal (nil ))
85
102
Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
@@ -88,7 +105,7 @@ var _ = Describe("CRD Versions", func() {
88
105
installPlanName := subscription .Status .InstallPlanRef .Name
89
106
90
107
// 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 ))
92
109
Expect (err ).ToNot (HaveOccurred ())
93
110
GinkgoT ().Logf ("Install plan %s fetched with status %s" , fetchedInstallPlan .GetName (), fetchedInstallPlan .Status .Phase )
94
111
Expect (fetchedInstallPlan .Status .Phase ).To (Equal (operatorsv1alpha1 .InstallPlanPhaseComplete ))
@@ -188,8 +205,8 @@ var _ = Describe("CRD Versions", func() {
188
205
},
189
206
}
190
207
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 )
193
210
mainCatalogName := genName ("mock-ocs-main-update2-" )
194
211
mainManifests := []registry.PackageManifest {
195
212
{
@@ -203,18 +220,18 @@ var _ = Describe("CRD Versions", func() {
203
220
}
204
221
205
222
// 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 })
207
224
defer cleanupMainCatalogSource ()
208
225
209
226
// Attempt to get the catalog source before creating install plan
210
- _ , err := fetchCatalogSourceOnStatus (crc , mainCatalogName , testNamespace , catalogSourceRegistryPodSynced )
227
+ _ , err := fetchCatalogSourceOnStatus (crc , mainCatalogName , generatedNamespace , catalogSourceRegistryPodSynced )
211
228
Expect (err ).ToNot (HaveOccurred ())
212
229
213
230
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 )
215
232
defer subscriptionCleanup ()
216
233
217
- subscription , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
234
+ subscription , err := fetchSubscription (crc , generatedNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
218
235
Expect (err ).ToNot (HaveOccurred ())
219
236
Expect (subscription ).ToNot (BeNil ())
220
237
Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
@@ -223,7 +240,7 @@ var _ = Describe("CRD Versions", func() {
223
240
installPlanName := subscription .Status .InstallPlanRef .Name
224
241
225
242
// 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 ))
227
244
Expect (err ).ToNot (HaveOccurred ())
228
245
GinkgoT ().Logf ("Install plan %s fetched with status %s" , fetchedInstallPlan .GetName (), fetchedInstallPlan .Status .Phase )
229
246
Expect (fetchedInstallPlan .Status .Phase ).To (Equal (operatorsv1alpha1 .InstallPlanPhaseComplete ))
@@ -242,14 +259,14 @@ var _ = Describe("CRD Versions", func() {
242
259
}
243
260
244
261
// fetch new subscription
245
- s , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionAtLatestWithDifferentInstallPlan )
262
+ s , err := fetchSubscription (crc , generatedNamespace , subscriptionName , subscriptionAtLatestWithDifferentInstallPlan )
246
263
Expect (err ).ToNot (HaveOccurred ())
247
264
Expect (s ).ToNot (BeNil ())
248
265
Expect (s .Status .InstallPlanRef ).ToNot (Equal (nil ))
249
266
250
267
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version
251
268
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 {})
253
270
}).Should (And (
254
271
WithTransform (
255
272
func (v * operatorsv1alpha1.InstallPlan ) operatorsv1alpha1.InstallPlanPhase {
@@ -378,7 +395,7 @@ var _ = Describe("CRD Versions", func() {
378
395
mainPackageName := genName ("nginx-update2-" )
379
396
mainPackageStable := fmt .Sprintf ("%s-stable" , mainPackageName )
380
397
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 )
382
399
383
400
mainCatalogName := genName ("mock-ocs-main-update2-" )
384
401
mainManifests := []registry.PackageManifest {
@@ -392,17 +409,17 @@ var _ = Describe("CRD Versions", func() {
392
409
}
393
410
394
411
// 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 })
396
413
defer cleanupMainCatalogSource ()
397
414
398
415
// Attempt to get the catalog source before creating install plan
399
- _ , err = fetchCatalogSourceOnStatus (crc , mainCatalogName , testNamespace , catalogSourceRegistryPodSynced )
416
+ _ , err = fetchCatalogSourceOnStatus (crc , mainCatalogName , generatedNamespace , catalogSourceRegistryPodSynced )
400
417
Expect (err ).ToNot (HaveOccurred ())
401
418
402
419
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 )
404
421
405
- subscription , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
422
+ subscription , err := fetchSubscription (crc , generatedNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
406
423
Expect (err ).ToNot (HaveOccurred ())
407
424
Expect (subscription ).ToNot (BeNil ())
408
425
Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
@@ -411,7 +428,7 @@ var _ = Describe("CRD Versions", func() {
411
428
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version (v1alpha1)
412
429
Eventually (
413
430
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 {})
415
432
},
416
433
90 * time .Second , // exhaust retries
417
434
).Should (WithTransform (
@@ -429,36 +446,36 @@ var _ = Describe("CRD Versions", func() {
429
446
430
447
// install should now succeed
431
448
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 {})
433
450
Expect (err ).ToNot (HaveOccurred (), "error deleting failed install plan" )
434
451
// 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 {})
436
453
Expect (err ).ToNot (HaveOccurred (), "error deleting old subscription" )
437
454
// 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 {})
439
456
Expect (err ).ToNot (HaveOccurred (), "error deleting old subscription" )
440
457
441
458
// recreate subscription
442
459
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 )
444
461
445
- subscription , err = fetchSubscription (crc , testNamespace , subscriptionNameNew , subscriptionHasInstallPlanChecker )
462
+ subscription , err = fetchSubscription (crc , generatedNamespace , subscriptionNameNew , subscriptionHasInstallPlanChecker )
446
463
Expect (err ).ToNot (HaveOccurred ())
447
464
Expect (subscription ).ToNot (BeNil ())
448
465
Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
449
466
Expect (catalogCSV .GetName ()).To (Equal (subscription .Status .CurrentCSV ))
450
467
451
468
// eventually the subscription should create a new install plan
452
469
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 {})
454
471
GinkgoT ().Logf ("waiting for subscription %s to generate a new install plan..." , subscription .GetName ())
455
472
return sub .Status .InstallPlanRef .Name != oldInstallPlanRef
456
473
}, 5 * time .Minute , 10 * time .Second ).Should (BeTrue ())
457
474
458
475
// eventually the new installplan should succeed
459
476
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 {})
462
479
if k8serrors .IsNotFound (err ) {
463
480
return false
464
481
}
0 commit comments