mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #111483 from jpbetz/fix-missing-root-object-type
Skip schemas that don't have CEL rules in NewValidator
This commit is contained in:
commit
f3d90aef8d
@ -62,11 +62,13 @@ type Validator struct {
|
|||||||
// NewValidator returns compiles all the CEL programs defined in x-kubernetes-validations extensions
|
// NewValidator returns compiles all the CEL programs defined in x-kubernetes-validations extensions
|
||||||
// of the Structural schema and returns a custom resource validator that contains nested
|
// of the Structural schema and returns a custom resource validator that contains nested
|
||||||
// validators for all items, properties and additionalProperties that transitively contain validator rules.
|
// validators for all items, properties and additionalProperties that transitively contain validator rules.
|
||||||
// Returns nil only if there no validator rules in the Structural schema. May return a validator containing
|
// Returns nil if there are no validator rules in the Structural schema. May return a validator containing only errors.
|
||||||
// only errors.
|
|
||||||
// Adding perCallLimit as input arg for testing purpose only. Callers should always use const PerCallLimit as input
|
// Adding perCallLimit as input arg for testing purpose only. Callers should always use const PerCallLimit as input
|
||||||
func NewValidator(s *schema.Structural, isResourceRoot bool, perCallLimit uint64) *Validator {
|
func NewValidator(s *schema.Structural, isResourceRoot bool, perCallLimit uint64) *Validator {
|
||||||
return validator(s, true, model.SchemaDeclType(s, isResourceRoot), perCallLimit)
|
if !hasXValidations(s) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return validator(s, isResourceRoot, model.SchemaDeclType(s, isResourceRoot), perCallLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validator creates a Validator for all x-kubernetes-validations at the level of the provided schema and lower and
|
// validator creates a Validator for all x-kubernetes-validations at the level of the provided schema and lower and
|
||||||
@ -378,3 +380,26 @@ func MapIsCorrelatable(mapType *string) bool {
|
|||||||
// if a third map type is introduced, assume it's not correlatable. granular is the default if unspecified.
|
// if a third map type is introduced, assume it's not correlatable. granular is the default if unspecified.
|
||||||
return mapType == nil || *mapType == "granular" || *mapType == "atomic"
|
return mapType == nil || *mapType == "granular" || *mapType == "atomic"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasXValidations(s *schema.Structural) bool {
|
||||||
|
if s == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if len(s.XValidations) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if hasXValidations(s.Items) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if s.AdditionalProperties != nil && hasXValidations(s.AdditionalProperties.Structural) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if s.Properties != nil {
|
||||||
|
for _, prop := range s.Properties {
|
||||||
|
if hasXValidations(&prop) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user