@@ -32,6 +32,7 @@ import (
32
32
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
33
33
"k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
34
34
apiequality "k8s.io/apimachinery/pkg/api/equality"
35
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35
36
"k8s.io/apimachinery/pkg/types"
36
37
utilversion "k8s.io/apimachinery/pkg/util/version"
37
38
"k8s.io/apimachinery/pkg/util/wait"
@@ -309,6 +310,10 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
309
310
}
310
311
311
312
ginkgo .By ("mark a version not serverd" )
313
+ crd .Crd , err = crd .APIExtensionClient .ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (crd .Crd .Name , metav1.GetOptions {})
314
+ if err != nil {
315
+ framework .Failf ("%v" , err )
316
+ }
312
317
crd .Crd .Spec .Versions [1 ].Served = false
313
318
crd .Crd , err = crd .APIExtensionClient .ApiextensionsV1beta1 ().CustomResourceDefinitions ().Update (crd .Crd )
314
319
if err != nil {
@@ -336,12 +341,16 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
336
341
return nil , fmt .Errorf ("require at least one version for CRD" )
337
342
}
338
343
339
- if schema == nil {
340
- schema = []byte (`type: object` )
341
- }
344
+ expect := schema
342
345
props := & v1beta1.JSONSchemaProps {}
343
- if err := yaml .Unmarshal (schema , props ); err != nil {
344
- return nil , err
346
+ if schema == nil {
347
+ // to be backwards compatible, we expect CRD controller to treat
348
+ // CRD with nil schema specially and publish an empty schema
349
+ expect = []byte (`type: object` )
350
+ } else {
351
+ if err := yaml .Unmarshal (schema , props ); err != nil {
352
+ return nil , err
353
+ }
345
354
}
346
355
347
356
crd , err := crd .CreateMultiVersionTestCRD (f , group , func (crd * v1beta1.CustomResourceDefinition ) {
@@ -355,16 +364,19 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
355
364
}
356
365
crd .Spec .Versions = apiVersions
357
366
358
- crd .Spec .Validation = & v1beta1.CustomResourceValidation {
359
- OpenAPIV3Schema : props ,
367
+ // set up validation when input schema isn't nil
368
+ if schema != nil {
369
+ crd .Spec .Validation = & v1beta1.CustomResourceValidation {
370
+ OpenAPIV3Schema : props ,
371
+ }
360
372
}
361
373
})
362
374
if err != nil {
363
375
return nil , fmt .Errorf ("failed to create CRD: %v" , err )
364
376
}
365
377
366
378
for _ , v := range crd .Crd .Spec .Versions {
367
- if err := waitForDefinition (f .ClientSet , definitionName (crd , v .Name ), schema ); err != nil {
379
+ if err := waitForDefinition (f .ClientSet , definitionName (crd , v .Name ), expect ); err != nil {
368
380
return nil , fmt .Errorf ("%v" , err )
369
381
}
370
382
}
@@ -579,9 +591,11 @@ properties:
579
591
properties:
580
592
dummy:
581
593
description: Dummy property.
594
+ type: object
582
595
status:
583
596
description: Status of Waldo
584
597
type: object
585
598
properties:
586
599
bars:
587
- description: List of Bars and their statuses.` )
600
+ description: List of Bars and their statuses.
601
+ type: array` )
0 commit comments