@@ -351,6 +351,11 @@ func CreateNewCustomResourceDefinition(crd *apiextensionsv1beta1.CustomResourceD
351
351
return nil , err
352
352
}
353
353
354
+ v1CRD , err := apiExtensionsClient .ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .TODO (), crd .Name , metav1.GetOptions {})
355
+ if err != nil {
356
+ return nil , err
357
+ }
358
+
354
359
// This is only for a test. We need the watch cache to have a resource version that works for the test.
355
360
// When new REST storage is created, the storage cacher for the CR starts asynchronously.
356
361
// REST API operations return like list use the RV of etcd, but the storage cacher's reflector's list
@@ -362,7 +367,7 @@ func CreateNewCustomResourceDefinition(crd *apiextensionsv1beta1.CustomResourceD
362
367
// This way all the tests that are checking for watches don't have to worry about RV too old problems because crazy things *could* happen
363
368
// before like the created RV could be too old to watch.
364
369
err = wait .PollImmediate (500 * time .Millisecond , 30 * time .Second , func () (bool , error ) {
365
- return isWatchCachePrimed (crd , dynamicClientSet )
370
+ return isWatchCachePrimed (v1CRD , dynamicClientSet )
366
371
})
367
372
if err != nil {
368
373
return nil , err
@@ -379,15 +384,11 @@ func CreateNewV1CustomResourceDefinitionWatchUnsafe(v1CRD *apiextensionsv1.Custo
379
384
if err != nil {
380
385
return nil , err
381
386
}
382
- crd , err := apiExtensionsClient .ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (context .TODO (), v1CRD .Name , metav1.GetOptions {})
383
- if err != nil {
384
- return nil , err
385
- }
386
387
387
388
// wait until all resources appears in discovery
388
- for _ , version := range servedVersions ( crd ) {
389
+ for _ , version := range servedV1Versions ( v1CRD ) {
389
390
err := wait .PollImmediate (500 * time .Millisecond , 30 * time .Second , func () (bool , error ) {
390
- return existsInDiscovery ( crd , apiExtensionsClient , version )
391
+ return existsInDiscoveryV1 ( v1CRD , apiExtensionsClient , version )
391
392
})
392
393
if err != nil {
393
394
return nil , err
@@ -403,10 +404,6 @@ func CreateNewV1CustomResourceDefinition(v1CRD *apiextensionsv1.CustomResourceDe
403
404
if err != nil {
404
405
return nil , err
405
406
}
406
- crd , err := apiExtensionsClient .ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (context .TODO (), v1CRD .Name , metav1.GetOptions {})
407
- if err != nil {
408
- return nil , err
409
- }
410
407
411
408
// This is only for a test. We need the watch cache to have a resource version that works for the test.
412
409
// When new REST storage is created, the storage cacher for the CR starts asynchronously.
@@ -419,30 +416,30 @@ func CreateNewV1CustomResourceDefinition(v1CRD *apiextensionsv1.CustomResourceDe
419
416
// This way all the tests that are checking for watches don't have to worry about RV too old problems because crazy things *could* happen
420
417
// before like the created RV could be too old to watch.
421
418
err = wait .PollImmediate (500 * time .Millisecond , 30 * time .Second , func () (bool , error ) {
422
- return isWatchCachePrimed (crd , dynamicClientSet )
419
+ return isWatchCachePrimed (v1CRD , dynamicClientSet )
423
420
})
424
421
if err != nil {
425
422
return nil , err
426
423
}
427
424
return v1CRD , nil
428
425
}
429
426
430
- func resourceClientForVersion (crd * apiextensionsv1beta1 .CustomResourceDefinition , dynamicClientSet dynamic.Interface , namespace , version string ) dynamic.ResourceInterface {
427
+ func resourceClientForVersion (crd * apiextensionsv1 .CustomResourceDefinition , dynamicClientSet dynamic.Interface , namespace , version string ) dynamic.ResourceInterface {
431
428
gvr := schema.GroupVersionResource {Group : crd .Spec .Group , Version : version , Resource : crd .Spec .Names .Plural }
432
- if crd .Spec .Scope != apiextensionsv1beta1 .ClusterScoped {
429
+ if crd .Spec .Scope != apiextensionsv1 .ClusterScoped {
433
430
return dynamicClientSet .Resource (gvr ).Namespace (namespace )
434
431
}
435
432
return dynamicClientSet .Resource (gvr )
436
433
}
437
434
438
435
// isWatchCachePrimed returns true if the watch is primed for an specified version of CRD watch
439
- func isWatchCachePrimed (crd * apiextensionsv1beta1 .CustomResourceDefinition , dynamicClientSet dynamic.Interface ) (bool , error ) {
436
+ func isWatchCachePrimed (crd * apiextensionsv1 .CustomResourceDefinition , dynamicClientSet dynamic.Interface ) (bool , error ) {
440
437
ns := ""
441
- if crd .Spec .Scope != apiextensionsv1beta1 .ClusterScoped {
438
+ if crd .Spec .Scope != apiextensionsv1 .ClusterScoped {
442
439
ns = "aval"
443
440
}
444
441
445
- versions := servedVersions (crd )
442
+ versions := servedV1Versions (crd )
446
443
if len (versions ) == 0 {
447
444
return true , nil
448
445
}
@@ -539,29 +536,6 @@ func DeleteV1CustomResourceDefinition(crd *apiextensionsv1.CustomResourceDefinit
539
536
return nil
540
537
}
541
538
542
- // DeleteCustomResourceDefinitions deletes all CRD matching the provided deleteListOpts and waits until all the CRDs disappear from discovery.
543
- func DeleteCustomResourceDefinitions (deleteListOpts metav1.ListOptions , apiExtensionsClient clientset.Interface ) error {
544
- list , err := apiExtensionsClient .ApiextensionsV1beta1 ().CustomResourceDefinitions ().List (context .TODO (), deleteListOpts )
545
- if err != nil {
546
- return err
547
- }
548
- if err = apiExtensionsClient .ApiextensionsV1beta1 ().CustomResourceDefinitions ().DeleteCollection (context .TODO (), nil , deleteListOpts ); err != nil {
549
- return err
550
- }
551
- for _ , crd := range list .Items {
552
- for _ , version := range servedVersions (& crd ) {
553
- err := wait .PollImmediate (500 * time .Millisecond , 30 * time .Second , func () (bool , error ) {
554
- exists , err := existsInDiscovery (& crd , apiExtensionsClient , version )
555
- return ! exists , err
556
- })
557
- if err != nil {
558
- return err
559
- }
560
- }
561
- }
562
- return nil
563
- }
564
-
565
539
// DeleteV1CustomResourceDefinitions deletes all CRD matching the provided deleteListOpts and waits until all the CRDs disappear from discovery.
566
540
func DeleteV1CustomResourceDefinitions (deleteListOpts metav1.ListOptions , apiExtensionsClient clientset.Interface ) error {
567
541
list , err := apiExtensionsClient .ApiextensionsV1 ().CustomResourceDefinitions ().List (context .TODO (), deleteListOpts )
0 commit comments