diff --git a/pkg/kubectl/cmd/apply.go b/pkg/kubectl/cmd/apply.go index 4afcfcb5fa2..2c69cf1cbc5 100644 --- a/pkg/kubectl/cmd/apply.go +++ b/pkg/kubectl/cmd/apply.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -181,8 +182,11 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti } } - mapper, typer := f.Object() - r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)). + mapper, typer, err := f.UnstructuredObject() + if err != nil { + return err + } + r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.UnstructuredClientForMapping), unstructured.UnstructuredJSONScheme). Schema(schema). ContinueOnError(). NamespaceParam(cmdNamespace).DefaultNamespace(). diff --git a/pkg/kubectl/cmd/apply_test.go b/pkg/kubectl/cmd/apply_test.go index 89a4d425f97..c41de7aa158 100644 --- a/pkg/kubectl/cmd/apply_test.go +++ b/pkg/kubectl/cmd/apply_test.go @@ -197,11 +197,11 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) { nameRC, rcBytes := readReplicationController(t, filenameRC) pathRC := "/namespaces/test/replicationcontrollers/" + nameRC - f, tf, _, ns := cmdtesting.NewAPIFactory() + f, tf, _, _ := cmdtesting.NewAPIFactory() tf.Printer = &testPrinter{} - tf.Client = &fake.RESTClient{ + tf.UnstructuredClient = &fake.RESTClient{ APIRegistry: api.Registry, - NegotiatedSerializer: ns, + NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { switch p, m := req.URL.Path, req.Method; { case p == pathRC && m == "GET": @@ -242,11 +242,11 @@ func TestApplyObject(t *testing.T) { nameRC, currentRC := readAndAnnotateReplicationController(t, filenameRC) pathRC := "/namespaces/test/replicationcontrollers/" + nameRC - f, tf, _, ns := cmdtesting.NewAPIFactory() + f, tf, _, _ := cmdtesting.NewAPIFactory() tf.Printer = &testPrinter{} - tf.Client = &fake.RESTClient{ + tf.UnstructuredClient = &fake.RESTClient{ APIRegistry: api.Registry, - NegotiatedSerializer: ns, + NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { switch p, m := req.URL.Path, req.Method; { case p == pathRC && m == "GET": @@ -286,11 +286,11 @@ func TestApplyRetry(t *testing.T) { firstPatch := true retry := false getCount := 0 - f, tf, _, ns := cmdtesting.NewAPIFactory() + f, tf, _, _ := cmdtesting.NewAPIFactory() tf.Printer = &testPrinter{} - tf.Client = &fake.RESTClient{ + tf.UnstructuredClient = &fake.RESTClient{ APIRegistry: api.Registry, - NegotiatedSerializer: ns, + NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { switch p, m := req.URL.Path, req.Method; { case p == pathRC && m == "GET": @@ -340,11 +340,11 @@ func TestApplyNonExistObject(t *testing.T) { pathRC := "/namespaces/test/replicationcontrollers" pathNameRC := pathRC + "/" + nameRC - f, tf, _, ns := cmdtesting.NewAPIFactory() + f, tf, _, _ := cmdtesting.NewAPIFactory() tf.Printer = &testPrinter{} - tf.Client = &fake.RESTClient{ + tf.UnstructuredClient = &fake.RESTClient{ APIRegistry: api.Registry, - NegotiatedSerializer: ns, + NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { switch p, m := req.URL.Path, req.Method; { case p == "/api/v1/namespaces/test" && m == "GET": @@ -391,11 +391,11 @@ func testApplyMultipleObjects(t *testing.T, asList bool) { nameSVC, currentSVC := readAndAnnotateService(t, filenameSVC) pathSVC := "/namespaces/test/services/" + nameSVC - f, tf, _, ns := cmdtesting.NewAPIFactory() + f, tf, _, _ := cmdtesting.NewAPIFactory() tf.Printer = &testPrinter{} - tf.Client = &fake.RESTClient{ + tf.UnstructuredClient = &fake.RESTClient{ APIRegistry: api.Registry, - NegotiatedSerializer: ns, + NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { switch p, m := req.URL.Path, req.Method; { case p == pathRC && m == "GET":