From d9ce524d635ee9ab6eac37ca91a0216d5d9619b9 Mon Sep 17 00:00:00 2001 From: Kris Date: Thu, 4 Aug 2016 10:26:58 -0700 Subject: [PATCH] Expose dynamic client's content config --- pkg/client/typed/dynamic/client.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pkg/client/typed/dynamic/client.go b/pkg/client/typed/dynamic/client.go index 72c460b255..8b065e3a1f 100644 --- a/pkg/client/typed/dynamic/client.go +++ b/pkg/client/typed/dynamic/client.go @@ -55,9 +55,12 @@ func NewClient(conf *restclient.Config) (*Client, error) { confCopy := *conf conf = &confCopy - // TODO: it's questionable that this should be using anything other than unstructured schema and JSON - conf.ContentType = runtime.ContentTypeJSON - conf.AcceptContentTypes = runtime.ContentTypeJSON + contentConfig := ContentConfig() + contentConfig.GroupVersion = conf.GroupVersion + if conf.NegotiatedSerializer != nil { + contentConfig.NegotiatedSerializer = conf.NegotiatedSerializer + } + conf.ContentConfig = contentConfig if conf.APIPath == "" { conf.APIPath = "/api" @@ -66,10 +69,6 @@ func NewClient(conf *restclient.Config) (*Client, error) { if len(conf.UserAgent) == 0 { conf.UserAgent = restclient.DefaultKubernetesUserAgent() } - if conf.NegotiatedSerializer == nil { - streamingInfo, _ := api.Codecs.StreamingSerializerForMediaType("application/json;stream=watch", nil) - conf.NegotiatedSerializer = serializer.NegotiatedSerializerWrapper(runtime.SerializerInfo{Serializer: dynamicCodec{}}, streamingInfo) - } cl, err := restclient.RESTClientFor(conf) if err != nil { @@ -255,6 +254,18 @@ func (dynamicCodec) Encode(obj runtime.Object, w io.Writer) error { return runtime.UnstructuredJSONScheme.Encode(obj, w) } +// ContentConfig returns a restclient.ContentConfig for dynamic types. +func ContentConfig() restclient.ContentConfig { + // TODO: it's questionable that this should be using anything other than unstructured schema and JSON + codec := dynamicCodec{} + streamingInfo, _ := api.Codecs.StreamingSerializerForMediaType("application/json;stream=watch", nil) + return restclient.ContentConfig{ + AcceptContentTypes: runtime.ContentTypeJSON, + ContentType: runtime.ContentTypeJSON, + NegotiatedSerializer: serializer.NegotiatedSerializerWrapper(runtime.SerializerInfo{Serializer: codec}, streamingInfo), + } +} + // paramaterCodec is a codec converts an API object to query // parameters without trying to convert to the target version. type parameterCodec struct{}