@@ -341,12 +341,16 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
341
341
return nil , fmt .Errorf ("require at least one version for CRD" )
342
342
}
343
343
344
- if schema == nil {
345
- schema = []byte (`type: object` )
346
- }
344
+ expect := schema
347
345
props := & v1beta1.JSONSchemaProps {}
348
- if err := yaml .Unmarshal (schema , props ); err != nil {
349
- 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
+ }
350
354
}
351
355
352
356
crd , err := crd .CreateMultiVersionTestCRD (f , group , func (crd * v1beta1.CustomResourceDefinition ) {
@@ -360,16 +364,19 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
360
364
}
361
365
crd .Spec .Versions = apiVersions
362
366
363
- crd .Spec .Validation = & v1beta1.CustomResourceValidation {
364
- 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
+ }
365
372
}
366
373
})
367
374
if err != nil {
368
375
return nil , fmt .Errorf ("failed to create CRD: %v" , err )
369
376
}
370
377
371
378
for _ , v := range crd .Crd .Spec .Versions {
372
- 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 {
373
380
return nil , fmt .Errorf ("%v" , err )
374
381
}
375
382
}
0 commit comments