Skip to content

Commit 629bdf5

Browse files
committed
restore test behavior for CRD without validation cases
the test doesn't set empty validation but expects CRD controller to treat nil schema specially and publish an empty schema
1 parent 1cfed1c commit 629bdf5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

test/e2e/apimachinery/crd_publish_openapi.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,16 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
341341
return nil, fmt.Errorf("require at least one version for CRD")
342342
}
343343

344-
if schema == nil {
345-
schema = []byte(`type: object`)
346-
}
344+
expect := schema
347345
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+
}
350354
}
351355

352356
crd, err := crd.CreateMultiVersionTestCRD(f, group, func(crd *v1beta1.CustomResourceDefinition) {
@@ -360,16 +364,19 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
360364
}
361365
crd.Spec.Versions = apiVersions
362366

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+
}
365372
}
366373
})
367374
if err != nil {
368375
return nil, fmt.Errorf("failed to create CRD: %v", err)
369376
}
370377

371378
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 {
373380
return nil, fmt.Errorf("%v", err)
374381
}
375382
}

0 commit comments

Comments
 (0)