mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 14:45:28 +00:00
Replace automatic YAML decoding with opt-in YAML decoding
Base codecs no longer automically handle YAML. Instead, clients must convert to JSON first via yaml.ToJSON and runtime.YAMLDecoder.
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/yaml"
|
||||
)
|
||||
|
||||
// Mapper is a convenience struct for holding references to the three interfaces
|
||||
@@ -36,6 +37,11 @@ type Mapper struct {
|
||||
// if any of the decoding or client lookup steps fail. Name and namespace will be
|
||||
// set into Info if the mapping's MetadataAccessor can retrieve them.
|
||||
func (m *Mapper) InfoForData(data []byte, source string) (*Info, error) {
|
||||
json, err := yaml.ToJSON(data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse %q: %v", err)
|
||||
}
|
||||
data = json
|
||||
version, kind, err := m.DataVersionAndKind(data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get type info from %q: %v", source, err)
|
||||
|
@@ -196,7 +196,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
|
||||
}
|
||||
// Use real decode function to undo the versioning process.
|
||||
poutput = testStruct{}
|
||||
err = testapi.Codec().DecodeInto(buf.Bytes(), &poutput)
|
||||
err = runtime.YAMLDecoder(testapi.Codec()).DecodeInto(buf.Bytes(), &poutput)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
|
||||
}
|
||||
// Use real decode function to undo the versioning process.
|
||||
objOut = api.Pod{}
|
||||
err = testapi.Codec().DecodeInto(buf.Bytes(), &objOut)
|
||||
err = runtime.YAMLDecoder(testapi.Codec()).DecodeInto(buf.Bytes(), &objOut)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user