mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
apply: use unstructured objects
This commit is contained in:
parent
d41e391799
commit
aaf96a1048
@ -28,6 +28,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
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/labels"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"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()
|
mapper, typer, err := f.UnstructuredObject()
|
||||||
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.UnstructuredClientForMapping), unstructured.UnstructuredJSONScheme).
|
||||||
Schema(schema).
|
Schema(schema).
|
||||||
ContinueOnError().
|
ContinueOnError().
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||||
|
@ -197,11 +197,11 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
|
|||||||
nameRC, rcBytes := readReplicationController(t, filenameRC)
|
nameRC, rcBytes := readReplicationController(t, filenameRC)
|
||||||
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
|
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
|
||||||
|
|
||||||
f, tf, _, ns := cmdtesting.NewAPIFactory()
|
f, tf, _, _ := cmdtesting.NewAPIFactory()
|
||||||
tf.Printer = &testPrinter{}
|
tf.Printer = &testPrinter{}
|
||||||
tf.Client = &fake.RESTClient{
|
tf.UnstructuredClient = &fake.RESTClient{
|
||||||
APIRegistry: api.Registry,
|
APIRegistry: api.Registry,
|
||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: unstructuredSerializer,
|
||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
case p == pathRC && m == "GET":
|
||||||
@ -242,11 +242,11 @@ func TestApplyObject(t *testing.T) {
|
|||||||
nameRC, currentRC := readAndAnnotateReplicationController(t, filenameRC)
|
nameRC, currentRC := readAndAnnotateReplicationController(t, filenameRC)
|
||||||
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
|
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
|
||||||
|
|
||||||
f, tf, _, ns := cmdtesting.NewAPIFactory()
|
f, tf, _, _ := cmdtesting.NewAPIFactory()
|
||||||
tf.Printer = &testPrinter{}
|
tf.Printer = &testPrinter{}
|
||||||
tf.Client = &fake.RESTClient{
|
tf.UnstructuredClient = &fake.RESTClient{
|
||||||
APIRegistry: api.Registry,
|
APIRegistry: api.Registry,
|
||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: unstructuredSerializer,
|
||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
case p == pathRC && m == "GET":
|
||||||
@ -286,11 +286,11 @@ func TestApplyRetry(t *testing.T) {
|
|||||||
firstPatch := true
|
firstPatch := true
|
||||||
retry := false
|
retry := false
|
||||||
getCount := 0
|
getCount := 0
|
||||||
f, tf, _, ns := cmdtesting.NewAPIFactory()
|
f, tf, _, _ := cmdtesting.NewAPIFactory()
|
||||||
tf.Printer = &testPrinter{}
|
tf.Printer = &testPrinter{}
|
||||||
tf.Client = &fake.RESTClient{
|
tf.UnstructuredClient = &fake.RESTClient{
|
||||||
APIRegistry: api.Registry,
|
APIRegistry: api.Registry,
|
||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: unstructuredSerializer,
|
||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
case p == pathRC && m == "GET":
|
||||||
@ -340,11 +340,11 @@ func TestApplyNonExistObject(t *testing.T) {
|
|||||||
pathRC := "/namespaces/test/replicationcontrollers"
|
pathRC := "/namespaces/test/replicationcontrollers"
|
||||||
pathNameRC := pathRC + "/" + nameRC
|
pathNameRC := pathRC + "/" + nameRC
|
||||||
|
|
||||||
f, tf, _, ns := cmdtesting.NewAPIFactory()
|
f, tf, _, _ := cmdtesting.NewAPIFactory()
|
||||||
tf.Printer = &testPrinter{}
|
tf.Printer = &testPrinter{}
|
||||||
tf.Client = &fake.RESTClient{
|
tf.UnstructuredClient = &fake.RESTClient{
|
||||||
APIRegistry: api.Registry,
|
APIRegistry: api.Registry,
|
||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: unstructuredSerializer,
|
||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/api/v1/namespaces/test" && m == "GET":
|
case p == "/api/v1/namespaces/test" && m == "GET":
|
||||||
@ -391,11 +391,11 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
|
|||||||
nameSVC, currentSVC := readAndAnnotateService(t, filenameSVC)
|
nameSVC, currentSVC := readAndAnnotateService(t, filenameSVC)
|
||||||
pathSVC := "/namespaces/test/services/" + nameSVC
|
pathSVC := "/namespaces/test/services/" + nameSVC
|
||||||
|
|
||||||
f, tf, _, ns := cmdtesting.NewAPIFactory()
|
f, tf, _, _ := cmdtesting.NewAPIFactory()
|
||||||
tf.Printer = &testPrinter{}
|
tf.Printer = &testPrinter{}
|
||||||
tf.Client = &fake.RESTClient{
|
tf.UnstructuredClient = &fake.RESTClient{
|
||||||
APIRegistry: api.Registry,
|
APIRegistry: api.Registry,
|
||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: unstructuredSerializer,
|
||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == pathRC && m == "GET":
|
case p == pathRC && m == "GET":
|
||||||
|
Loading…
Reference in New Issue
Block a user