From 29424b90cbd261128ffb6bcc7f7497b411ce0a87 Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Wed, 1 Aug 2018 10:35:43 -0700 Subject: [PATCH] dry-run: Update DynamicClient to pass Create/Update options Kubernetes-commit: 71970d6475f6570d933fa9f22be2ebc20a9ace6f --- deprecated-dynamic/client.go | 6 ++--- dynamic/client_test.go | 6 ++--- dynamic/fake/simple.go | 8 +++--- dynamic/interface.go | 8 +++--- dynamic/simple.go | 49 ++++++++++++++++++++++++++++-------- 5 files changed, 53 insertions(+), 24 deletions(-) diff --git a/deprecated-dynamic/client.go b/deprecated-dynamic/client.go index 0974fe64..3b8efffa 100644 --- a/deprecated-dynamic/client.go +++ b/deprecated-dynamic/client.go @@ -107,11 +107,11 @@ type oldResourceShimType struct { } func (s oldResourceShimType) Create(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { - return s.ResourceInterface.Create(obj, s.subresources...) + return s.ResourceInterface.Create(obj, metav1.CreateOptions{}, s.subresources...) } func (s oldResourceShimType) Update(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { - return s.ResourceInterface.Update(obj, s.subresources...) + return s.ResourceInterface.Update(obj, metav1.UpdateOptions{}, s.subresources...) } func (s oldResourceShimType) Delete(name string, opts *metav1.DeleteOptions) error { @@ -127,5 +127,5 @@ func (s oldResourceShimType) List(opts metav1.ListOptions) (runtime.Object, erro } func (s oldResourceShimType) Patch(name string, pt types.PatchType, data []byte) (*unstructured.Unstructured, error) { - return s.ResourceInterface.Patch(name, pt, data, s.subresources...) + return s.ResourceInterface.Patch(name, pt, data, metav1.UpdateOptions{}, s.subresources...) } diff --git a/dynamic/client_test.go b/dynamic/client_test.go index e8fe9386..e74cb832 100644 --- a/dynamic/client_test.go +++ b/dynamic/client_test.go @@ -404,7 +404,7 @@ func TestCreate(t *testing.T) { } defer srv.Close() - got, err := cl.Resource(resource).Namespace(tc.namespace).Create(tc.obj, tc.subresource...) + got, err := cl.Resource(resource).Namespace(tc.namespace).Create(tc.obj, metav1.CreateOptions{}, tc.subresource...) if err != nil { t.Errorf("unexpected error when creating %q: %v", tc.name, err) continue @@ -481,7 +481,7 @@ func TestUpdate(t *testing.T) { } defer srv.Close() - got, err := cl.Resource(resource).Namespace(tc.namespace).Update(tc.obj, tc.subresource...) + got, err := cl.Resource(resource).Namespace(tc.namespace).Update(tc.obj, metav1.UpdateOptions{}, tc.subresource...) if err != nil { t.Errorf("unexpected error when updating %q: %v", tc.name, err) continue @@ -638,7 +638,7 @@ func TestPatch(t *testing.T) { } defer srv.Close() - got, err := cl.Resource(resource).Namespace(tc.namespace).Patch(tc.name, types.StrategicMergePatchType, tc.patch, tc.subresource...) + got, err := cl.Resource(resource).Namespace(tc.namespace).Patch(tc.name, types.StrategicMergePatchType, tc.patch, metav1.UpdateOptions{}, tc.subresource...) if err != nil { t.Errorf("unexpected error when patching %q: %v", tc.name, err) continue diff --git a/dynamic/fake/simple.go b/dynamic/fake/simple.go index 7be914c9..24e5c7bf 100644 --- a/dynamic/fake/simple.go +++ b/dynamic/fake/simple.go @@ -86,7 +86,7 @@ func (c *dynamicResourceClient) Namespace(ns string) dynamic.ResourceInterface { return &ret } -func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error) { +func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, opts metav1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error) { var uncastRet runtime.Object var err error switch { @@ -132,7 +132,7 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, subresour return ret, err } -func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error) { +func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, opts metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) { var uncastRet runtime.Object var err error switch { @@ -168,7 +168,7 @@ func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, subresour return ret, err } -func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { +func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured, opts metav1.UpdateOptions) (*unstructured.Unstructured, error) { var uncastRet runtime.Object var err error switch { @@ -331,7 +331,7 @@ func (c *dynamicResourceClient) Watch(opts metav1.ListOptions) (watch.Interface, panic("math broke") } -func (c *dynamicResourceClient) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*unstructured.Unstructured, error) { +func (c *dynamicResourceClient) Patch(name string, pt types.PatchType, data []byte, opts metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) { var uncastRet runtime.Object var err error switch { diff --git a/dynamic/interface.go b/dynamic/interface.go index 3f364f87..c457be17 100644 --- a/dynamic/interface.go +++ b/dynamic/interface.go @@ -29,15 +29,15 @@ type Interface interface { } type ResourceInterface interface { - Create(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error) - Update(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error) - UpdateStatus(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) + Create(obj *unstructured.Unstructured, options metav1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error) + Update(obj *unstructured.Unstructured, options metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) + UpdateStatus(obj *unstructured.Unstructured, options metav1.UpdateOptions) (*unstructured.Unstructured, error) Delete(name string, options *metav1.DeleteOptions, subresources ...string) error DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error Get(name string, options metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error) List(opts metav1.ListOptions) (*unstructured.UnstructuredList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*unstructured.Unstructured, error) + Patch(name string, pt types.PatchType, data []byte, options metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) } type NamespaceableResourceInterface interface { diff --git a/dynamic/simple.go b/dynamic/simple.go index 2bc7b50e..9e21cda6 100644 --- a/dynamic/simple.go +++ b/dynamic/simple.go @@ -82,7 +82,7 @@ func (c *dynamicResourceClient) Namespace(ns string) ResourceInterface { return &ret } -func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error) { +func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, opts metav1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error) { outBytes, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj) if err != nil { return nil, err @@ -96,7 +96,12 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, subresour name = accessor.GetName() } - result := c.client.client.Post().AbsPath(append(c.makeURLSegments(name), subresources...)...).Body(outBytes).Do() + result := c.client.client. + Post(). + AbsPath(append(c.makeURLSegments(name), subresources...)...). + Body(outBytes). + SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). + Do() if err := result.Error(); err != nil { return nil, err } @@ -112,7 +117,7 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, subresour return uncastObj.(*unstructured.Unstructured), nil } -func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error) { +func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, opts metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) { accessor, err := meta.Accessor(obj) if err != nil { return nil, err @@ -122,7 +127,12 @@ func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, subresour return nil, err } - result := c.client.client.Put().AbsPath(append(c.makeURLSegments(accessor.GetName()), subresources...)...).Body(outBytes).Do() + result := c.client.client. + Put(). + AbsPath(append(c.makeURLSegments(accessor.GetName()), subresources...)...). + Body(outBytes). + SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). + Do() if err := result.Error(); err != nil { return nil, err } @@ -138,7 +148,7 @@ func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, subresour return uncastObj.(*unstructured.Unstructured), nil } -func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { +func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured, opts metav1.UpdateOptions) (*unstructured.Unstructured, error) { accessor, err := meta.Accessor(obj) if err != nil { return nil, err @@ -149,7 +159,12 @@ func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured) (*u return nil, err } - result := c.client.client.Put().AbsPath(append(c.makeURLSegments(accessor.GetName()), "status")...).Body(outBytes).Do() + result := c.client.client. + Put(). + AbsPath(append(c.makeURLSegments(accessor.GetName()), "status")...). + Body(outBytes). + SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). + Do() if err := result.Error(); err != nil { return nil, err } @@ -174,7 +189,11 @@ func (c *dynamicResourceClient) Delete(name string, opts *metav1.DeleteOptions, return err } - result := c.client.client.Delete().AbsPath(append(c.makeURLSegments(name), subresources...)...).Body(deleteOptionsByte).Do() + result := c.client.client. + Delete(). + AbsPath(append(c.makeURLSegments(name), subresources...)...). + Body(deleteOptionsByte). + Do() return result.Error() } @@ -187,7 +206,12 @@ func (c *dynamicResourceClient) DeleteCollection(opts *metav1.DeleteOptions, lis return err } - result := c.client.client.Delete().AbsPath(c.makeURLSegments("")...).Body(deleteOptionsByte).SpecificallyVersionedParams(&listOptions, dynamicParameterCodec, versionV1).Do() + result := c.client.client. + Delete(). + AbsPath(c.makeURLSegments("")...). + Body(deleteOptionsByte). + SpecificallyVersionedParams(&listOptions, dynamicParameterCodec, versionV1). + Do() return result.Error() } @@ -259,8 +283,13 @@ func (c *dynamicResourceClient) Watch(opts metav1.ListOptions) (watch.Interface, WatchWithSpecificDecoders(wrappedDecoderFn, unstructured.UnstructuredJSONScheme) } -func (c *dynamicResourceClient) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*unstructured.Unstructured, error) { - result := c.client.client.Patch(pt).AbsPath(append(c.makeURLSegments(name), subresources...)...).Body(data).Do() +func (c *dynamicResourceClient) Patch(name string, pt types.PatchType, data []byte, opts metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) { + result := c.client.client. + Patch(pt). + AbsPath(append(c.makeURLSegments(name), subresources...)...). + Body(data). + SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). + Do() if err := result.Error(); err != nil { return nil, err }