Revert strict decoding of Kustomization due to regression in anchor handling (#5073)

* Revert strict decoding of Kustomization due to regression in anchor handling

* Empty commit
This commit is contained in:
Katrina Verey
2023-03-13 16:46:47 -04:00
committed by GitHub
parent bf6e6ad33b
commit dd520f8889
5 changed files with 39 additions and 12 deletions

View File

@@ -4,6 +4,8 @@
package types
import (
"bytes"
"encoding/json"
"fmt"
"sigs.k8s.io/kustomize/kyaml/errors"
@@ -313,8 +315,20 @@ func (k *Kustomization) EnforceFields() []string {
// Unmarshal replace k with the content in YAML input y
func (k *Kustomization) Unmarshal(y []byte) error {
if err := yaml.UnmarshalStrict(y, &k); err != nil {
// TODO: switch to strict decoding to catch duplicate keys.
// We can't do so until there is a yaml decoder that supports anchors AND case-insensitive keys.
// See https://github.com/kubernetes-sigs/kustomize/issues/5061
j, err := yaml.YAMLToJSON(y)
if err != nil {
return errors.WrapPrefixf(err, "invalid Kustomization")
}
dec := json.NewDecoder(bytes.NewReader(j))
dec.DisallowUnknownFields()
var nk Kustomization
err = dec.Decode(&nk)
if err != nil {
return errors.WrapPrefixf(err, "invalid Kustomization")
}
*k = nk
return nil
}

View File

@@ -278,7 +278,7 @@ unknown: foo`)
if err == nil {
t.Fatalf("expect an error")
}
expect := "invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field \"unknown\""
expect := "invalid Kustomization: json: unknown field \"unknown\""
if err.Error() != expect {
t.Fatalf("expect %v but got: %v", expect, err.Error())
}