mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-11 12:02:30 +00:00
Merge pull request #133851 from andremarianiello/respect-dynamic-fake-options
client-go/dynamic/fake: Stop ignoring options Kubernetes-commit: 39b160f10cf0a71954b58dcc60a013ff7faa34fa
This commit is contained in:
@@ -168,7 +168,7 @@ func (c *dynamicResourceClient) Create(ctx context.Context, obj *unstructured.Un
|
|||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0 && len(subresources) == 0:
|
case len(c.namespace) == 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootCreateAction(c.resource, obj), obj)
|
Invokes(testing.NewRootCreateActionWithOptions(c.resource, obj, opts), obj)
|
||||||
|
|
||||||
case len(c.namespace) == 0 && len(subresources) > 0:
|
case len(c.namespace) == 0 && len(subresources) > 0:
|
||||||
var accessor metav1.Object // avoid shadowing err
|
var accessor metav1.Object // avoid shadowing err
|
||||||
@@ -178,11 +178,11 @@ func (c *dynamicResourceClient) Create(ctx context.Context, obj *unstructured.Un
|
|||||||
}
|
}
|
||||||
name := accessor.GetName()
|
name := accessor.GetName()
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootCreateSubresourceAction(c.resource, name, strings.Join(subresources, "/"), obj), obj)
|
Invokes(testing.NewRootCreateSubresourceActionWithOptions(c.resource, name, strings.Join(subresources, "/"), obj, opts), obj)
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) == 0:
|
case len(c.namespace) > 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewCreateAction(c.resource, c.namespace, obj), obj)
|
Invokes(testing.NewCreateActionWithOptions(c.resource, c.namespace, obj, opts), obj)
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) > 0:
|
case len(c.namespace) > 0 && len(subresources) > 0:
|
||||||
var accessor metav1.Object // avoid shadowing err
|
var accessor metav1.Object // avoid shadowing err
|
||||||
@@ -192,7 +192,7 @@ func (c *dynamicResourceClient) Create(ctx context.Context, obj *unstructured.Un
|
|||||||
}
|
}
|
||||||
name := accessor.GetName()
|
name := accessor.GetName()
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewCreateSubresourceAction(c.resource, name, strings.Join(subresources, "/"), c.namespace, obj), obj)
|
Invokes(testing.NewCreateSubresourceActionWithOptions(c.resource, name, strings.Join(subresources, "/"), c.namespace, obj, opts), obj)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,19 +216,19 @@ func (c *dynamicResourceClient) Update(ctx context.Context, obj *unstructured.Un
|
|||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0 && len(subresources) == 0:
|
case len(c.namespace) == 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootUpdateAction(c.resource, obj), obj)
|
Invokes(testing.NewRootUpdateActionWithOptions(c.resource, obj, opts), obj)
|
||||||
|
|
||||||
case len(c.namespace) == 0 && len(subresources) > 0:
|
case len(c.namespace) == 0 && len(subresources) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootUpdateSubresourceAction(c.resource, strings.Join(subresources, "/"), obj), obj)
|
Invokes(testing.NewRootUpdateSubresourceActionWithOptions(c.resource, strings.Join(subresources, "/"), obj, opts), obj)
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) == 0:
|
case len(c.namespace) > 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewUpdateAction(c.resource, c.namespace, obj), obj)
|
Invokes(testing.NewUpdateActionWithOptions(c.resource, c.namespace, obj, opts), obj)
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) > 0:
|
case len(c.namespace) > 0 && len(subresources) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewUpdateSubresourceAction(c.resource, strings.Join(subresources, "/"), c.namespace, obj), obj)
|
Invokes(testing.NewUpdateSubresourceActionWithOptions(c.resource, strings.Join(subresources, "/"), c.namespace, obj, opts), obj)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,11 +252,11 @@ func (c *dynamicResourceClient) UpdateStatus(ctx context.Context, obj *unstructu
|
|||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0:
|
case len(c.namespace) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootUpdateSubresourceAction(c.resource, "status", obj), obj)
|
Invokes(testing.NewRootUpdateSubresourceActionWithOptions(c.resource, "status", obj, opts), obj)
|
||||||
|
|
||||||
case len(c.namespace) > 0:
|
case len(c.namespace) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewUpdateSubresourceAction(c.resource, "status", c.namespace, obj), obj)
|
Invokes(testing.NewUpdateSubresourceActionWithOptions(c.resource, "status", c.namespace, obj, opts), obj)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,11 +301,11 @@ func (c *dynamicResourceClient) DeleteCollection(ctx context.Context, opts metav
|
|||||||
var err error
|
var err error
|
||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0:
|
case len(c.namespace) == 0:
|
||||||
action := testing.NewRootDeleteCollectionAction(c.resource, listOptions)
|
action := testing.NewRootDeleteCollectionActionWithOptions(c.resource, opts, listOptions)
|
||||||
_, err = c.client.Fake.Invokes(action, &metav1.Status{Status: "dynamic deletecollection fail"})
|
_, err = c.client.Fake.Invokes(action, &metav1.Status{Status: "dynamic deletecollection fail"})
|
||||||
|
|
||||||
case len(c.namespace) > 0:
|
case len(c.namespace) > 0:
|
||||||
action := testing.NewDeleteCollectionAction(c.resource, c.namespace, listOptions)
|
action := testing.NewDeleteCollectionActionWithOptions(c.resource, c.namespace, opts, listOptions)
|
||||||
_, err = c.client.Fake.Invokes(action, &metav1.Status{Status: "dynamic deletecollection fail"})
|
_, err = c.client.Fake.Invokes(action, &metav1.Status{Status: "dynamic deletecollection fail"})
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -319,19 +319,19 @@ func (c *dynamicResourceClient) Get(ctx context.Context, name string, opts metav
|
|||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0 && len(subresources) == 0:
|
case len(c.namespace) == 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootGetAction(c.resource, name), &metav1.Status{Status: "dynamic get fail"})
|
Invokes(testing.NewRootGetActionWithOptions(c.resource, name, opts), &metav1.Status{Status: "dynamic get fail"})
|
||||||
|
|
||||||
case len(c.namespace) == 0 && len(subresources) > 0:
|
case len(c.namespace) == 0 && len(subresources) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootGetSubresourceAction(c.resource, strings.Join(subresources, "/"), name), &metav1.Status{Status: "dynamic get fail"})
|
Invokes(testing.NewRootGetSubresourceActionWithOptions(c.resource, strings.Join(subresources, "/"), name, opts), &metav1.Status{Status: "dynamic get fail"})
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) == 0:
|
case len(c.namespace) > 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewGetAction(c.resource, c.namespace, name), &metav1.Status{Status: "dynamic get fail"})
|
Invokes(testing.NewGetActionWithOptions(c.resource, c.namespace, name, opts), &metav1.Status{Status: "dynamic get fail"})
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) > 0:
|
case len(c.namespace) > 0 && len(subresources) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewGetSubresourceAction(c.resource, c.namespace, strings.Join(subresources, "/"), name), &metav1.Status{Status: "dynamic get fail"})
|
Invokes(testing.NewGetSubresourceActionWithOptions(c.resource, c.namespace, strings.Join(subresources, "/"), name, opts), &metav1.Status{Status: "dynamic get fail"})
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -360,11 +360,11 @@ func (c *dynamicResourceClient) List(ctx context.Context, opts metav1.ListOption
|
|||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0:
|
case len(c.namespace) == 0:
|
||||||
obj, err = c.client.Fake.
|
obj, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootListAction(c.resource, listForFakeClientGVK, opts), &metav1.Status{Status: "dynamic list fail"})
|
Invokes(testing.NewRootListActionWithOptions(c.resource, listForFakeClientGVK, opts), &metav1.Status{Status: "dynamic list fail"})
|
||||||
|
|
||||||
case len(c.namespace) > 0:
|
case len(c.namespace) > 0:
|
||||||
obj, err = c.client.Fake.
|
obj, err = c.client.Fake.
|
||||||
Invokes(testing.NewListAction(c.resource, listForFakeClientGVK, c.namespace, opts), &metav1.Status{Status: "dynamic list fail"})
|
Invokes(testing.NewListActionWithOptions(c.resource, listForFakeClientGVK, c.namespace, opts), &metav1.Status{Status: "dynamic list fail"})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,11 +409,11 @@ func (c *dynamicResourceClient) Watch(ctx context.Context, opts metav1.ListOptio
|
|||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0:
|
case len(c.namespace) == 0:
|
||||||
return c.client.Fake.
|
return c.client.Fake.
|
||||||
InvokesWatch(testing.NewRootWatchAction(c.resource, opts))
|
InvokesWatch(testing.NewRootWatchActionWithOptions(c.resource, opts))
|
||||||
|
|
||||||
case len(c.namespace) > 0:
|
case len(c.namespace) > 0:
|
||||||
return c.client.Fake.
|
return c.client.Fake.
|
||||||
InvokesWatch(testing.NewWatchAction(c.resource, c.namespace, opts))
|
InvokesWatch(testing.NewWatchActionWithOptions(c.resource, c.namespace, opts))
|
||||||
}
|
}
|
||||||
|
|
||||||
panic("math broke")
|
panic("math broke")
|
||||||
@@ -426,19 +426,19 @@ func (c *dynamicResourceClient) Patch(ctx context.Context, name string, pt types
|
|||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0 && len(subresources) == 0:
|
case len(c.namespace) == 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootPatchAction(c.resource, name, pt, data), &metav1.Status{Status: "dynamic patch fail"})
|
Invokes(testing.NewRootPatchActionWithOptions(c.resource, name, pt, data, opts), &metav1.Status{Status: "dynamic patch fail"})
|
||||||
|
|
||||||
case len(c.namespace) == 0 && len(subresources) > 0:
|
case len(c.namespace) == 0 && len(subresources) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootPatchSubresourceAction(c.resource, name, pt, data, subresources...), &metav1.Status{Status: "dynamic patch fail"})
|
Invokes(testing.NewRootPatchSubresourceActionWithOptions(c.resource, name, pt, data, opts, subresources...), &metav1.Status{Status: "dynamic patch fail"})
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) == 0:
|
case len(c.namespace) > 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewPatchAction(c.resource, c.namespace, name, pt, data), &metav1.Status{Status: "dynamic patch fail"})
|
Invokes(testing.NewPatchActionWithOptions(c.resource, c.namespace, name, pt, data, opts), &metav1.Status{Status: "dynamic patch fail"})
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) > 0:
|
case len(c.namespace) > 0 && len(subresources) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewPatchSubresourceAction(c.resource, c.namespace, name, pt, data, subresources...), &metav1.Status{Status: "dynamic patch fail"})
|
Invokes(testing.NewPatchSubresourceActionWithOptions(c.resource, c.namespace, name, pt, data, opts, subresources...), &metav1.Status{Status: "dynamic patch fail"})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,23 +462,28 @@ func (c *dynamicResourceClient) Apply(ctx context.Context, name string, obj *uns
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
patchOptions := metav1.PatchOptions{
|
||||||
|
Force: &options.Force,
|
||||||
|
DryRun: options.DryRun,
|
||||||
|
FieldManager: options.FieldManager,
|
||||||
|
}
|
||||||
var uncastRet runtime.Object
|
var uncastRet runtime.Object
|
||||||
switch {
|
switch {
|
||||||
case len(c.namespace) == 0 && len(subresources) == 0:
|
case len(c.namespace) == 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootPatchAction(c.resource, name, types.ApplyPatchType, outBytes), &metav1.Status{Status: "dynamic patch fail"})
|
Invokes(testing.NewRootPatchActionWithOptions(c.resource, name, types.ApplyPatchType, outBytes, patchOptions), &metav1.Status{Status: "dynamic patch fail"})
|
||||||
|
|
||||||
case len(c.namespace) == 0 && len(subresources) > 0:
|
case len(c.namespace) == 0 && len(subresources) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewRootPatchSubresourceAction(c.resource, name, types.ApplyPatchType, outBytes, subresources...), &metav1.Status{Status: "dynamic patch fail"})
|
Invokes(testing.NewRootPatchSubresourceActionWithOptions(c.resource, name, types.ApplyPatchType, outBytes, patchOptions, subresources...), &metav1.Status{Status: "dynamic patch fail"})
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) == 0:
|
case len(c.namespace) > 0 && len(subresources) == 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewPatchAction(c.resource, c.namespace, name, types.ApplyPatchType, outBytes), &metav1.Status{Status: "dynamic patch fail"})
|
Invokes(testing.NewPatchActionWithOptions(c.resource, c.namespace, name, types.ApplyPatchType, outBytes, patchOptions), &metav1.Status{Status: "dynamic patch fail"})
|
||||||
|
|
||||||
case len(c.namespace) > 0 && len(subresources) > 0:
|
case len(c.namespace) > 0 && len(subresources) > 0:
|
||||||
uncastRet, err = c.client.Fake.
|
uncastRet, err = c.client.Fake.
|
||||||
Invokes(testing.NewPatchSubresourceAction(c.resource, c.namespace, name, types.ApplyPatchType, outBytes, subresources...), &metav1.Status{Status: "dynamic patch fail"})
|
Invokes(testing.NewPatchSubresourceActionWithOptions(c.resource, c.namespace, name, types.ApplyPatchType, outBytes, patchOptions, subresources...), &metav1.Status{Status: "dynamic patch fail"})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
go.mod
4
go.mod
@@ -25,8 +25,8 @@ require (
|
|||||||
golang.org/x/time v0.9.0
|
golang.org/x/time v0.9.0
|
||||||
google.golang.org/protobuf v1.36.6
|
google.golang.org/protobuf v1.36.6
|
||||||
gopkg.in/evanphx/json-patch.v4 v4.13.0
|
gopkg.in/evanphx/json-patch.v4 v4.13.0
|
||||||
k8s.io/api v0.0.0-20250901203655-82f77ebdf665
|
k8s.io/api v0.0.0-20250903042103-a2a241f99d37
|
||||||
k8s.io/apimachinery v0.0.0-20250901203349-2340d9bf7725
|
k8s.io/apimachinery v0.0.0-20250903081746-f33167494573
|
||||||
k8s.io/klog/v2 v2.130.1
|
k8s.io/klog/v2 v2.130.1
|
||||||
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b
|
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b
|
||||||
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
|
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
|
||||||
|
8
go.sum
8
go.sum
@@ -148,10 +148,10 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
|||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
k8s.io/api v0.0.0-20250901203655-82f77ebdf665 h1:tXyaymnd1lkW1B4+gxJBRsolnee9v9SYVNpamAemq3c=
|
k8s.io/api v0.0.0-20250903042103-a2a241f99d37 h1:ybz9dJ1Dy4rA1hD775Tjo5CGmdC2enFcMkn5gIPrx4g=
|
||||||
k8s.io/api v0.0.0-20250901203655-82f77ebdf665/go.mod h1:MUZMQv8g8lHQb2eyO/Uo7B5NN4E09dlElJ9ls7J0YSM=
|
k8s.io/api v0.0.0-20250903042103-a2a241f99d37/go.mod h1:MUZMQv8g8lHQb2eyO/Uo7B5NN4E09dlElJ9ls7J0YSM=
|
||||||
k8s.io/apimachinery v0.0.0-20250901203349-2340d9bf7725 h1:ZJjp+abIevhn1KFHm6gvXno1ssCePnBxCImQhHGr9X4=
|
k8s.io/apimachinery v0.0.0-20250903081746-f33167494573 h1:U4QezBSIuWaOR+NlUE1Ff+OkvDiDfZz4Ja/zzGOWCz0=
|
||||||
k8s.io/apimachinery v0.0.0-20250901203349-2340d9bf7725/go.mod h1:7OLTj40s+nlro63xSAmcBvG2yQchJEdd+Lq2NGRhUlY=
|
k8s.io/apimachinery v0.0.0-20250903081746-f33167494573/go.mod h1:7OLTj40s+nlro63xSAmcBvG2yQchJEdd+Lq2NGRhUlY=
|
||||||
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
|
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
|
||||||
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
|
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
|
||||||
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOPolHyvO06MXG5TUIj2mNAA=
|
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOPolHyvO06MXG5TUIj2mNAA=
|
||||||
|
Reference in New Issue
Block a user