mirror of https://github.com/k3s-io/k3s
Expose dynamic client's content config
parent
79ed7064ca
commit
d9ce524d63
|
@ -55,9 +55,12 @@ func NewClient(conf *restclient.Config) (*Client, error) {
|
||||||
confCopy := *conf
|
confCopy := *conf
|
||||||
conf = &confCopy
|
conf = &confCopy
|
||||||
|
|
||||||
// TODO: it's questionable that this should be using anything other than unstructured schema and JSON
|
contentConfig := ContentConfig()
|
||||||
conf.ContentType = runtime.ContentTypeJSON
|
contentConfig.GroupVersion = conf.GroupVersion
|
||||||
conf.AcceptContentTypes = runtime.ContentTypeJSON
|
if conf.NegotiatedSerializer != nil {
|
||||||
|
contentConfig.NegotiatedSerializer = conf.NegotiatedSerializer
|
||||||
|
}
|
||||||
|
conf.ContentConfig = contentConfig
|
||||||
|
|
||||||
if conf.APIPath == "" {
|
if conf.APIPath == "" {
|
||||||
conf.APIPath = "/api"
|
conf.APIPath = "/api"
|
||||||
|
@ -66,10 +69,6 @@ func NewClient(conf *restclient.Config) (*Client, error) {
|
||||||
if len(conf.UserAgent) == 0 {
|
if len(conf.UserAgent) == 0 {
|
||||||
conf.UserAgent = restclient.DefaultKubernetesUserAgent()
|
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)
|
cl, err := restclient.RESTClientFor(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -255,6 +254,18 @@ func (dynamicCodec) Encode(obj runtime.Object, w io.Writer) error {
|
||||||
return runtime.UnstructuredJSONScheme.Encode(obj, w)
|
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
|
// paramaterCodec is a codec converts an API object to query
|
||||||
// parameters without trying to convert to the target version.
|
// parameters without trying to convert to the target version.
|
||||||
type parameterCodec struct{}
|
type parameterCodec struct{}
|
||||||
|
|
Loading…
Reference in New Issue