Merge pull request #64766 from nikhita/allow-description-at-root

Automatic merge from submit-queue (batch tested with PRs 64276, 64094, 64719, 64766, 64750). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiextensions: allow Description at root with status subresource

Allows `Description` at the root of the schema when the status subresource is enabled.

**Release note**:
I'll update the original PR, which allowed `Required`, to de-duplicate the release notes.


```release-note
NONE
```

/assign sttts
This commit is contained in:
Kubernetes Submit Queue
2018-06-05 11:35:21 -07:00
committed by GitHub
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 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 { if utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) && statusSubresourceEnabled {
v := reflect.ValueOf(schema).Elem() v := reflect.ValueOf(schema).Elem()
for i := 0; i < v.NumField(); i++ { for i := 0; i < v.NumField(); i++ {
@@ -300,8 +300,8 @@ func ValidateCustomResourceDefinitionValidation(customResourceValidation *apiext
continue continue
} }
if name := v.Type().Field(i).Name; name != "Properties" && name != "Required" { 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" or "required" at the root if the status subresource is enabled`))) 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 break
} }
} }

View File

@@ -849,14 +849,15 @@ func TestValidateCustomResourceDefinitionValidation(t *testing.T) {
wantError: true, wantError: true,
}, },
{ {
name: "properties and required with status", name: "properties, required and description with status",
input: apiextensions.CustomResourceValidation{ input: apiextensions.CustomResourceValidation{
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{ OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
Properties: map[string]apiextensions.JSONSchemaProps{ Properties: map[string]apiextensions.JSONSchemaProps{
"spec": {}, "spec": {},
"status": {}, "status": {},
}, },
Required: []string{"spec", "status"}, Required: []string{"spec", "status"},
Description: "This is a description",
}, },
}, },
statusEnabled: true, 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) noxuDefinition, err = testserver.CreateNewCustomResourceDefinition(noxuDefinition, apiExtensionClient, dynamicClient)
if err != nil { if err != nil {