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
This commit is contained in:
Haowei Cai 2019-05-22 12:16:08 -07:00
parent 1cfed1cca6
commit 629bdf5e84

View File

@ -341,13 +341,17 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
return nil, fmt.Errorf("require at least one version for CRD") return nil, fmt.Errorf("require at least one version for CRD")
} }
if schema == nil { expect := schema
schema = []byte(`type: object`)
}
props := &v1beta1.JSONSchemaProps{} props := &v1beta1.JSONSchemaProps{}
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 { if err := yaml.Unmarshal(schema, props); err != nil {
return nil, err return nil, err
} }
}
crd, err := crd.CreateMultiVersionTestCRD(f, group, func(crd *v1beta1.CustomResourceDefinition) { crd, err := crd.CreateMultiVersionTestCRD(f, group, func(crd *v1beta1.CustomResourceDefinition) {
var apiVersions []v1beta1.CustomResourceDefinitionVersion var apiVersions []v1beta1.CustomResourceDefinitionVersion
@ -360,16 +364,19 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
} }
crd.Spec.Versions = apiVersions crd.Spec.Versions = apiVersions
// set up validation when input schema isn't nil
if schema != nil {
crd.Spec.Validation = &v1beta1.CustomResourceValidation{ crd.Spec.Validation = &v1beta1.CustomResourceValidation{
OpenAPIV3Schema: props, OpenAPIV3Schema: props,
} }
}
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create CRD: %v", err) return nil, fmt.Errorf("failed to create CRD: %v", err)
} }
for _, v := range crd.Crd.Spec.Versions { 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) return nil, fmt.Errorf("%v", err)
} }
} }