mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
apiextensions: simplify default value pruning test
This commit is contained in:
parent
1c061bb401
commit
e521fb8fe7
@ -784,21 +784,23 @@ func (v *specStandardValidatorV3) validate(schema *apiextensions.JSONSchemaProps
|
|||||||
// ignore errors here locally. They will show up for the root of the schema.
|
// ignore errors here locally. They will show up for the root of the schema.
|
||||||
|
|
||||||
clone := runtime.DeepCopyJSONValue(interface{}(*schema.Default))
|
clone := runtime.DeepCopyJSONValue(interface{}(*schema.Default))
|
||||||
if !v.isInsideResourceMeta || s.XEmbeddedResource {
|
if !v.isInsideResourceMeta {
|
||||||
pruning.Prune(clone, s, s.XEmbeddedResource)
|
|
||||||
// If we are under metadata, there are implicitly specified fields like kind, apiVersion, metadata, labels.
|
// If we are under metadata, there are implicitly specified fields like kind, apiVersion, metadata, labels.
|
||||||
// We cannot prune as they are pruned as well. This allows more defaults than we would like to.
|
// We cannot prune as they are pruned as well. This allows more defaults than we would like to.
|
||||||
// TODO: be precise about pruning under metadata
|
// TODO: be precise about pruning under metadata
|
||||||
}
|
pruning.Prune(clone, s, s.XEmbeddedResource)
|
||||||
// TODO: coerce correctly if we are not at the object root, but somewhere below.
|
|
||||||
if err := schemaobjectmeta.Coerce(fldPath, clone, s, s.XEmbeddedResource, false); err != nil {
|
// TODO: coerce correctly if we are not at the object root, but somewhere below.
|
||||||
allErrs = append(allErrs, err)
|
if err := schemaobjectmeta.Coerce(fldPath, clone, s, s.XEmbeddedResource, false); err != nil {
|
||||||
}
|
allErrs = append(allErrs, err)
|
||||||
if !reflect.DeepEqual(clone, interface{}(*schema.Default)) {
|
}
|
||||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("default"), schema.Default, "must not have unknown fields"))
|
|
||||||
} else if s.XEmbeddedResource {
|
if !reflect.DeepEqual(clone, interface{}(*schema.Default)) {
|
||||||
// validate an embedded resource
|
allErrs = append(allErrs, field.Invalid(fldPath.Child("default"), schema.Default, "must not have unknown fields"))
|
||||||
schemaobjectmeta.Validate(fldPath, interface{}(*schema.Default), nil, true)
|
} else if s.XEmbeddedResource {
|
||||||
|
// validate an embedded resource
|
||||||
|
schemaobjectmeta.Validate(fldPath, interface{}(*schema.Default), nil, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate the default value with user the provided schema.
|
// validate the default value with user the provided schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user