mirror of https://github.com/k3s-io/k3s
Add NegotiatedSerializer to config
parent
43b644ea6f
commit
b4c83022e3
|
@ -204,7 +204,8 @@ func setConfigDefaults(config *$.Config|raw$) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
config.Codec = $.codecs|raw$.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = $.codecs|raw$
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
@ -232,11 +233,7 @@ func setConfigDefaults(config *$.Config|raw$) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
codec, ok := $.codecs|raw$.SerializerForFileExtension("json")
|
||||
if !ok {
|
||||
return $.Errorf|raw$("unable to find serializer for JSON")
|
||||
}
|
||||
config.Codec = codec
|
||||
config.NegotiatedSerializer = $.codecs|raw$
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
|
|
|
@ -80,7 +80,8 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -45,13 +45,14 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
Groups = make(map[string]TestGroup)
|
||||
Default TestGroup
|
||||
Autoscaling TestGroup
|
||||
Batch TestGroup
|
||||
Extensions TestGroup
|
||||
Apps TestGroup
|
||||
Federation TestGroup
|
||||
Groups = make(map[string]TestGroup)
|
||||
Default TestGroup
|
||||
Autoscaling TestGroup
|
||||
Batch TestGroup
|
||||
Extensions TestGroup
|
||||
Apps TestGroup
|
||||
Federation TestGroup
|
||||
NegotiatedSerializer = api.Codecs
|
||||
)
|
||||
|
||||
type TestGroup struct {
|
||||
|
|
|
@ -80,7 +80,8 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -155,7 +155,8 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -110,7 +110,8 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -149,7 +149,8 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -114,7 +114,8 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package v1
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
api "k8s.io/kubernetes/pkg/api"
|
||||
registered "k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
restclient "k8s.io/kubernetes/pkg/client/restclient"
|
||||
|
@ -150,11 +149,7 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
codec, ok := api.Codecs.SerializerForFileExtension("json")
|
||||
if !ok {
|
||||
return fmt.Errorf("unable to find serializer for JSON")
|
||||
}
|
||||
config.Codec = codec
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package v1beta1
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
api "k8s.io/kubernetes/pkg/api"
|
||||
registered "k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
restclient "k8s.io/kubernetes/pkg/client/restclient"
|
||||
|
@ -115,11 +114,7 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
codec, ok := api.Codecs.SerializerForFileExtension("json")
|
||||
if !ok {
|
||||
return fmt.Errorf("unable to find serializer for JSON")
|
||||
}
|
||||
config.Codec = codec
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
|
|
|
@ -63,7 +63,7 @@ type RESTClient struct {
|
|||
// NewRESTClient creates a new RESTClient. This client performs generic REST functions
|
||||
// such as Get, Put, Post, and Delete on specified paths. Codec controls encoding and
|
||||
// decoding of responses from the server.
|
||||
func NewRESTClient(baseURL *url.URL, versionedAPIPath string, config ContentConfig, maxQPS float32, maxBurst int, rateLimiter flowcontrol.RateLimiter, client *http.Client) *RESTClient {
|
||||
func NewRESTClient(baseURL *url.URL, versionedAPIPath string, config ContentConfig, maxQPS float32, maxBurst int, rateLimiter flowcontrol.RateLimiter, client *http.Client) (*RESTClient, error) {
|
||||
base := *baseURL
|
||||
if !strings.HasSuffix(base.Path, "/") {
|
||||
base.Path += "/"
|
||||
|
@ -90,7 +90,7 @@ func NewRESTClient(baseURL *url.URL, versionedAPIPath string, config ContentConf
|
|||
contentConfig: config,
|
||||
Throttle: throttle,
|
||||
Client: client,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetRateLimiter returns rate limier for a given client, or nil if it's called on a nil client
|
||||
|
@ -122,7 +122,8 @@ func readExpBackoffConfig() BackoffManager {
|
|||
// Verb begins a request with a verb (GET, POST, PUT, DELETE).
|
||||
//
|
||||
// Example usage of RESTClient's request building interface:
|
||||
// c := NewRESTClient(url, codec)
|
||||
// c, err := NewRESTClient(...)
|
||||
// if err != nil { ... }
|
||||
// resp, err := c.Verb("GET").
|
||||
// Path("pods").
|
||||
// SelectorParam("labels", "area=staging").
|
||||
|
|
|
@ -130,9 +130,15 @@ type ContentConfig struct {
|
|||
// a RESTClient directly. When initializing a Client, will be set with the default
|
||||
// code version.
|
||||
GroupVersion *unversioned.GroupVersion
|
||||
// NegotiatedSerializer is used for obtaining encoders and decoders for multiple
|
||||
// supported media types.
|
||||
NegotiatedSerializer runtime.NegotiatedSerializer
|
||||
|
||||
// Codec specifies the encoding and decoding behavior for runtime.Objects passed
|
||||
// to a RESTClient or Client. Required when initializing a RESTClient, optional
|
||||
// when initializing a Client.
|
||||
//
|
||||
// DEPRECATED: Please use NegotiatedSerializer instead.
|
||||
Codec runtime.Codec
|
||||
}
|
||||
|
||||
|
@ -144,8 +150,8 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
|
|||
if config.GroupVersion == nil {
|
||||
return nil, fmt.Errorf("GroupVersion is required when initializing a RESTClient")
|
||||
}
|
||||
if config.Codec == nil {
|
||||
return nil, fmt.Errorf("Codec is required when initializing a RESTClient")
|
||||
if config.NegotiatedSerializer == nil {
|
||||
return nil, fmt.Errorf("NegotiatedSerializer is required when initializing a RESTClient")
|
||||
}
|
||||
|
||||
baseURL, versionedAPIPath, err := defaultServerUrlFor(config)
|
||||
|
@ -163,16 +169,14 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
|
|||
httpClient = &http.Client{Transport: transport}
|
||||
}
|
||||
|
||||
client := NewRESTClient(baseURL, versionedAPIPath, config.ContentConfig, config.QPS, config.Burst, config.RateLimiter, httpClient)
|
||||
|
||||
return client, nil
|
||||
return NewRESTClient(baseURL, versionedAPIPath, config.ContentConfig, config.QPS, config.Burst, config.RateLimiter, httpClient)
|
||||
}
|
||||
|
||||
// UnversionedRESTClientFor is the same as RESTClientFor, except that it allows
|
||||
// the config.Version to be empty.
|
||||
func UnversionedRESTClientFor(config *Config) (*RESTClient, error) {
|
||||
if config.Codec == nil {
|
||||
return nil, fmt.Errorf("Codec is required when initializing a RESTClient")
|
||||
if config.NegotiatedSerializer == nil {
|
||||
return nil, fmt.Errorf("NeogitatedSerializer is required when initializing a RESTClient")
|
||||
}
|
||||
|
||||
baseURL, versionedAPIPath, err := defaultServerUrlFor(config)
|
||||
|
@ -196,8 +200,7 @@ func UnversionedRESTClientFor(config *Config) (*RESTClient, error) {
|
|||
versionConfig.GroupVersion = &v
|
||||
}
|
||||
|
||||
client := NewRESTClient(baseURL, versionedAPIPath, versionConfig, config.QPS, config.Burst, config.RateLimiter, httpClient)
|
||||
return client, nil
|
||||
return NewRESTClient(baseURL, versionedAPIPath, versionConfig, config.QPS, config.Burst, config.RateLimiter, httpClient)
|
||||
}
|
||||
|
||||
// SetKubernetesDefaults sets default values on the provided client config for accessing the
|
||||
|
|
|
@ -87,13 +87,13 @@ func TestSetKubernetesDefaultsUserAgent(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRESTClientRequires(t *testing.T) {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{Codec: testapi.Default.Codec()}}); err == nil {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{NegotiatedSerializer: testapi.NegotiatedSerializer}}); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: testapi.Default.GroupVersion(), Codec: testapi.Default.Codec()}}); err != nil {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: testapi.Default.GroupVersion(), NegotiatedSerializer: testapi.NegotiatedSerializer}}); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1308,5 +1308,9 @@ func testRESTClient(t testing.TB, srv *httptest.Server) *RESTClient {
|
|||
}
|
||||
}
|
||||
versionedAPIPath := testapi.Default.ResourcePath("", "", "")
|
||||
return NewRESTClient(baseURL, versionedAPIPath, ContentConfig{GroupVersion: testapi.Default.GroupVersion(), Codec: testapi.Default.Codec()}, 0, 0, nil, nil)
|
||||
client, err := NewRESTClient(baseURL, versionedAPIPath, ContentConfig{GroupVersion: testapi.Default.GroupVersion(), Codec: testapi.Default.Codec()}, 0, 0, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a client: %v", err)
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ func setAppsDefaults(config *restclient.Config) error {
|
|||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ func setAutoscalingDefaults(config *restclient.Config) error {
|
|||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ func setBatchDefaults(config *restclient.Config) error {
|
|||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -127,6 +127,7 @@ func setExtensionsDefaults(config *restclient.Config) error {
|
|||
//}
|
||||
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
|
|
|
@ -231,6 +231,9 @@ func SetKubernetesDefaults(config *restclient.Config) error {
|
|||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
if config.NegotiatedSerializer == nil {
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
}
|
||||
if config.Codec == nil {
|
||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||
}
|
||||
|
|
|
@ -40,8 +40,9 @@ func TestSetKubernetesDefaults(t *testing.T) {
|
|||
restclient.Config{
|
||||
APIPath: "/api",
|
||||
ContentConfig: restclient.ContentConfig{
|
||||
GroupVersion: testapi.Default.GroupVersion(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
GroupVersion: testapi.Default.GroupVersion(),
|
||||
Codec: testapi.Default.Codec(),
|
||||
NegotiatedSerializer: testapi.NegotiatedSerializer,
|
||||
},
|
||||
QPS: 5,
|
||||
Burst: 10,
|
||||
|
@ -125,7 +126,7 @@ func TestHelperGetServerAPIVersions(t *testing.T) {
|
|||
w.Write(output)
|
||||
}))
|
||||
defer server.Close()
|
||||
got, err := restclient.ServerAPIVersions(&restclient.Config{Host: server.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &unversioned.GroupVersion{Group: "invalid version", Version: "one"}, Codec: testapi.Default.Codec()}})
|
||||
got, err := restclient.ServerAPIVersions(&restclient.Config{Host: server.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &unversioned.GroupVersion{Group: "invalid version", Version: "one"}, NegotiatedSerializer: testapi.NegotiatedSerializer}})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected encoding error: %v", err)
|
||||
}
|
||||
|
|
|
@ -212,7 +212,10 @@ func TestStream(t *testing.T) {
|
|||
server := httptest.NewServer(fakeServer(t, name, exec, testCase.Stdin, testCase.Stdout, testCase.Stderr, testCase.Error, testCase.Tty, testCase.MessageCount, testCase.ServerProtocols))
|
||||
|
||||
url, _ := url.ParseRequestURI(server.URL)
|
||||
c := restclient.NewRESTClient(url, "", restclient.ContentConfig{GroupVersion: &unversioned.GroupVersion{Group: "x"}}, -1, -1, nil, nil)
|
||||
c, err := restclient.NewRESTClient(url, "", restclient.ContentConfig{GroupVersion: &unversioned.GroupVersion{Group: "x"}}, -1, -1, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a client: %v", err)
|
||||
}
|
||||
req := c.Post().Resource("testing")
|
||||
|
||||
if exec {
|
||||
|
|
Loading…
Reference in New Issue