Split the storage and negotiation parts of Codecs
The codec factory should support two distinct interfaces - negotiating for a serializer with a client, vs reading or writing data to a storage form (etcd, disk, etc). Make the EncodeForVersion and DecodeToVersion methods only take Encoder and Decoder, and slight refactoring elsewhere. In the storage factory, use a content type to control what serializer to pick, and use the universal deserializer. This ensures that storage can read JSON (which might be from older objects) while only writing protobuf. Add exceptions for those resources that may not be able to write to protobuf (specifically third party resources, but potentially others in the future).
This commit is contained in:
@@ -284,18 +284,14 @@ func TestObjectWatchFraming(t *testing.T) {
|
||||
converted, _ := api.Scheme.ConvertToVersion(secret, "v1")
|
||||
v1secret := converted.(*v1.Secret)
|
||||
for _, streamingMediaType := range api.Codecs.SupportedStreamingMediaTypes() {
|
||||
s, framer, mediaType, _ := api.Codecs.StreamingSerializerForMediaType(streamingMediaType, nil)
|
||||
// TODO: remove this when the runtime.SerializerInfo PR lands
|
||||
if mediaType == "application/vnd.kubernetes.protobuf;stream=watch" {
|
||||
mediaType = "application/vnd.kubernetes.protobuf"
|
||||
}
|
||||
embedded, ok := api.Codecs.SerializerForMediaType(mediaType, nil)
|
||||
if !ok {
|
||||
t.Logf("no embedded serializer for %s", mediaType)
|
||||
embedded = s
|
||||
s, _ := api.Codecs.StreamingSerializerForMediaType(streamingMediaType, nil)
|
||||
framer := s.Framer
|
||||
embedded := s.Embedded.Serializer
|
||||
if embedded == nil {
|
||||
t.Errorf("no embedded serializer for %s", streamingMediaType)
|
||||
continue
|
||||
}
|
||||
innerDecode := api.Codecs.DecoderToVersion(embedded, api.SchemeGroupVersion)
|
||||
//innerEncode := api.Codecs.EncoderForVersion(embedded, api.SchemeGroupVersion)
|
||||
|
||||
// write a single object through the framer and back out
|
||||
obj := &bytes.Buffer{}
|
||||
|
Reference in New Issue
Block a user