dry-run: Update DynamicClient to pass Create/Update options

Kubernetes-commit: 71970d6475f6570d933fa9f22be2ebc20a9ace6f
This commit is contained in:
Antoine Pelisse 2018-08-01 10:35:43 -07:00 committed by Kubernetes Publisher
parent 453b064209
commit 29424b90cb
5 changed files with 53 additions and 24 deletions

View File

@ -107,11 +107,11 @@ type oldResourceShimType struct {
} }
func (s oldResourceShimType) Create(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { 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) { 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 { 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) { 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...)
} }

View File

@ -404,7 +404,7 @@ func TestCreate(t *testing.T) {
} }
defer srv.Close() 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 { if err != nil {
t.Errorf("unexpected error when creating %q: %v", tc.name, err) t.Errorf("unexpected error when creating %q: %v", tc.name, err)
continue continue
@ -481,7 +481,7 @@ func TestUpdate(t *testing.T) {
} }
defer srv.Close() 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 { if err != nil {
t.Errorf("unexpected error when updating %q: %v", tc.name, err) t.Errorf("unexpected error when updating %q: %v", tc.name, err)
continue continue
@ -638,7 +638,7 @@ func TestPatch(t *testing.T) {
} }
defer srv.Close() 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 { if err != nil {
t.Errorf("unexpected error when patching %q: %v", tc.name, err) t.Errorf("unexpected error when patching %q: %v", tc.name, err)
continue continue

View File

@ -86,7 +86,7 @@ func (c *dynamicResourceClient) Namespace(ns string) dynamic.ResourceInterface {
return &ret 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 uncastRet runtime.Object
var err error var err error
switch { switch {
@ -132,7 +132,7 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, subresour
return ret, err 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 uncastRet runtime.Object
var err error var err error
switch { switch {
@ -168,7 +168,7 @@ func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, subresour
return ret, err 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 uncastRet runtime.Object
var err error var err error
switch { switch {
@ -331,7 +331,7 @@ func (c *dynamicResourceClient) Watch(opts metav1.ListOptions) (watch.Interface,
panic("math broke") 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 uncastRet runtime.Object
var err error var err error
switch { switch {

View File

@ -29,15 +29,15 @@ type Interface interface {
} }
type ResourceInterface interface { type ResourceInterface interface {
Create(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error) Create(obj *unstructured.Unstructured, options metav1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error)
Update(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error) Update(obj *unstructured.Unstructured, options metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error)
UpdateStatus(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) UpdateStatus(obj *unstructured.Unstructured, options metav1.UpdateOptions) (*unstructured.Unstructured, error)
Delete(name string, options *metav1.DeleteOptions, subresources ...string) error Delete(name string, options *metav1.DeleteOptions, subresources ...string) error
DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error
Get(name string, options metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error) Get(name string, options metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error)
List(opts metav1.ListOptions) (*unstructured.UnstructuredList, error) List(opts metav1.ListOptions) (*unstructured.UnstructuredList, error)
Watch(opts metav1.ListOptions) (watch.Interface, 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 { type NamespaceableResourceInterface interface {

View File

@ -82,7 +82,7 @@ func (c *dynamicResourceClient) Namespace(ns string) ResourceInterface {
return &ret 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) outBytes, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj)
if err != nil { if err != nil {
return nil, err return nil, err
@ -96,7 +96,12 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, subresour
name = accessor.GetName() 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 { if err := result.Error(); err != nil {
return nil, err return nil, err
} }
@ -112,7 +117,7 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, subresour
return uncastObj.(*unstructured.Unstructured), nil 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) accessor, err := meta.Accessor(obj)
if err != nil { if err != nil {
return nil, err return nil, err
@ -122,7 +127,12 @@ func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, subresour
return nil, err 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 { if err := result.Error(); err != nil {
return nil, err return nil, err
} }
@ -138,7 +148,7 @@ func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, subresour
return uncastObj.(*unstructured.Unstructured), nil 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) accessor, err := meta.Accessor(obj)
if err != nil { if err != nil {
return nil, err return nil, err
@ -149,7 +159,12 @@ func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured) (*u
return nil, err 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 { if err := result.Error(); err != nil {
return nil, err return nil, err
} }
@ -174,7 +189,11 @@ func (c *dynamicResourceClient) Delete(name string, opts *metav1.DeleteOptions,
return err 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() return result.Error()
} }
@ -187,7 +206,12 @@ func (c *dynamicResourceClient) DeleteCollection(opts *metav1.DeleteOptions, lis
return err 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() return result.Error()
} }
@ -259,8 +283,13 @@ func (c *dynamicResourceClient) Watch(opts metav1.ListOptions) (watch.Interface,
WatchWithSpecificDecoders(wrappedDecoderFn, unstructured.UnstructuredJSONScheme) WatchWithSpecificDecoders(wrappedDecoderFn, unstructured.UnstructuredJSONScheme)
} }
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) {
result := c.client.client.Patch(pt).AbsPath(append(c.makeURLSegments(name), subresources...)...).Body(data).Do() 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 { if err := result.Error(); err != nil {
return nil, err return nil, err
} }