diff --git a/internal/graph/parser/parser.go b/internal/graph/parser/parser.go index 5c61facc..0420c5e1 100644 --- a/internal/graph/parser/parser.go +++ b/internal/graph/parser/parser.go @@ -22,6 +22,10 @@ import ( "github.com/awslabs/kro/internal/graph/variable" ) +const ( + xKubernetesPreserveUnknownFields = "x-kubernetes-preserve-unknown-fields" +) + // ParseResource extracts CEL expressions from a resource based on // the schema. The resource is expected to be a map[string]interface{}. // @@ -88,6 +92,15 @@ func parseObject(field map[string]interface{}, schema *spec.Schema, path, expect return nil, fmt.Errorf("expected object type or AdditionalProperties allowed for path %s, got %v", path, field) } + // Look for vendor schema extensions first + if len(schema.VendorExtensible.Extensions) > 0 { + // If the schema has the x-kubernetes-preserve-unknown-fields extension, we should not + // parse the object and return an empty list of expressions. + if enabled, ok := schema.VendorExtensible.Extensions[xKubernetesPreserveUnknownFields]; ok && enabled.(bool) { + return nil, nil + } + } + var expressionsFields []variable.FieldDescriptor for fieldName, value := range field { fieldSchema, err := getFieldSchema(schema, fieldName) diff --git a/internal/graph/parser/parser_test.go b/internal/graph/parser/parser_test.go index 2b490dac..b459ea49 100644 --- a/internal/graph/parser/parser_test.go +++ b/internal/graph/parser/parser_test.go @@ -618,6 +618,21 @@ func TestParserEdgeCases(t *testing.T) { }, expectedError: "", }, + { + name: "schema with x-kubernetes-preserve-unknown-fields", + schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + }, + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-preserve-unknown-fields": true, + }, + }, + }, + resource: map[string]interface{}{"name": "John", "age": 30}, + expectedError: "", + }, } for _, tc := range testCases {