Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apiextensions: allow Description at root with status subresource #64766

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand All @@ -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" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should start to have a slice when we add the next one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down