Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions internal/resolvers/crds/schema/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,40 @@ func buildValidationFromSchemaData(data map[string]any) (*apiextensions.CustomRe
}, nil
}

// enforceStrictObjects set additionalProperties=false on all nodes (type: object)
func enforceStrictObjects(node map[string]any) {
if nodeType, ok := node["type"].(string); ok && nodeType == "object" {
// If preserve-unknown-fields exists, do not force additionalProperties
preserve, ok := node["x-kubernetes-preserve-unknown-fields"].(bool)
if !(ok && preserve) {
if _, exists := node["additionalProperties"]; !exists {
node["additionalProperties"] = false
}
}
}

// Recursion for properties
if props, ok := node["properties"].(map[string]any); ok {
for _, v := range props {
if child, ok := v.(map[string]any); ok {
enforceStrictObjects(child)
}
}
}

// Recursion for items (array)
if items, ok := node["items"].(map[string]any); ok {
enforceStrictObjects(items)
} else if itemsSlice, ok := node["items"].([]any); ok {
for _, it := range itemsSlice {
if child, ok := it.(map[string]any); ok {
enforceStrictObjects(child)
}
}
}
}

/*
// enforceStrictObjects set additionalProperties=false on all nodes (type: object)
func enforceStrictObjects(node map[string]any) {
if nodeType, ok := node["type"].(string); ok && nodeType == "object" {
Expand Down Expand Up @@ -65,6 +99,7 @@ func enforceStrictObjects(node map[string]any) {
}
}
}
*/

func validateCustomResource(crv *apiextensions.CustomResourceValidation, doc map[string]any) error {
validator, _, err := validation.NewSchemaValidator(crv.OpenAPIV3Schema)
Expand Down
74 changes: 0 additions & 74 deletions testdata/sselogs/index.html

This file was deleted.

Loading