Refactor loops over SupportedMediaTypes() where mediaType is used to match a single SerializerInfo{}

We have an existing helper function for this:  runtime.SerializerInfoForMediaType()

This is common prep-work for encoding runtime.Objects into JSON/YAML for transmission over the wire or writing to ComponentConfigs.

Kubernetes-commit: 47e52d2981dc2a5c5950042f50688cf24dd92eda
This commit is contained in:
leigh capili 2019-04-04 19:01:01 -06:00 committed by Kubernetes Publisher
parent 95d8a92c48
commit 6c6c98c9ca

View File

@ -59,15 +59,9 @@ func (dynamicCodec) Encode(obj runtime.Object, w io.Writer) error {
// ContentConfig returns a rest.ContentConfig for dynamic types.
// Deprecated only used by test code and its wrong
func ContentConfig() rest.ContentConfig {
var jsonInfo runtime.SerializerInfo
// TODO: scheme.Codecs here should become "pkg/apis/server/scheme" which is the minimal core you need
// to talk to a kubernetes server
for _, info := range scheme.Codecs.SupportedMediaTypes() {
if info.MediaType == runtime.ContentTypeJSON {
jsonInfo = info
break
}
}
jsonInfo, _ := runtime.SerializerInfoForMediaType(scheme.Codecs.SupportedMediaTypes(), runtime.ContentTypeJSON)
jsonInfo.Serializer = dynamicCodec{}
jsonInfo.PrettySerializer = nil