mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-02 01:42:19 +00:00
make dynamic client slightly easier to use
Kubernetes-commit: 5ff923c7f931a34632df1f5a5400adbec33d49bf
This commit is contained in:
parent
e26238c324
commit
7757aaeb14
@ -32,8 +32,7 @@ import (
|
||||
)
|
||||
|
||||
type DynamicInterface interface {
|
||||
ClusterResource(resource schema.GroupVersionResource) DynamicResourceInterface
|
||||
NamespacedResource(resource schema.GroupVersionResource, namespace string) DynamicResourceInterface
|
||||
Resource(resource schema.GroupVersionResource) NamespaceableDynamicResourceInterface
|
||||
|
||||
// Deprecated, this isn't how we want to do it
|
||||
ClusterSubresource(resource schema.GroupVersionResource, subresource string) DynamicResourceInterface
|
||||
@ -53,6 +52,11 @@ type DynamicResourceInterface interface {
|
||||
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
|
||||
}
|
||||
@ -86,12 +90,9 @@ type dynamicResourceClient struct {
|
||||
subresource string
|
||||
}
|
||||
|
||||
func (c *dynamicClient) ClusterResource(resource schema.GroupVersionResource) DynamicResourceInterface {
|
||||
func (c *dynamicClient) Resource(resource schema.GroupVersionResource) NamespaceableDynamicResourceInterface {
|
||||
return &dynamicResourceClient{client: c, resource: resource}
|
||||
}
|
||||
func (c *dynamicClient) NamespacedResource(resource schema.GroupVersionResource, namespace string) DynamicResourceInterface {
|
||||
return &dynamicResourceClient{client: c, resource: resource, namespace: namespace}
|
||||
}
|
||||
|
||||
func (c *dynamicClient) ClusterSubresource(resource schema.GroupVersionResource, subresource string) DynamicResourceInterface {
|
||||
return &dynamicResourceClient{client: c, resource: resource, subresource: subresource}
|
||||
@ -100,6 +101,12 @@ func (c *dynamicClient) NamespacedSubresource(resource schema.GroupVersionResour
|
||||
return &dynamicResourceClient{client: c, resource: resource, namespace: namespace, subresource: subresource}
|
||||
}
|
||||
|
||||
func (c *dynamicResourceClient) Namespace(ns string) DynamicResourceInterface {
|
||||
ret := *c
|
||||
ret.namespace = ns
|
||||
return &ret
|
||||
}
|
||||
|
||||
func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) {
|
||||
if len(c.subresource) > 0 {
|
||||
return nil, fmt.Errorf("create not supported for subresources")
|
||||
|
Loading…
Reference in New Issue
Block a user