diff --git a/cmd/config/internal/commands/e2e/e2econtainerconfig/main.go b/cmd/config/internal/commands/e2e/e2econtainerconfig/main.go index d3e6b0e6c7..91595bd937 100644 --- a/cmd/config/internal/commands/e2e/e2econtainerconfig/main.go +++ b/cmd/config/internal/commands/e2e/e2econtainerconfig/main.go @@ -8,6 +8,7 @@ import ( "os" "strconv" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/kustomize/kyaml/fn/framework" "sigs.k8s.io/kustomize/kyaml/fn/framework/command" "sigs.k8s.io/kustomize/kyaml/kio" @@ -16,6 +17,9 @@ import ( // Config defines the ResourceList.functionConfig schema. type Config struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + // Data contains configuration data for the Example // Nest values under Data so that the function can accept a ConfigMap as its // functionConfig (`run` generates a ConfigMap for the functionConfig when run with --) diff --git a/kyaml/fn/framework/processors.go b/kyaml/fn/framework/processors.go index 1b390b2695..0904c3bd6d 100644 --- a/kyaml/fn/framework/processors.go +++ b/kyaml/fn/framework/processors.go @@ -156,7 +156,7 @@ func LoadFunctionConfig(src *yaml.RNode, api interface{}) error { // using sigs.k8s.io/yaml here lets the custom types embed core types // that only have json tags, notably types from k8s.io/apimachinery/pkg/apis/meta/v1 - if err := k8syaml.Unmarshal([]byte(src.MustString()), api); err != nil { + if err := k8syaml.UnmarshalStrict([]byte(src.MustString()), api); err != nil { if schemaValidationError != nil { // if we got a validation error, report it instead as it is likely a nicer version of the same message return schemaValidationError diff --git a/kyaml/fn/framework/processors_test.go b/kyaml/fn/framework/processors_test.go index 88eee73897..8b75c7970d 100644 --- a/kyaml/fn/framework/processors_test.go +++ b/kyaml/fn/framework/processors_test.go @@ -834,6 +834,26 @@ test: true api: &yamlTagTest{}, want: &yamlTagTest{Name: "tester", Test: true}, }, + { + name: "fails on unknown fields on types with yaml tags", + src: yaml.MustParse(` +name: tester +test: true +unknown: field +`), + api: &yamlTagTest{}, + wantErrMsgs: []string{`error unmarshaling JSON: while decoding JSON: json: unknown field "unknown"`}, + }, + { + name: "fails on unknown fields on types with json tags", + src: yaml.MustParse(` +name: tester +test: true +unknown: field +`), + api: &jsonTagTest{}, + wantErrMsgs: []string{`error unmarshaling JSON: while decoding JSON: json: unknown field "unknown"`}, + }, } for _, tt := range tests {