Skip to content

Commit

Permalink
Use the simpler DirectEncoder method to make init a bit terser
Browse files Browse the repository at this point in the history
Minor adjustment for getting a direct encoder factory.
  • Loading branch information
smarterclayton committed Feb 18, 2019
1 parent 508a800 commit 53a9962
Show file tree
Hide file tree
Showing 112 changed files with 81 additions and 175 deletions.
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/drain/drain_test.go
Expand Up @@ -166,7 +166,7 @@ func TestCordon(t *testing.T) {
defer tf.Cleanup()

codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := scheme.Codecs
ns := scheme.Codecs.Direct()

newNode := &corev1.Node{}
updated := false
Expand Down Expand Up @@ -731,7 +731,7 @@ func TestDrain(t *testing.T) {
defer tf.Cleanup()

codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := scheme.Codecs
ns := scheme.Codecs.Direct()

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Group: "", Version: "v1"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/expose/expose_test.go
Expand Up @@ -602,7 +602,7 @@ func TestRunExposeService(t *testing.T) {
defer tf.Cleanup()

codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := scheme.Codecs
ns := scheme.Codecs.Direct()

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: "v1"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/portforward/portforward_test.go
Expand Up @@ -77,7 +77,7 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) {
defer tf.Cleanup()

codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := scheme.Codecs
ns := scheme.Codecs.Direct()

tf.Client = &fake.RESTClient{
VersionedAPIPath: "/api/v1",
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/run/run_test.go
Expand Up @@ -168,7 +168,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
defer tf.Cleanup()

codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := scheme.Codecs
ns := scheme.Codecs.Direct()

tf.Client = &fake.RESTClient{
GroupVersion: corev1.SchemeGroupVersion,
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestGenerateService(t *testing.T) {
defer tf.Cleanup()

codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := scheme.Codecs
ns := scheme.Codecs.Direct()

tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
tf.Client = &fake.RESTClient{
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubectl/cmd/set/set_env_test.go
Expand Up @@ -47,7 +47,7 @@ func TestSetEnvLocal(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""},
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
t.Fatalf("unexpected request: %s %#v\n%#v", req.Method, req.URL, req)
return nil, nil
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""},
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
t.Fatalf("unexpected request: %s %#v\n%#v", req.Method, req.URL, req)
return nil, nil
Expand Down Expand Up @@ -447,7 +447,7 @@ func TestSetEnvRemote(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: input.groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == input.path && m == http.MethodGet:
Expand Down Expand Up @@ -582,7 +582,7 @@ func TestSetEnvFromResource(t *testing.T) {
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Group: "", Version: "v1"},
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/configmaps/testconfigmap" && m == http.MethodGet:
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubectl/cmd/set/set_image_test.go
Expand Up @@ -48,7 +48,7 @@ func TestImageLocal(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""},
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
t.Fatalf("unexpected request: %s %#v\n%#v", req.Method, req.URL, req)
return nil, nil
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""},
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
t.Fatalf("unexpected request: %s %#v\n%#v", req.Method, req.URL, req)
return nil, nil
Expand Down Expand Up @@ -620,7 +620,7 @@ func TestSetImageRemote(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: input.groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == input.path && m == http.MethodGet:
Expand Down Expand Up @@ -732,7 +732,7 @@ func TestSetImageRemoteWithSpecificContainers(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: input.groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == input.path && m == http.MethodGet:
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubectl/cmd/set/set_resources_test.go
Expand Up @@ -47,7 +47,7 @@ func TestResourcesLocal(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""},
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
t.Fatalf("unexpected request: %s %#v\n%#v", req.Method, req.URL, req)
return nil, nil
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""},
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
t.Fatalf("unexpected request: %s %#v\n%#v", req.Method, req.URL, req)
return nil, nil
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestSetResourcesRemote(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: input.groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == input.path && m == http.MethodGet:
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/set/set_serviceaccount_test.go
Expand Up @@ -103,7 +103,7 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""},
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
t.Fatalf("unexpected request: %s %#v\n%#v", req.Method, req.URL, req)
return nil, nil
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestSetServiceAccountRemote(t *testing.T) {

tf.Client = &fake.RESTClient{
GroupVersion: input.groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == input.path && m == http.MethodGet:
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/taint/taint_test.go
Expand Up @@ -243,7 +243,7 @@ func TestTaint(t *testing.T) {
defer tf.Cleanup()

codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := scheme.Codecs
ns := scheme.Codecs.Direct()

tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
Expand Down
1 change: 0 additions & 1 deletion pkg/kubectl/cmd/util/BUILD
Expand Up @@ -26,7 +26,6 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/yaml:go_default_library",
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubectl/cmd/util/kubectl_match_version.go
Expand Up @@ -23,7 +23,6 @@ import (

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -124,7 +123,7 @@ func setKubernetesDefaults(config *rest.Config) error {
// This codec factory ensures the resources are not converted. Therefore, resources
// will not be round-tripped through internal versions. Defaulting does not happen
// on the client.
config.NegotiatedSerializer = &serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}
config.NegotiatedSerializer = scheme.Codecs.Direct()
}
return rest.SetKubernetesDefaults(config)
}
2 changes: 1 addition & 1 deletion pkg/kubelet/certificate/bootstrap/bootstrap.go
Expand Up @@ -276,7 +276,7 @@ func verifyKeyData(data []byte) bool {
}

func waitForServer(cfg restclient.Config, deadline time.Duration) error {
cfg.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}
cfg.NegotiatedSerializer = scheme.Codecs.Direct()
cfg.Timeout = 1 * time.Second
cli, err := restclient.UnversionedRESTClientFor(&cfg)
if err != nil {
Expand Down
Expand Up @@ -15,7 +15,6 @@ go_library(
"//staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/apis/cr/v1:go_default_library",
"//staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/clientset/versioned/scheme:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/client-go/rest:go_default_library",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -19,7 +19,6 @@ go_library(
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1:go_default_library",
"//staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/scheme:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/client-go/rest:go_default_library",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -154,7 +154,7 @@ func TestTableGet(t *testing.T) {
crConfig := *config
crConfig.GroupVersion = &gv
crConfig.APIPath = "/apis"
crConfig.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: codecs}
crConfig.NegotiatedSerializer = codecs.Direct()
crRestClient, err := rest.RESTClientFor(&crConfig)
if err != nil {
t.Fatal(err)
Expand Down
Expand Up @@ -169,7 +169,7 @@ func TestAuditAnnotation(t *testing.T) {
}

scheme := runtime.NewScheme()
negotiatedSerializer := serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}
negotiatedSerializer := serializer.NewCodecFactory(scheme).Direct()
for k, tc := range testcases {
audit := &auditinternal.Event{Level: auditinternal.LevelMetadata}
handler := WithAuthorization(&fakeHTTPHandler{}, tc.authorizer, negotiatedSerializer)
Expand Down
Expand Up @@ -76,7 +76,7 @@ func TestForbidden(t *testing.T) {
for _, test := range cases {
observer := httptest.NewRecorder()
scheme := runtime.NewScheme()
negotiatedSerializer := serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}
negotiatedSerializer := serializer.NewCodecFactory(scheme).Direct()
Forbidden(request.NewDefaultContext(), test.attributes, observer, &http.Request{}, test.reason, negotiatedSerializer)
result := string(observer.Body.Bytes())
if result != test.expected {
Expand Down
Expand Up @@ -257,7 +257,7 @@ func (b *Builder) WithScheme(scheme *runtime.Scheme, decodingVersions ...schema.
// if you specified versions, you're specifying a desire for external types, which you don't want to round-trip through
// internal types
if len(decodingVersions) > 0 {
negotiatedSerializer = &serializer.DirectCodecFactory{CodecFactory: codecFactory}
negotiatedSerializer = codecFactory.Direct()
}
b.negotiatedSerializer = negotiatedSerializer

Expand Down
Expand Up @@ -83,7 +83,7 @@ func fakeClientWith(testName string, t *testing.T, data map[string]string) FakeC
return func(version schema.GroupVersion) (RESTClient, error) {
return &fake.RESTClient{
GroupVersion: corev1GV,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
p := req.URL.Path
q := req.URL.RawQuery
Expand Down
Expand Up @@ -304,7 +304,7 @@ func TestHelperGet(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
client := &fake.RESTClient{
GroupVersion: corev1GV,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Resp: tt.Resp,
Err: tt.HttpErr,
}
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestHelperList(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
client := &fake.RESTClient{
GroupVersion: corev1GV,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Resp: tt.Resp,
Err: tt.HttpErr,
}
Expand Down Expand Up @@ -596,7 +596,7 @@ func TestHelperReplace(t *testing.T) {
t.Run(tt.Name, func(t *testing.T) {
client := &fake.RESTClient{
GroupVersion: corev1GV,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
NegotiatedSerializer: scheme.Codecs.Direct(),
Client: tt.HTTPClient,
Resp: tt.Resp,
Err: tt.HttpErr,
Expand Down
Expand Up @@ -15,7 +15,6 @@ go_library(
deps = [
"//staging/src/k8s.io/api/admissionregistration/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -19,7 +19,6 @@ go_library(
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -20,7 +20,6 @@ go_library(
deps = [
"//staging/src/k8s.io/api/apps/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
Expand Down

0 comments on commit 53a9962

Please sign in to comment.