Expose dynamic client's content config

pull/6/head
Kris 2016-08-04 10:26:58 -07:00
parent 79ed7064ca
commit d9ce524d63
1 changed files with 18 additions and 7 deletions

View File

@ -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{}