mirror of https://github.com/k3s-io/k3s
Set GVK when decoding protobuf
parent
0c0caefd86
commit
8f26874577
|
@ -40,7 +40,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUniversalDeserializer(t *testing.T) {
|
func TestUniversalDeserializer(t *testing.T) {
|
||||||
expected := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test"}}
|
expected := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test"}, TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Pod"}}
|
||||||
d := legacyscheme.Codecs.UniversalDeserializer()
|
d := legacyscheme.Codecs.UniversalDeserializer()
|
||||||
for _, mediaType := range []string{"application/json", "application/yaml", "application/vnd.kubernetes.protobuf"} {
|
for _, mediaType := range []string{"application/json", "application/yaml", "application/vnd.kubernetes.protobuf"} {
|
||||||
info, ok := runtime.SerializerInfoForMediaType(legacyscheme.Codecs.SupportedMediaTypes(), mediaType)
|
info, ok := runtime.SerializerInfoForMediaType(legacyscheme.Codecs.SupportedMediaTypes(), mediaType)
|
||||||
|
|
|
@ -141,12 +141,7 @@ func RoundTripExternalTypes(t *testing.T, scheme *runtime.Scheme, codecFactory r
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t.Run(gvk.Group+"."+gvk.Version+"."+gvk.Kind, func(t *testing.T) {
|
t.Run(gvk.Group+"."+gvk.Version+"."+gvk.Kind, func(t *testing.T) {
|
||||||
// FIXME: this is explicitly testing w/o protobuf which was failing if enabled
|
roundTripSpecificKind(t, gvk, scheme, codecFactory, fuzzer, nonRoundTrippableTypes, false)
|
||||||
// the reason for that is that protobuf is not setting Kind and APIVersion fields
|
|
||||||
// during obj2 decode, the same then applies to DecodeInto obj3. My guess is we
|
|
||||||
// should be setting these two fields accordingly when protobuf is passed as codec
|
|
||||||
// to roundTrip method.
|
|
||||||
roundTripSpecificKind(t, gvk, scheme, codecFactory, fuzzer, nonRoundTrippableTypes, true)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -405,6 +405,9 @@ func unmarshalToObject(typer runtime.ObjectTyper, creater runtime.ObjectCreater,
|
||||||
if err := proto.Unmarshal(data, pb); err != nil {
|
if err := proto.Unmarshal(data, pb); err != nil {
|
||||||
return nil, actual, err
|
return nil, actual, err
|
||||||
}
|
}
|
||||||
|
if actual != nil {
|
||||||
|
obj.GetObjectKind().SetGroupVersionKind(*actual)
|
||||||
|
}
|
||||||
return obj, actual, nil
|
return obj, actual, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -320,13 +320,15 @@ func TestDecodeObjects(t *testing.T) {
|
||||||
|
|
||||||
wire1 = append([]byte{0x6b, 0x38, 0x73, 0x00}, wire1...)
|
wire1 = append([]byte{0x6b, 0x38, 0x73, 0x00}, wire1...)
|
||||||
|
|
||||||
|
obj1WithKind := obj1.DeepCopyObject()
|
||||||
|
obj1WithKind.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Carp"})
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
obj runtime.Object
|
obj runtime.Object
|
||||||
data []byte
|
data []byte
|
||||||
errFn func(error) bool
|
errFn func(error) bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
obj: obj1,
|
obj: obj1WithKind,
|
||||||
data: wire1,
|
data: wire1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue