@@ -14,95 +14,13 @@ import (
14
14
15
15
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
16
16
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
17
- apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
18
17
k8serrors "k8s.io/apimachinery/pkg/api/errors"
19
18
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
19
)
21
20
22
21
var _ = Describe ("CRD Versions" , func () {
23
22
AfterEach (func () { TearDown (testNamespace ) }, float64 (30 ))
24
23
25
- It ("creates v1beta1 crds with a v1beta1 schema successfully" , func () {
26
- By ("This test proves that OLM is able to handle v1beta1 CRDs successfully. Creating v1 CRDs has more " +
27
- "restrictions around the schema. v1beta1 validation schemas are not necessarily valid in v1. " +
28
- "OLM should support both v1beta1 and v1 CRDs" )
29
- c := newKubeClient ()
30
- crc := newCRClient ()
31
-
32
- mainPackageName := genName ("nginx-update2-" )
33
- mainPackageStable := fmt .Sprintf ("%s-stable" , mainPackageName )
34
- stableChannel := "stable"
35
-
36
- crdPlural := genName ("ins-v1beta1-" )
37
- crdName := crdPlural + ".cluster.com"
38
- mainCRD := apiextensions.CustomResourceDefinition {
39
- ObjectMeta : metav1.ObjectMeta {
40
- Name : crdName ,
41
- },
42
- Spec : apiextensions.CustomResourceDefinitionSpec {
43
- Group : "cluster.com" ,
44
- Versions : []apiextensions.CustomResourceDefinitionVersion {
45
- {
46
- Name : "v1alpha1" ,
47
- Served : true ,
48
- Storage : true ,
49
- },
50
- },
51
- Names : apiextensions.CustomResourceDefinitionNames {
52
- Plural : crdPlural ,
53
- Singular : crdPlural ,
54
- Kind : crdPlural ,
55
- ListKind : "list" + crdPlural ,
56
- },
57
- Scope : "Namespaced" ,
58
- // this validation is not a valid v1 structural schema because the "type: object" field is missing
59
- Validation : & apiextensions.CustomResourceValidation {
60
- OpenAPIV3Schema : & apiextensions.JSONSchemaProps {
61
- Description : "my crd schema" ,
62
- },
63
- },
64
- },
65
- }
66
-
67
- mainCSV := newCSV (mainPackageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {mainCRD }, nil , nil )
68
- mainCatalogName := genName ("mock-ocs-main-update2-" )
69
- mainManifests := []registry.PackageManifest {
70
- {
71
- PackageName : mainPackageName ,
72
- Channels : []registry.PackageChannel {
73
- {Name : stableChannel , CurrentCSVName : mainPackageStable },
74
- },
75
- DefaultChannelName : stableChannel ,
76
- },
77
- }
78
-
79
- // Create the catalog sources
80
- _ , cleanupMainCatalogSource := createInternalCatalogSource (c , crc , mainCatalogName , testNamespace , mainManifests , []apiextensions.CustomResourceDefinition {mainCRD }, []operatorsv1alpha1.ClusterServiceVersion {mainCSV })
81
- defer cleanupMainCatalogSource ()
82
-
83
- // Attempt to get the catalog source before creating install plan
84
- _ , err := fetchCatalogSourceOnStatus (crc , mainCatalogName , testNamespace , catalogSourceRegistryPodSynced )
85
- Expect (err ).ToNot (HaveOccurred ())
86
-
87
- subscriptionName := genName ("sub-nginx-update2-" )
88
- subscriptionCleanup := createSubscriptionForCatalog (crc , testNamespace , subscriptionName , mainCatalogName , mainPackageName , stableChannel , "" , operatorsv1alpha1 .ApprovalAutomatic )
89
- defer subscriptionCleanup ()
90
-
91
- subscription , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
92
- Expect (err ).ToNot (HaveOccurred ())
93
- Expect (subscription ).ToNot (Equal (nil ))
94
- Expect (subscription .Status .InstallPlanRef ).ToNot (Equal (nil ))
95
- Expect (mainCSV .GetName ()).To (Equal (subscription .Status .CurrentCSV ))
96
-
97
- installPlanName := subscription .Status .InstallPlanRef .Name
98
-
99
- // Wait for InstallPlan to be status: Complete before checking resource presence
100
- fetchedInstallPlan , err := fetchInstallPlan (GinkgoT (), crc , installPlanName , buildInstallPlanPhaseCheckFunc (operatorsv1alpha1 .InstallPlanPhaseComplete ))
101
- Expect (err ).ToNot (HaveOccurred ())
102
- GinkgoT ().Logf ("Install plan %s fetched with status %s" , fetchedInstallPlan .GetName (), fetchedInstallPlan .Status .Phase )
103
- Expect (fetchedInstallPlan .Status .Phase ).To (Equal (operatorsv1alpha1 .InstallPlanPhaseComplete ))
104
- })
105
-
106
24
It ("creates v1 CRDs with a v1 schema successfully" , func () {
107
25
By ("v1 crds with a valid openapiv3 schema should be created successfully by OLM" )
108
26
c := newKubeClient ()
@@ -112,13 +30,14 @@ var _ = Describe("CRD Versions", func() {
112
30
mainPackageStable := fmt .Sprintf ("%s-stable" , mainPackageName )
113
31
stableChannel := "stable"
114
32
115
- crdPlural := genName ("ins-v1beta1- " )
33
+ crdPlural := genName ("ins-" )
116
34
crdName := crdPlural + ".cluster.com"
117
35
v1crd := apiextensionsv1.CustomResourceDefinition {
118
36
ObjectMeta : metav1.ObjectMeta {
119
37
Name : crdName ,
120
38
},
121
39
Spec : apiextensionsv1.CustomResourceDefinitionSpec {
40
+ Scope : apiextensionsv1 .NamespaceScoped ,
122
41
Group : "cluster.com" ,
123
42
Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
124
43
{
@@ -185,7 +104,7 @@ var _ = Describe("CRD Versions", func() {
185
104
mainPackageStable := fmt .Sprintf ("%s-stable" , mainPackageName )
186
105
stableChannel := "stable"
187
106
188
- crdPlural := genName ("ins-v1beta1- " )
107
+ crdPlural := genName ("ins-" )
189
108
crdName := crdPlural + ".cluster.com"
190
109
oldCRD := apiextensions.CustomResourceDefinition {
191
110
ObjectMeta : metav1.ObjectMeta {
@@ -209,6 +128,12 @@ var _ = Describe("CRD Versions", func() {
209
128
Name : "v2alpha1" ,
210
129
Served : true ,
211
130
Storage : false ,
131
+ Schema : & apiextensions.CustomResourceValidation {
132
+ OpenAPIV3Schema : & apiextensions.JSONSchemaProps {
133
+ Type : "object" ,
134
+ Description : "my crd schema" ,
135
+ },
136
+ },
212
137
},
213
138
},
214
139
Names : apiextensions.CustomResourceDefinitionNames {
@@ -217,7 +142,7 @@ var _ = Describe("CRD Versions", func() {
217
142
Kind : crdPlural ,
218
143
ListKind : "list" + crdPlural ,
219
144
},
220
- Scope : "Namespaced" ,
145
+ Scope : apiextensions . NamespaceScoped ,
221
146
},
222
147
}
223
148
@@ -245,6 +170,12 @@ var _ = Describe("CRD Versions", func() {
245
170
Name : "v2alpha2" ,
246
171
Served : true ,
247
172
Storage : false ,
173
+ Schema : & apiextensions.CustomResourceValidation {
174
+ OpenAPIV3Schema : & apiextensions.JSONSchemaProps {
175
+ Type : "object" ,
176
+ Description : "my crd schema" ,
177
+ },
178
+ },
248
179
},
249
180
},
250
181
Names : apiextensions.CustomResourceDefinitionNames {
@@ -253,6 +184,7 @@ var _ = Describe("CRD Versions", func() {
253
184
Kind : crdPlural ,
254
185
ListKind : "list" + crdPlural ,
255
186
},
187
+ Scope : apiextensions .NamespaceScoped ,
256
188
},
257
189
}
258
190
@@ -352,49 +284,60 @@ var _ = Describe("CRD Versions", func() {
352
284
crdName := crdPlural + ".cluster.com"
353
285
crdGroup := "cluster.com"
354
286
355
- oldCRD := & apiextensionsv1beta1 .CustomResourceDefinition {
287
+ oldCRD := & apiextensionsv1 .CustomResourceDefinition {
356
288
ObjectMeta : metav1.ObjectMeta {
357
289
Name : crdName ,
358
290
},
359
- Spec : apiextensionsv1beta1 .CustomResourceDefinitionSpec {
291
+ Spec : apiextensionsv1 .CustomResourceDefinitionSpec {
360
292
Group : crdGroup ,
361
- Versions : []apiextensionsv1beta1 .CustomResourceDefinitionVersion {
293
+ Versions : []apiextensionsv1 .CustomResourceDefinitionVersion {
362
294
{
363
295
Name : "v1alpha1" ,
364
296
Served : true ,
365
297
Storage : true ,
298
+ Schema : & apiextensionsv1.CustomResourceValidation {
299
+ OpenAPIV3Schema : & apiextensionsv1.JSONSchemaProps {
300
+ Type : "object" ,
301
+ Description : "my crd schema" ,
302
+ },
303
+ },
366
304
},
367
305
},
368
- Names : apiextensionsv1beta1 .CustomResourceDefinitionNames {
306
+ Names : apiextensionsv1 .CustomResourceDefinitionNames {
369
307
Plural : crdPlural ,
370
308
Singular : crdPlural ,
371
309
Kind : crdPlural ,
372
310
ListKind : "list" + crdPlural ,
373
311
},
374
- Scope : "Namespaced" ,
312
+ Scope : apiextensionsv1 . NamespaceScoped ,
375
313
},
376
314
}
377
- _ , err := c .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Create (context .TODO (), oldCRD , metav1.CreateOptions {})
315
+ _ , err := c .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Create (context .TODO (), oldCRD , metav1.CreateOptions {})
378
316
Expect (err ).ToNot (HaveOccurred (), "error creating old CRD" )
379
317
380
318
// wrap CRD update in a poll because of the object has been modified related errors
381
319
Eventually (func () error {
382
- oldCRD , err = c .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (context .TODO (), oldCRD .GetName (), metav1.GetOptions {})
320
+ oldCRD , err = c .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .TODO (), oldCRD .GetName (), metav1.GetOptions {})
383
321
if err != nil {
384
322
return err
385
323
}
386
324
GinkgoT ().Logf ("old crd status stored versions: %#v" , oldCRD .Status .StoredVersions )
387
325
388
- // set v1alpha1 to no longer served
326
+ // set v1alpha1 to no longer stored
389
327
oldCRD .Spec .Versions [0 ].Storage = false
390
328
// update CRD on-cluster with a new version
391
- oldCRD .Spec .Versions = append (oldCRD .Spec .Versions , apiextensionsv1beta1 .CustomResourceDefinitionVersion {
329
+ oldCRD .Spec .Versions = append (oldCRD .Spec .Versions , apiextensionsv1 .CustomResourceDefinitionVersion {
392
330
Name : "v1alpha2" ,
393
331
Served : true ,
394
332
Storage : true ,
333
+ Schema : & apiextensionsv1.CustomResourceValidation {
334
+ OpenAPIV3Schema : & apiextensionsv1.JSONSchemaProps {
335
+ Type : "object" ,
336
+ },
337
+ },
395
338
})
396
339
397
- updatedCRD , err := c .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Update (context .TODO (), oldCRD , metav1.UpdateOptions {})
340
+ updatedCRD , err := c .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Update (context .TODO (), oldCRD , metav1.UpdateOptions {})
398
341
if err != nil {
399
342
return err
400
343
}
@@ -414,6 +357,12 @@ var _ = Describe("CRD Versions", func() {
414
357
Name : "v1alpha2" ,
415
358
Served : true ,
416
359
Storage : true ,
360
+ Schema : & apiextensions.CustomResourceValidation {
361
+ OpenAPIV3Schema : & apiextensions.JSONSchemaProps {
362
+ Type : "object" ,
363
+ Description : "my crd schema" ,
364
+ },
365
+ },
417
366
},
418
367
},
419
368
Names : apiextensions.CustomResourceDefinitionNames {
@@ -422,7 +371,7 @@ var _ = Describe("CRD Versions", func() {
422
371
Kind : crdPlural ,
423
372
ListKind : "list" + crdPlural ,
424
373
},
425
- Scope : "Namespaced" ,
374
+ Scope : apiextensions . NamespaceScoped ,
426
375
},
427
376
}
428
377
@@ -471,10 +420,10 @@ var _ = Describe("CRD Versions", func() {
471
420
))
472
421
473
422
// update CRD status to remove the v1alpha1 stored version
474
- newCRD , err := c .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (context .TODO (), oldCRD .GetName (), metav1.GetOptions {})
423
+ newCRD , err := c .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .TODO (), oldCRD .GetName (), metav1.GetOptions {})
475
424
Expect (err ).ToNot (HaveOccurred (), "error getting new CRD" )
476
425
newCRD .Status .StoredVersions = []string {"v1alpha2" }
477
- newCRD , err = c .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().UpdateStatus (context .TODO (), newCRD , metav1.UpdateOptions {})
426
+ newCRD , err = c .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().UpdateStatus (context .TODO (), newCRD , metav1.UpdateOptions {})
478
427
Expect (err ).ToNot (HaveOccurred (), "error updating new CRD" )
479
428
GinkgoT ().Logf ("new crd status stored versions: %#v" , newCRD .Status .StoredVersions ) // only v1alpha2 should be in the status now
480
429
0 commit comments