@@ -226,8 +226,171 @@ var _ = Describe("Test", func() {
226
226
227
227
close (done )
228
228
}, 5 )
229
+
230
+ It ("should reinstall the CRDs if already present in the cluster" , func (done Done ) {
231
+
232
+ crds , err = InstallCRDs (env .Config , CRDInstallOptions {
233
+ Paths : []string {filepath .Join ("." , "testdata" )},
234
+ })
235
+ Expect (err ).NotTo (HaveOccurred ())
236
+
237
+ // Expect to find the CRDs
238
+
239
+ crd := & v1beta1.CustomResourceDefinition {}
240
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "foos.bar.example.com" }, crd )
241
+ Expect (err ).NotTo (HaveOccurred ())
242
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Foo" ))
243
+
244
+ crd = & v1beta1.CustomResourceDefinition {}
245
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "bazs.qux.example.com" }, crd )
246
+ Expect (err ).NotTo (HaveOccurred ())
247
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Baz" ))
248
+
249
+ crd = & v1beta1.CustomResourceDefinition {}
250
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "captains.crew.example.com" }, crd )
251
+ Expect (err ).NotTo (HaveOccurred ())
252
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Captain" ))
253
+
254
+ crd = & v1beta1.CustomResourceDefinition {}
255
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "firstmates.crew.example.com" }, crd )
256
+ Expect (err ).NotTo (HaveOccurred ())
257
+ Expect (crd .Spec .Names .Kind ).To (Equal ("FirstMate" ))
258
+
259
+ crd = & v1beta1.CustomResourceDefinition {}
260
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "drivers.crew.example.com" }, crd )
261
+ Expect (err ).NotTo (HaveOccurred ())
262
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Driver" ))
263
+
264
+ err = WaitForCRDs (env .Config , []* v1beta1.CustomResourceDefinition {
265
+ {
266
+ Spec : v1beta1.CustomResourceDefinitionSpec {
267
+ Group : "qux.example.com" ,
268
+ Version : "v1beta1" ,
269
+ Names : v1beta1.CustomResourceDefinitionNames {
270
+ Plural : "bazs" ,
271
+ }},
272
+ },
273
+ {
274
+ Spec : v1beta1.CustomResourceDefinitionSpec {
275
+ Group : "bar.example.com" ,
276
+ Version : "v1beta1" ,
277
+ Names : v1beta1.CustomResourceDefinitionNames {
278
+ Plural : "foos" ,
279
+ }},
280
+ },
281
+ {
282
+ Spec : v1beta1.CustomResourceDefinitionSpec {
283
+ Group : "crew.example.com" ,
284
+ Version : "v1beta1" ,
285
+ Names : v1beta1.CustomResourceDefinitionNames {
286
+ Plural : "captains" ,
287
+ }},
288
+ },
289
+ {
290
+ Spec : v1beta1.CustomResourceDefinitionSpec {
291
+ Group : "crew.example.com" ,
292
+ Version : "v1beta1" ,
293
+ Names : v1beta1.CustomResourceDefinitionNames {
294
+ Plural : "firstmates" ,
295
+ }},
296
+ },
297
+ {
298
+ Spec : v1beta1.CustomResourceDefinitionSpec {
299
+ Group : "crew.example.com" ,
300
+ Names : v1beta1.CustomResourceDefinitionNames {
301
+ Plural : "drivers" ,
302
+ },
303
+ Versions : []v1beta1.CustomResourceDefinitionVersion {
304
+ {
305
+ Name : "v1" ,
306
+ Storage : true ,
307
+ Served : true ,
308
+ },
309
+ {
310
+ Name : "v2" ,
311
+ Storage : false ,
312
+ Served : true ,
313
+ },
314
+ }},
315
+ },
316
+ },
317
+ CRDInstallOptions {MaxTime : 50 * time .Millisecond , PollInterval : 15 * time .Millisecond },
318
+ )
319
+ Expect (err ).NotTo (HaveOccurred ())
320
+
321
+ // Try to re-install the CRDs
322
+
323
+ crds , err = InstallCRDs (env .Config , CRDInstallOptions {
324
+ Paths : []string {filepath .Join ("." , "testdata" )},
325
+ })
326
+ Expect (err ).NotTo (HaveOccurred ())
327
+
328
+ // Expect to find the CRDs
329
+
330
+ crd = & v1beta1.CustomResourceDefinition {}
331
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "foos.bar.example.com" }, crd )
332
+ Expect (err ).NotTo (HaveOccurred ())
333
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Foo" ))
334
+
335
+ crd = & v1beta1.CustomResourceDefinition {}
336
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "bazs.qux.example.com" }, crd )
337
+ Expect (err ).NotTo (HaveOccurred ())
338
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Baz" ))
339
+
340
+ crd = & v1beta1.CustomResourceDefinition {}
341
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "captains.crew.example.com" }, crd )
342
+ Expect (err ).NotTo (HaveOccurred ())
343
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Captain" ))
344
+
345
+ crd = & v1beta1.CustomResourceDefinition {}
346
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "firstmates.crew.example.com" }, crd )
347
+ Expect (err ).NotTo (HaveOccurred ())
348
+ Expect (crd .Spec .Names .Kind ).To (Equal ("FirstMate" ))
349
+
350
+ crd = & v1beta1.CustomResourceDefinition {}
351
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "drivers.crew.example.com" }, crd )
352
+ Expect (err ).NotTo (HaveOccurred ())
353
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Driver" ))
354
+
355
+ close (done )
356
+ }, 5 )
229
357
})
230
358
359
+ It ("should update CRDs if already present in the cluster" , func (done Done ) {
360
+
361
+ // Install only the CRDv1 multi-version example
362
+ crds , err = InstallCRDs (env .Config , CRDInstallOptions {
363
+ Paths : []string {filepath .Join ("." , "testdata" , "crdv1_original" )},
364
+ })
365
+ Expect (err ).NotTo (HaveOccurred ())
366
+
367
+ // Expect to find the CRDs
368
+
369
+ crd := & v1beta1.CustomResourceDefinition {}
370
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "drivers.crew.example.com" }, crd )
371
+ Expect (err ).NotTo (HaveOccurred ())
372
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Driver" ))
373
+ Expect (len (crd .Spec .Versions )).To (BeEquivalentTo (2 ))
374
+
375
+ // Store resource version for comparison later on
376
+ firstRV := crd .ResourceVersion
377
+
378
+ // Add one more version and update
379
+ crds , err = InstallCRDs (env .Config , CRDInstallOptions {
380
+ Paths : []string {filepath .Join ("." , "testdata" , "crdv1_updated" )},
381
+ })
382
+ Expect (err ).NotTo (HaveOccurred ())
383
+
384
+ // Expect to find updated CRD
385
+
386
+ crd = & v1beta1.CustomResourceDefinition {}
387
+ err = c .Get (context .TODO (), types.NamespacedName {Name : "drivers.crew.example.com" }, crd )
388
+ Expect (err ).NotTo (HaveOccurred ())
389
+ Expect (crd .Spec .Names .Kind ).To (Equal ("Driver" ))
390
+ Expect (len (crd .Spec .Versions )).To (BeEquivalentTo (3 ))
391
+ Expect (crd .ResourceVersion ).NotTo (BeEquivalentTo (firstRV ))
392
+ }, 5 )
393
+
231
394
Describe ("UninstallCRDs" , func () {
232
395
It ("should uninstall the CRDs from the cluster" , func (done Done ) {
233
396
0 commit comments