Skip to content
Open
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
4 changes: 4 additions & 0 deletions cmd/config/internal/commands/e2e/e2econtainerconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 --)
Expand Down
2 changes: 1 addition & 1 deletion kyaml/fn/framework/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions kyaml/fn/framework/processors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading