diff --git a/deprecated-dynamic/client.go b/deprecated-dynamic/client.go index 46c7535a..0974fe64 100644 --- a/deprecated-dynamic/client.go +++ b/deprecated-dynamic/client.go @@ -66,7 +66,7 @@ type ResourceInterface interface { // and manipulate metadata of a Kubernetes API group, and implements Interface. type Client struct { version schema.GroupVersion - delegate dynamic.DynamicInterface + delegate dynamic.Interface } // NewClient returns a new client based on the passed in config. The @@ -97,35 +97,35 @@ func (c *Client) Resource(resource *metav1.APIResource, namespace string) Resour } // the old interfaces used the wrong type for lists. this fixes that -func oldResourceShim(in dynamic.DynamicResourceInterface, subresources []string) ResourceInterface { - return oldResourceShimType{DynamicResourceInterface: in, subresources: subresources} +func oldResourceShim(in dynamic.ResourceInterface, subresources []string) ResourceInterface { + return oldResourceShimType{ResourceInterface: in, subresources: subresources} } type oldResourceShimType struct { - dynamic.DynamicResourceInterface + dynamic.ResourceInterface subresources []string } func (s oldResourceShimType) Create(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { - return s.DynamicResourceInterface.Create(obj, s.subresources...) + return s.ResourceInterface.Create(obj, s.subresources...) } func (s oldResourceShimType) Update(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { - return s.DynamicResourceInterface.Update(obj, s.subresources...) + return s.ResourceInterface.Update(obj, s.subresources...) } func (s oldResourceShimType) Delete(name string, opts *metav1.DeleteOptions) error { - return s.DynamicResourceInterface.Delete(name, opts, s.subresources...) + return s.ResourceInterface.Delete(name, opts, s.subresources...) } func (s oldResourceShimType) Get(name string, opts metav1.GetOptions) (*unstructured.Unstructured, error) { - return s.DynamicResourceInterface.Get(name, opts, s.subresources...) + return s.ResourceInterface.Get(name, opts, s.subresources...) } func (s oldResourceShimType) List(opts metav1.ListOptions) (runtime.Object, error) { - return s.DynamicResourceInterface.List(opts) + return s.ResourceInterface.List(opts) } func (s oldResourceShimType) Patch(name string, pt types.PatchType, data []byte) (*unstructured.Unstructured, error) { - return s.DynamicResourceInterface.Patch(name, pt, data, s.subresources...) + return s.ResourceInterface.Patch(name, pt, data, s.subresources...) } diff --git a/dynamic/client_test.go b/dynamic/client_test.go index 3e116cb8..e8fe9386 100644 --- a/dynamic/client_test.go +++ b/dynamic/client_test.go @@ -58,7 +58,7 @@ func getObject(version, kind, name string) *unstructured.Unstructured { } } -func getClientServer(h func(http.ResponseWriter, *http.Request)) (DynamicInterface, *httptest.Server, error) { +func getClientServer(h func(http.ResponseWriter, *http.Request)) (Interface, *httptest.Server, error) { srv := httptest.NewServer(http.HandlerFunc(h)) cl, err := NewForConfig(&restclient.Config{ Host: srv.URL, diff --git a/dynamic/fake/simple.go b/dynamic/fake/simple.go index 20b7b3c2..a71cec50 100644 --- a/dynamic/fake/simple.go +++ b/dynamic/fake/simple.go @@ -70,13 +70,13 @@ type dynamicResourceClient struct { resource schema.GroupVersionResource } -var _ dynamic.DynamicInterface = &FakeDynamicClient{} +var _ dynamic.Interface = &FakeDynamicClient{} -func (c *FakeDynamicClient) Resource(resource schema.GroupVersionResource) dynamic.NamespaceableDynamicResourceInterface { +func (c *FakeDynamicClient) Resource(resource schema.GroupVersionResource) dynamic.NamespaceableResourceInterface { return &dynamicResourceClient{client: c, resource: resource} } -func (c *dynamicResourceClient) Namespace(ns string) dynamic.DynamicResourceInterface { +func (c *dynamicResourceClient) Namespace(ns string) dynamic.ResourceInterface { ret := *c ret.namespace = ns return &ret diff --git a/dynamic/interface.go b/dynamic/interface.go index 4503af6b..3f364f87 100644 --- a/dynamic/interface.go +++ b/dynamic/interface.go @@ -17,9 +17,34 @@ limitations under the License. package dynamic import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" ) +type Interface interface { + Resource(resource schema.GroupVersionResource) NamespaceableResourceInterface +} + +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) + 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) +} + +type NamespaceableResourceInterface interface { + Namespace(string) ResourceInterface + ResourceInterface +} + // APIPathResolverFunc knows how to convert a groupVersion to its API path. The Kind field is optional. // TODO find a better place to move this for existing callers type APIPathResolverFunc func(kind schema.GroupVersionKind) string diff --git a/dynamic/simple.go b/dynamic/simple.go index e87d99d7..88e9cc2b 100644 --- a/dynamic/simple.go +++ b/dynamic/simple.go @@ -30,34 +30,13 @@ import ( "k8s.io/client-go/rest" ) -type DynamicInterface interface { - Resource(resource schema.GroupVersionResource) NamespaceableDynamicResourceInterface -} - -type DynamicResourceInterface 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) - 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) -} - -type NamespaceableDynamicResourceInterface interface { - Namespace(string) DynamicResourceInterface - DynamicResourceInterface -} - type dynamicClient struct { client *rest.RESTClient } -var _ DynamicInterface = &dynamicClient{} +var _ Interface = &dynamicClient{} -func NewForConfig(inConfig *rest.Config) (DynamicInterface, error) { +func NewForConfig(inConfig *rest.Config) (Interface, error) { config := rest.CopyConfig(inConfig) // for serializing the options config.GroupVersion = &schema.GroupVersion{} @@ -83,11 +62,11 @@ type dynamicResourceClient struct { resource schema.GroupVersionResource } -func (c *dynamicClient) Resource(resource schema.GroupVersionResource) NamespaceableDynamicResourceInterface { +func (c *dynamicClient) Resource(resource schema.GroupVersionResource) NamespaceableResourceInterface { return &dynamicResourceClient{client: c, resource: resource} } -func (c *dynamicResourceClient) Namespace(ns string) DynamicResourceInterface { +func (c *dynamicResourceClient) Namespace(ns string) ResourceInterface { ret := *c ret.namespace = ns return &ret @@ -161,6 +140,10 @@ func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured) (*u } result := c.client.client.Put().AbsPath(append(c.makeURLSegments(accessor.GetName()), "status")...).Body(outBytes).Do() + if err := result.Error(); err != nil { + return nil, err + } + retBytes, err := result.Raw() if err != nil { return nil, err