diff --git a/test/e2e/apimachinery/crd_publish_openapi.go b/test/e2e/apimachinery/crd_publish_openapi.go index 99967a3cf33..afa4c053bcd 100644 --- a/test/e2e/apimachinery/crd_publish_openapi.go +++ b/test/e2e/apimachinery/crd_publish_openapi.go @@ -341,12 +341,16 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version return nil, fmt.Errorf("require at least one version for CRD") } - if schema == nil { - schema = []byte(`type: object`) - } + expect := schema props := &v1beta1.JSONSchemaProps{} - if err := yaml.Unmarshal(schema, props); err != nil { - return nil, err + if schema == nil { + // to be backwards compatible, we expect CRD controller to treat + // CRD with nil schema specially and publish an empty schema + expect = []byte(`type: object`) + } else { + if err := yaml.Unmarshal(schema, props); err != nil { + return nil, err + } } crd, err := crd.CreateMultiVersionTestCRD(f, group, func(crd *v1beta1.CustomResourceDefinition) { @@ -360,8 +364,11 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version } crd.Spec.Versions = apiVersions - crd.Spec.Validation = &v1beta1.CustomResourceValidation{ - OpenAPIV3Schema: props, + // set up validation when input schema isn't nil + if schema != nil { + crd.Spec.Validation = &v1beta1.CustomResourceValidation{ + OpenAPIV3Schema: props, + } } }) if err != nil { @@ -369,7 +376,7 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version } for _, v := range crd.Crd.Spec.Versions { - if err := waitForDefinition(f.ClientSet, definitionName(crd, v.Name), schema); err != nil { + if err := waitForDefinition(f.ClientSet, definitionName(crd, v.Name), expect); err != nil { return nil, fmt.Errorf("%v", err) } }