apiextensions: allow Description in the root schema for subresources

This commit is contained in:
Nikhita Raghunath 2018-06-05 19:05:07 +05:30
parent b81a192a84
commit 0528e96928
3 changed files with 8 additions and 6 deletions

View File

@ -291,7 +291,7 @@ func ValidateCustomResourceDefinitionValidation(customResourceValidation *apiext
}
if schema := customResourceValidation.OpenAPIV3Schema; schema != nil {
// if subresources are enabled, only "properties" and "required" is allowed inside the root schema
// if subresources are enabled, only "properties", "required" and "description" are allowed inside the root schema
if utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) && statusSubresourceEnabled {
v := reflect.ValueOf(schema).Elem()
for i := 0; i < v.NumField(); i++ {
@ -300,8 +300,8 @@ func ValidateCustomResourceDefinitionValidation(customResourceValidation *apiext
continue
}
if name := v.Type().Field(i).Name; name != "Properties" && name != "Required" {
allErrs = append(allErrs, field.Invalid(fldPath.Child("openAPIV3Schema"), *schema, fmt.Sprintf(`must only have "properties" or "required" at the root if the status subresource is enabled`)))
if name := v.Type().Field(i).Name; name != "Properties" && name != "Required" && name != "Description" {
allErrs = append(allErrs, field.Invalid(fldPath.Child("openAPIV3Schema"), *schema, fmt.Sprintf(`must only have "properties", "required" or "description" at the root if the status subresource is enabled`)))
break
}
}

View File

@ -849,14 +849,15 @@ func TestValidateCustomResourceDefinitionValidation(t *testing.T) {
wantError: true,
},
{
name: "properties and required with status",
name: "properties, required and description with status",
input: apiextensions.CustomResourceValidation{
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
Properties: map[string]apiextensions.JSONSchemaProps{
"spec": {},
"status": {},
},
Required: []string{"spec", "status"},
Required: []string{"spec", "status"},
Description: "This is a description",
},
},
statusEnabled: true,

View File

@ -359,7 +359,8 @@ func TestValidationSchema(t *testing.T) {
},
},
},
Required: []string{"spec"},
Required: []string{"spec"},
Description: "This is a description at the root of the schema",
}
noxuDefinition, err = testserver.CreateNewCustomResourceDefinition(noxuDefinition, apiExtensionClient, dynamicClient)
if err != nil {