Skip to content

Commit

Permalink
Set GVK when decoding protobuf
Browse files Browse the repository at this point in the history
Kubernetes-commit: 8f2687457702a9d67fe34b9bd872ce6c2256643d
  • Loading branch information
liggitt authored and k8s-publishing-bot committed May 29, 2019
1 parent 985f9b9 commit 3610fc3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 1 addition & 6 deletions pkg/api/apitesting/roundtrip/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@ func RoundTripExternalTypes(t *testing.T, scheme *runtime.Scheme, codecFactory r
continue
}
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
// 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)
roundTripSpecificKind(t, gvk, scheme, codecFactory, fuzzer, nonRoundTrippableTypes, false)
})
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/runtime/serializer/protobuf/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ func unmarshalToObject(typer runtime.ObjectTyper, creater runtime.ObjectCreater,
if err := proto.Unmarshal(data, pb); err != nil {
return nil, actual, err
}
if actual != nil {
obj.GetObjectKind().SetGroupVersionKind(*actual)
}
return obj, actual, nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/test/runtime_serializer_protobuf_protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,15 @@ func TestDecodeObjects(t *testing.T) {

wire1 = append([]byte{0x6b, 0x38, 0x73, 0x00}, wire1...)

obj1WithKind := obj1.DeepCopyObject()
obj1WithKind.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Carp"})
testCases := []struct {
obj runtime.Object
data []byte
errFn func(error) bool
}{
{
obj: obj1,
obj: obj1WithKind,
data: wire1,
},
}
Expand Down

0 comments on commit 3610fc3

Please sign in to comment.