mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
Merge 5dcb6cfa3b into e60892483e
This commit is contained in:
commit
104d436f46
1 changed files with 71 additions and 1 deletions
|
|
@ -384,7 +384,20 @@ func downloadSchema(registries []registry.Registry, l jsonschema.SchemeURLLoader
|
|||
if err != nil {
|
||||
continue
|
||||
}
|
||||
return schema, nil
|
||||
if schema != nil {
|
||||
// First check if the schema has explicit kind constraints
|
||||
if hasKindConstraints(schema) {
|
||||
if isSchemaForKind(schema, kind) {
|
||||
return schema, nil
|
||||
}
|
||||
} else {
|
||||
// If no kind constraints, check if the path matches the kind
|
||||
if pathMatchesKind(path, kind) {
|
||||
return schema, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if _, notfound := err.(*loader.NotFoundError); notfound {
|
||||
|
|
@ -399,3 +412,60 @@ func downloadSchema(registries []registry.Registry, l jsonschema.SchemeURLLoader
|
|||
|
||||
return nil, nil // No schema found - we don't consider it an error, resource will be skipped
|
||||
}
|
||||
|
||||
func hasKindConstraints(schema *jsonschema.Schema) bool {
|
||||
if schema == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if schema.Properties != nil {
|
||||
if kindProp, ok := schema.Properties["kind"]; ok {
|
||||
// Check if the kind property has enum or const constraints
|
||||
if kindProp.Enum != nil || kindProp.Const != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func pathMatchesKind(path string, expectedKind string) bool {
|
||||
// Convert expected kind to lowercase for comparison
|
||||
expectedLower := strings.ToLower(expectedKind)
|
||||
|
||||
// Check if the path contains the expected kind name
|
||||
pathLower := strings.ToLower(path)
|
||||
|
||||
// For direct file paths (like secretstore_v1.json), check if the filename contains the kind
|
||||
if strings.Contains(pathLower, expectedLower) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func isSchemaForKind(schema *jsonschema.Schema, expectedKind string) bool {
|
||||
if schema == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if schema.Properties != nil {
|
||||
if kindProp, ok := schema.Properties["kind"]; ok {
|
||||
if kindProp.Enum != nil {
|
||||
if enumValues := kindProp.Enum.Values; len(enumValues) > 0 {
|
||||
if enumKind, ok := enumValues[0].(string); ok {
|
||||
return enumKind == expectedKind
|
||||
}
|
||||
}
|
||||
}
|
||||
if kindProp.Const != nil {
|
||||
if constVal, ok := (*kindProp.Const).(string); ok {
|
||||
return constVal == expectedKind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue