From fd044d152ee13a6cb812e4c3e7504ee8e24b5b8c Mon Sep 17 00:00:00 2001 From: David Eads Date: Wed, 9 May 2018 12:58:12 -0400 Subject: [PATCH] fix dynamic client name --- .../app/util/apiclient/clientbacked_dryrun.go | 2 +- .../garbagecollector/garbagecollector.go | 4 +-- .../garbagecollector/graph_builder.go | 4 +-- .../deletion/namespaced_resources_deleter.go | 4 +-- .../namespace/namespace_controller.go | 2 +- pkg/kubectl/BUILD | 1 - pkg/kubectl/cmd/apply.go | 8 ++--- pkg/kubectl/cmd/create/BUILD | 2 +- pkg/kubectl/cmd/create/create.go | 2 +- pkg/kubectl/cmd/create/create_test.go | 2 +- pkg/kubectl/cmd/expose.go | 2 +- pkg/kubectl/cmd/get/BUILD | 2 +- pkg/kubectl/cmd/get/get_test.go | 2 +- pkg/kubectl/cmd/run.go | 2 +- pkg/kubectl/cmd/testing/fake.go | 2 +- pkg/kubectl/cmd/util/factory.go | 2 +- pkg/kubectl/cmd/util/factory_client_access.go | 2 +- pkg/kubectl/genericclioptions/resource/BUILD | 2 ++ .../resource/scheme.go | 0 pkg/printers/internalversion/describe.go | 4 +-- .../test/integration/basic_test.go | 6 ++-- .../test/integration/registration_test.go | 4 +-- .../test/integration/testserver/resources.go | 6 ++-- .../test/integration/testserver/start.go | 2 +- .../client-go/deprecated-dynamic/client.go | 20 +++++------ .../k8s.io/client-go/dynamic/client_test.go | 2 +- .../k8s.io/client-go/dynamic/fake/simple.go | 6 ++-- .../src/k8s.io/client-go/dynamic/interface.go | 25 ++++++++++++++ .../src/k8s.io/client-go/dynamic/simple.go | 33 +++++-------------- test/e2e/apimachinery/crd_watch.go | 8 ++--- test/e2e/apimachinery/webhook.go | 4 +-- test/e2e/framework/crd_util.go | 2 +- test/e2e/framework/framework.go | 2 +- test/e2e/framework/util.go | 6 ++-- .../garbage_collector_test.go | 6 ++-- 35 files changed, 96 insertions(+), 87 deletions(-) rename pkg/kubectl/{ => genericclioptions}/resource/scheme.go (100%) diff --git a/cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go b/cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go index 73bbde66efb..34b20dc38d9 100644 --- a/cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go +++ b/cmd/kubeadm/app/util/apiclient/clientbacked_dryrun.go @@ -33,7 +33,7 @@ import ( // ClientBackedDryRunGetter implements the DryRunGetter interface for use in NewDryRunClient() and proxies all GET and LIST requests to the backing API server reachable via rest.Config type ClientBackedDryRunGetter struct { client clientset.Interface - dynamicClient dynamic.DynamicInterface + dynamicClient dynamic.Interface } // InitDryRunGetter should implement the DryRunGetter interface diff --git a/pkg/controller/garbagecollector/garbagecollector.go b/pkg/controller/garbagecollector/garbagecollector.go index 4d05dee56cf..7f93386a86d 100644 --- a/pkg/controller/garbagecollector/garbagecollector.go +++ b/pkg/controller/garbagecollector/garbagecollector.go @@ -60,7 +60,7 @@ const ResourceResyncTime time.Duration = 0 // up to date as the notification is sent. type GarbageCollector struct { restMapper resettableRESTMapper - dynamicClient dynamic.DynamicInterface + dynamicClient dynamic.Interface // garbage collector attempts to delete the items in attemptToDelete queue when the time is ripe. attemptToDelete workqueue.RateLimitingInterface // garbage collector attempts to orphan the dependents of the items in the attemptToOrphan queue, then deletes the items. @@ -74,7 +74,7 @@ type GarbageCollector struct { } func NewGarbageCollector( - dynamicClient dynamic.DynamicInterface, + dynamicClient dynamic.Interface, mapper resettableRESTMapper, deletableResources map[schema.GroupVersionResource]struct{}, ignoredResources map[schema.GroupResource]struct{}, diff --git a/pkg/controller/garbagecollector/graph_builder.go b/pkg/controller/garbagecollector/graph_builder.go index 407af134504..4e18b1c2678 100644 --- a/pkg/controller/garbagecollector/graph_builder.go +++ b/pkg/controller/garbagecollector/graph_builder.go @@ -91,7 +91,7 @@ type GraphBuilder struct { // it is protected by monitorLock. running bool - dynamicClient dynamic.DynamicInterface + dynamicClient dynamic.Interface // monitors are the producer of the graphChanges queue, graphBuilder alters // the in-memory graph according to the changes. graphChanges workqueue.RateLimitingInterface @@ -125,7 +125,7 @@ func (m *monitor) Run() { type monitors map[schema.GroupVersionResource]*monitor -func listWatcher(client dynamic.DynamicInterface, resource schema.GroupVersionResource) *cache.ListWatch { +func listWatcher(client dynamic.Interface, resource schema.GroupVersionResource) *cache.ListWatch { return &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { // We want to list this resource in all namespaces if it's namespace scoped, so not passing namespace is ok. diff --git a/pkg/controller/namespace/deletion/namespaced_resources_deleter.go b/pkg/controller/namespace/deletion/namespaced_resources_deleter.go index f92cf81f0d6..62e09392f4a 100644 --- a/pkg/controller/namespace/deletion/namespaced_resources_deleter.go +++ b/pkg/controller/namespace/deletion/namespaced_resources_deleter.go @@ -43,7 +43,7 @@ type NamespacedResourcesDeleterInterface interface { } func NewNamespacedResourcesDeleter(nsClient v1clientset.NamespaceInterface, - dynamicClient dynamic.DynamicInterface, podsGetter v1clientset.PodsGetter, + dynamicClient dynamic.Interface, podsGetter v1clientset.PodsGetter, discoverResourcesFn func() ([]*metav1.APIResourceList, error), finalizerToken v1.FinalizerName, deleteNamespaceWhenDone bool) NamespacedResourcesDeleterInterface { d := &namespacedResourcesDeleter{ @@ -68,7 +68,7 @@ type namespacedResourcesDeleter struct { // Client to manipulate the namespace. nsClient v1clientset.NamespaceInterface // Dynamic client to list and delete all namespaced resources. - dynamicClient dynamic.DynamicInterface + dynamicClient dynamic.Interface // Interface to get PodInterface. podsGetter v1clientset.PodsGetter // Cache of what operations are not supported on each group version resource. diff --git a/pkg/controller/namespace/namespace_controller.go b/pkg/controller/namespace/namespace_controller.go index 3784b7b571c..3164d290b93 100644 --- a/pkg/controller/namespace/namespace_controller.go +++ b/pkg/controller/namespace/namespace_controller.go @@ -63,7 +63,7 @@ type NamespaceController struct { // NewNamespaceController creates a new NamespaceController func NewNamespaceController( kubeClient clientset.Interface, - dynamicClient dynamic.DynamicInterface, + dynamicClient dynamic.Interface, discoverResourcesFn func() ([]*metav1.APIResourceList, error), namespaceInformer coreinformers.NamespaceInformer, resyncPeriod time.Duration, diff --git a/pkg/kubectl/BUILD b/pkg/kubectl/BUILD index a5d68729099..3ce1e6d876d 100644 --- a/pkg/kubectl/BUILD +++ b/pkg/kubectl/BUILD @@ -206,7 +206,6 @@ filegroup( "//pkg/kubectl/metricsutil:all-srcs", "//pkg/kubectl/plugins:all-srcs", "//pkg/kubectl/proxy:all-srcs", - "//pkg/kubectl/resource:all-srcs", "//pkg/kubectl/scheme:all-srcs", "//pkg/kubectl/util:all-srcs", "//pkg/kubectl/validation:all-srcs", diff --git a/pkg/kubectl/cmd/apply.go b/pkg/kubectl/cmd/apply.go index fcdaaf09ab1..a28a8ae44c5 100644 --- a/pkg/kubectl/cmd/apply.go +++ b/pkg/kubectl/cmd/apply.go @@ -82,7 +82,7 @@ type ApplyOptions struct { Builder *resource.Builder Mapper meta.RESTMapper Scaler scaleclient.ScalesGetter - DynamicClient dynamic.DynamicInterface + DynamicClient dynamic.Interface ClientSetFunc func() (internalclientset.Interface, error) OpenAPISchema openapi.Resources @@ -580,7 +580,7 @@ func getRESTMappings(mapper meta.RESTMapper, pruneResources *[]pruneResource) (n type pruner struct { mapper meta.RESTMapper - dynamicClient dynamic.DynamicInterface + dynamicClient dynamic.Interface clientsetFunc func() (internalclientset.Interface, error) visitedUids sets.String @@ -649,7 +649,7 @@ func (p *pruner) delete(namespace, name string, mapping *meta.RESTMapping, scale return runDelete(namespace, name, mapping, p.dynamicClient, p.cascade, p.gracePeriod, p.clientsetFunc, scaleClient) } -func runDelete(namespace, name string, mapping *meta.RESTMapping, c dynamic.DynamicInterface, cascade bool, gracePeriod int, clientsetFunc func() (internalclientset.Interface, error), scaleClient scaleclient.ScalesGetter) error { +func runDelete(namespace, name string, mapping *meta.RESTMapping, c dynamic.Interface, cascade bool, gracePeriod int, clientsetFunc func() (internalclientset.Interface, error), scaleClient scaleclient.ScalesGetter) error { if !cascade { return c.Resource(mapping.Resource).Namespace(namespace).Delete(name, nil) } @@ -681,7 +681,7 @@ func (p *patcher) delete(namespace, name string) error { type patcher struct { mapping *meta.RESTMapping helper *resource.Helper - dynamicClient dynamic.DynamicInterface + dynamicClient dynamic.Interface clientsetFunc func() (internalclientset.Interface, error) overwrite bool diff --git a/pkg/kubectl/cmd/create/BUILD b/pkg/kubectl/cmd/create/BUILD index b7c813e772c..131dc94981d 100644 --- a/pkg/kubectl/cmd/create/BUILD +++ b/pkg/kubectl/cmd/create/BUILD @@ -82,7 +82,7 @@ go_test( "//pkg/kubectl/cmd/testing:go_default_library", "//pkg/kubectl/cmd/util:go_default_library", "//pkg/kubectl/genericclioptions:go_default_library", - "//pkg/kubectl/resource:go_default_library", + "//pkg/kubectl/genericclioptions/resource:go_default_library", "//pkg/kubectl/scheme:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library", "//vendor/k8s.io/api/batch/v1:go_default_library", diff --git a/pkg/kubectl/cmd/create/create.go b/pkg/kubectl/cmd/create/create.go index cee2299f4ee..6105c9f4b1b 100644 --- a/pkg/kubectl/cmd/create/create.go +++ b/pkg/kubectl/cmd/create/create.go @@ -348,7 +348,7 @@ type CreateSubcommandOptions struct { EnforceNamespace bool Mapper meta.RESTMapper - DynamicClient dynamic.DynamicInterface + DynamicClient dynamic.Interface PrintObj func(obj kruntime.Object) error diff --git a/pkg/kubectl/cmd/create/create_test.go b/pkg/kubectl/cmd/create/create_test.go index e97fd06724c..607a3bfbd3f 100644 --- a/pkg/kubectl/cmd/create/create_test.go +++ b/pkg/kubectl/cmd/create/create_test.go @@ -29,7 +29,7 @@ import ( cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" "k8s.io/kubernetes/pkg/kubectl/genericclioptions" - "k8s.io/kubernetes/pkg/kubectl/resource" + "k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource" "k8s.io/kubernetes/pkg/kubectl/scheme" ) diff --git a/pkg/kubectl/cmd/expose.go b/pkg/kubectl/cmd/expose.go index 18ae1589fbf..86444896211 100644 --- a/pkg/kubectl/cmd/expose.go +++ b/pkg/kubectl/cmd/expose.go @@ -100,7 +100,7 @@ type ExposeServiceOptions struct { Namespace string Mapper meta.RESTMapper - DynamicClient dynamic.DynamicInterface + DynamicClient dynamic.Interface Builder *resource.Builder Recorder genericclioptions.Recorder diff --git a/pkg/kubectl/cmd/get/BUILD b/pkg/kubectl/cmd/get/BUILD index a22ded79dc4..db904110bdc 100644 --- a/pkg/kubectl/cmd/get/BUILD +++ b/pkg/kubectl/cmd/get/BUILD @@ -75,7 +75,7 @@ go_test( "//pkg/kubectl/cmd/util/openapi:go_default_library", "//pkg/kubectl/cmd/util/openapi/testing:go_default_library", "//pkg/kubectl/genericclioptions:go_default_library", - "//pkg/kubectl/resource:go_default_library", + "//pkg/kubectl/genericclioptions/resource:go_default_library", "//pkg/kubectl/scheme:go_default_library", "//pkg/printers:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/kubectl/cmd/get/get_test.go b/pkg/kubectl/cmd/get/get_test.go index 711e144cfdc..e094463cdd9 100644 --- a/pkg/kubectl/cmd/get/get_test.go +++ b/pkg/kubectl/cmd/get/get_test.go @@ -48,7 +48,7 @@ import ( "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi" openapitesting "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing" "k8s.io/kubernetes/pkg/kubectl/genericclioptions" - "k8s.io/kubernetes/pkg/kubectl/resource" + "k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource" "k8s.io/kubernetes/pkg/kubectl/scheme" ) diff --git a/pkg/kubectl/cmd/run.go b/pkg/kubectl/cmd/run.go index 8e512d6cadb..28c1b82b8a5 100644 --- a/pkg/kubectl/cmd/run.go +++ b/pkg/kubectl/cmd/run.go @@ -107,7 +107,7 @@ type RunOptions struct { PrintObj func(runtime.Object) error Recorder genericclioptions.Recorder - DynamicClient dynamic.DynamicInterface + DynamicClient dynamic.Interface ArgsLenAtDash int Attach bool diff --git a/pkg/kubectl/cmd/testing/fake.go b/pkg/kubectl/cmd/testing/fake.go index 9dc6b0b153d..b304228d919 100644 --- a/pkg/kubectl/cmd/testing/fake.go +++ b/pkg/kubectl/cmd/testing/fake.go @@ -398,7 +398,7 @@ func (f *TestFactory) ClientSet() (internalclientset.Interface, error) { return clientset, nil } -func (f *TestFactory) DynamicClient() (dynamic.DynamicInterface, error) { +func (f *TestFactory) DynamicClient() (dynamic.Interface, error) { if f.FakeDynamicClient != nil { return f.FakeDynamicClient, nil } diff --git a/pkg/kubectl/cmd/util/factory.go b/pkg/kubectl/cmd/util/factory.go index 19880c5fb92..96e7aa3f9f2 100644 --- a/pkg/kubectl/cmd/util/factory.go +++ b/pkg/kubectl/cmd/util/factory.go @@ -85,7 +85,7 @@ type ClientAccessFactory interface { ClientSet() (internalclientset.Interface, error) // DynamicClient returns a dynamic client ready for use - DynamicClient() (dynamic.DynamicInterface, error) + DynamicClient() (dynamic.Interface, error) // KubernetesClientSet gives you back an external clientset KubernetesClientSet() (*kubernetes.Clientset, error) diff --git a/pkg/kubectl/cmd/util/factory_client_access.go b/pkg/kubectl/cmd/util/factory_client_access.go index cc281568d88..86e587fb5a5 100644 --- a/pkg/kubectl/cmd/util/factory_client_access.go +++ b/pkg/kubectl/cmd/util/factory_client_access.go @@ -114,7 +114,7 @@ func (f *ring0Factory) ClientSet() (internalclientset.Interface, error) { return internalclientset.NewForConfig(clientConfig) } -func (f *ring0Factory) DynamicClient() (dynamic.DynamicInterface, error) { +func (f *ring0Factory) DynamicClient() (dynamic.Interface, error) { clientConfig, err := f.ClientConfig() if err != nil { return nil, err diff --git a/pkg/kubectl/genericclioptions/resource/BUILD b/pkg/kubectl/genericclioptions/resource/BUILD index 29e7119a146..e2fb1a89216 100644 --- a/pkg/kubectl/genericclioptions/resource/BUILD +++ b/pkg/kubectl/genericclioptions/resource/BUILD @@ -11,6 +11,7 @@ go_library( "interfaces.go", "mapper.go", "result.go", + "scheme.go", "selector.go", "visitor.go", ], @@ -36,6 +37,7 @@ go_library( "//vendor/k8s.io/apimachinery/pkg/util/yaml:go_default_library", "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", "//vendor/k8s.io/client-go/discovery:go_default_library", + "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library", "//vendor/k8s.io/client-go/restmapper:go_default_library", ], diff --git a/pkg/kubectl/resource/scheme.go b/pkg/kubectl/genericclioptions/resource/scheme.go similarity index 100% rename from pkg/kubectl/resource/scheme.go rename to pkg/kubectl/genericclioptions/resource/scheme.go diff --git a/pkg/printers/internalversion/describe.go b/pkg/printers/internalversion/describe.go index d73da869885..89bd48a606c 100644 --- a/pkg/printers/internalversion/describe.go +++ b/pkg/printers/internalversion/describe.go @@ -192,13 +192,13 @@ func DescriberFor(kind schema.GroupKind, clientConfig *rest.Config) (printers.De // GenericDescriberFor returns a generic describer for the specified mapping // that uses only information available from runtime.Unstructured -func GenericDescriberFor(mapping *meta.RESTMapping, dynamic dynamic.DynamicInterface, events coreclient.EventsGetter) printers.Describer { +func GenericDescriberFor(mapping *meta.RESTMapping, dynamic dynamic.Interface, events coreclient.EventsGetter) printers.Describer { return &genericDescriber{mapping, dynamic, events} } type genericDescriber struct { mapping *meta.RESTMapping - dynamic dynamic.DynamicInterface + dynamic dynamic.Interface events coreclient.EventsGetter } diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/basic_test.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/basic_test.go index 3b21ad339d1..9dfe68e444a 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/basic_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/basic_test.go @@ -79,7 +79,7 @@ func TestClusterScopedCRUD(t *testing.T) { testFieldSelector(t, ns, noxuDefinition, dynamicClient) } -func testSimpleCRUD(t *testing.T, ns string, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition, dynamicClient dynamic.DynamicInterface) { +func testSimpleCRUD(t *testing.T, ns string, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition, dynamicClient dynamic.Interface) { noxuResourceClient := NewNamespacedCustomResourceClient(ns, dynamicClient, noxuDefinition) initialList, err := noxuResourceClient.List(metav1.ListOptions{}) if err != nil { @@ -201,7 +201,7 @@ func testSimpleCRUD(t *testing.T, ns string, noxuDefinition *apiextensionsv1beta } } -func testFieldSelector(t *testing.T, ns string, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition, dynamicClient dynamic.DynamicInterface) { +func testFieldSelector(t *testing.T, ns string, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition, dynamicClient dynamic.Interface) { noxuResourceClient := NewNamespacedCustomResourceClient(ns, dynamicClient, noxuDefinition) initialList, err := noxuResourceClient.List(metav1.ListOptions{}) if err != nil { @@ -703,7 +703,7 @@ func TestCrossNamespaceListWatch(t *testing.T) { checkNamespacesWatchHelper(t, ns2, noxuNamespacesWatch2) } -func createInstanceWithNamespaceHelper(t *testing.T, ns string, name string, noxuNamespacedResourceClient dynamic.DynamicResourceInterface, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition) *unstructured.Unstructured { +func createInstanceWithNamespaceHelper(t *testing.T, ns string, name string, noxuNamespacedResourceClient dynamic.ResourceInterface, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition) *unstructured.Unstructured { createdInstance, err := instantiateCustomResource(t, testserver.NewNoxuInstance(ns, name), noxuNamespacedResourceClient, noxuDefinition) if err != nil { t.Fatalf("unable to create noxu Instance:%v", err) diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go index 82ce9edbcd3..7d0ab684fe9 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go @@ -41,7 +41,7 @@ import ( "k8s.io/client-go/dynamic" ) -func instantiateCustomResource(t *testing.T, instanceToCreate *unstructured.Unstructured, client dynamic.DynamicResourceInterface, definition *apiextensionsv1beta1.CustomResourceDefinition) (*unstructured.Unstructured, error) { +func instantiateCustomResource(t *testing.T, instanceToCreate *unstructured.Unstructured, client dynamic.ResourceInterface, definition *apiextensionsv1beta1.CustomResourceDefinition) (*unstructured.Unstructured, error) { createdInstance, err := client.Create(instanceToCreate) if err != nil { t.Logf("%#v", createdInstance) @@ -68,7 +68,7 @@ func instantiateCustomResource(t *testing.T, instanceToCreate *unstructured.Unst return createdInstance, nil } -func NewNamespacedCustomResourceClient(ns string, client dynamic.DynamicInterface, crd *apiextensionsv1beta1.CustomResourceDefinition) dynamic.DynamicResourceInterface { +func NewNamespacedCustomResourceClient(ns string, client dynamic.Interface, crd *apiextensionsv1beta1.CustomResourceDefinition) dynamic.ResourceInterface { gvr := schema.GroupVersionResource{Group: crd.Spec.Group, Version: crd.Spec.Version, Resource: crd.Spec.Names.Plural} if crd.Spec.Scope != apiextensionsv1beta1.ClusterScoped { diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go index 1f4a952b332..2502b9a9006 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go @@ -178,7 +178,7 @@ func CreateNewCustomResourceDefinitionWatchUnsafe(crd *apiextensionsv1beta1.Cust return err } -func CreateNewCustomResourceDefinition(crd *apiextensionsv1beta1.CustomResourceDefinition, apiExtensionsClient clientset.Interface, dynamicClientSet dynamic.DynamicInterface) error { +func CreateNewCustomResourceDefinition(crd *apiextensionsv1beta1.CustomResourceDefinition, apiExtensionsClient clientset.Interface, dynamicClientSet dynamic.Interface) error { err := CreateNewCustomResourceDefinitionWatchUnsafe(crd, apiExtensionsClient) if err != nil { return err @@ -209,14 +209,14 @@ func CreateNewCustomResourceDefinition(crd *apiextensionsv1beta1.CustomResourceD return nil } -func checkForWatchCachePrimed(crd *apiextensionsv1beta1.CustomResourceDefinition, dynamicClientSet dynamic.DynamicInterface) error { +func checkForWatchCachePrimed(crd *apiextensionsv1beta1.CustomResourceDefinition, dynamicClientSet dynamic.Interface) error { ns := "" if crd.Spec.Scope != apiextensionsv1beta1.ClusterScoped { ns = "aval" } gvr := schema.GroupVersionResource{Group: crd.Spec.Group, Version: crd.Spec.Version, Resource: crd.Spec.Names.Plural} - var resourceClient dynamic.DynamicResourceInterface + var resourceClient dynamic.ResourceInterface if crd.Spec.Scope != apiextensionsv1beta1.ClusterScoped { resourceClient = dynamicClientSet.Resource(gvr).Namespace(ns) } else { diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/start.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/start.go index cac4a9d066d..22b9fa2862a 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/start.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/start.go @@ -139,7 +139,7 @@ func StartDefaultServer() (chan struct{}, *rest.Config, error) { return StartServer(config) } -func StartDefaultServerWithClients() (chan struct{}, clientset.Interface, dynamic.DynamicInterface, error) { +func StartDefaultServerWithClients() (chan struct{}, clientset.Interface, dynamic.Interface, error) { stopCh, config, err := StartDefaultServer() if err != nil { return nil, nil, nil, err diff --git a/staging/src/k8s.io/client-go/deprecated-dynamic/client.go b/staging/src/k8s.io/client-go/deprecated-dynamic/client.go index 46c7535aab4..0974fe64dea 100644 --- a/staging/src/k8s.io/client-go/deprecated-dynamic/client.go +++ b/staging/src/k8s.io/client-go/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/staging/src/k8s.io/client-go/dynamic/client_test.go b/staging/src/k8s.io/client-go/dynamic/client_test.go index 3e116cb8d51..e8fe938676b 100644 --- a/staging/src/k8s.io/client-go/dynamic/client_test.go +++ b/staging/src/k8s.io/client-go/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/staging/src/k8s.io/client-go/dynamic/fake/simple.go b/staging/src/k8s.io/client-go/dynamic/fake/simple.go index 20b7b3c2877..a71cec50ea4 100644 --- a/staging/src/k8s.io/client-go/dynamic/fake/simple.go +++ b/staging/src/k8s.io/client-go/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/staging/src/k8s.io/client-go/dynamic/interface.go b/staging/src/k8s.io/client-go/dynamic/interface.go index 4503af6b543..3f364f872a7 100644 --- a/staging/src/k8s.io/client-go/dynamic/interface.go +++ b/staging/src/k8s.io/client-go/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/staging/src/k8s.io/client-go/dynamic/simple.go b/staging/src/k8s.io/client-go/dynamic/simple.go index e87d99d7a4d..88e9cc2b06b 100644 --- a/staging/src/k8s.io/client-go/dynamic/simple.go +++ b/staging/src/k8s.io/client-go/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 diff --git a/test/e2e/apimachinery/crd_watch.go b/test/e2e/apimachinery/crd_watch.go index 6c38a50ae85..a101f549256 100644 --- a/test/e2e/apimachinery/crd_watch.go +++ b/test/e2e/apimachinery/crd_watch.go @@ -115,7 +115,7 @@ var _ = SIGDescribe("CustomResourceDefinition Watch", func() { }) }) -func watchCRWithName(crdResourceClient dynamic.DynamicResourceInterface, name string) (watch.Interface, error) { +func watchCRWithName(crdResourceClient dynamic.ResourceInterface, name string) (watch.Interface, error) { return crdResourceClient.Watch( metav1.ListOptions{ FieldSelector: "metadata.name=" + name, @@ -124,7 +124,7 @@ func watchCRWithName(crdResourceClient dynamic.DynamicResourceInterface, name st ) } -func instantiateCustomResource(instanceToCreate *unstructured.Unstructured, client dynamic.DynamicResourceInterface, definition *apiextensionsv1beta1.CustomResourceDefinition) (*unstructured.Unstructured, error) { +func instantiateCustomResource(instanceToCreate *unstructured.Unstructured, client dynamic.ResourceInterface, definition *apiextensionsv1beta1.CustomResourceDefinition) (*unstructured.Unstructured, error) { createdInstance, err := client.Create(instanceToCreate) if err != nil { return nil, err @@ -150,11 +150,11 @@ func instantiateCustomResource(instanceToCreate *unstructured.Unstructured, clie return createdInstance, nil } -func deleteCustomResource(client dynamic.DynamicResourceInterface, name string) error { +func deleteCustomResource(client dynamic.ResourceInterface, name string) error { return client.Delete(name, &metav1.DeleteOptions{}) } -func newNamespacedCustomResourceClient(ns string, client dynamic.DynamicInterface, crd *apiextensionsv1beta1.CustomResourceDefinition) dynamic.DynamicResourceInterface { +func newNamespacedCustomResourceClient(ns string, client dynamic.Interface, crd *apiextensionsv1beta1.CustomResourceDefinition) dynamic.ResourceInterface { gvr := schema.GroupVersionResource{Group: crd.Spec.Group, Version: crd.Spec.Version, Resource: crd.Spec.Names.Plural} if crd.Spec.Scope != apiextensionsv1beta1.ClusterScoped { diff --git a/test/e2e/apimachinery/webhook.go b/test/e2e/apimachinery/webhook.go index 248f6fb5466..5dbda0239c3 100644 --- a/test/e2e/apimachinery/webhook.go +++ b/test/e2e/apimachinery/webhook.go @@ -1081,7 +1081,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c return func() { client.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Delete(configName, nil) } } -func testCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1.CustomResourceDefinition, customResourceClient dynamic.DynamicResourceInterface) { +func testCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1.CustomResourceDefinition, customResourceClient dynamic.ResourceInterface) { By("Creating a custom resource that should be denied by the webhook") crInstance := &unstructured.Unstructured{ Object: map[string]interface{}{ @@ -1104,7 +1104,7 @@ func testCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1 } } -func testMutatingCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1.CustomResourceDefinition, customResourceClient dynamic.DynamicResourceInterface) { +func testMutatingCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1.CustomResourceDefinition, customResourceClient dynamic.ResourceInterface) { By("Creating a custom resource that should be mutated by the webhook") cr := &unstructured.Unstructured{ Object: map[string]interface{}{ diff --git a/test/e2e/framework/crd_util.go b/test/e2e/framework/crd_util.go index 58cbdcc976f..4a4acc8cb71 100644 --- a/test/e2e/framework/crd_util.go +++ b/test/e2e/framework/crd_util.go @@ -38,7 +38,7 @@ type TestCrd struct { ApiVersion string ApiExtensionClient *crdclientset.Clientset Crd *apiextensionsv1beta1.CustomResourceDefinition - DynamicClient dynamic.DynamicResourceInterface + DynamicClient dynamic.ResourceInterface CleanUp CleanCrdFn } diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index dcf04ec2a8c..d9a23c53329 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -70,7 +70,7 @@ type Framework struct { InternalClientset *internalclientset.Clientset AggregatorClient *aggregatorclient.Clientset - DynamicClient dynamic.DynamicInterface + DynamicClient dynamic.Interface ScalesGetter scaleclient.ScalesGetter diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 4e4a9e74fd2..36d88ef2d21 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -506,7 +506,7 @@ func SkipUnlessServerVersionGTE(v *utilversion.Version, c discovery.ServerVersio } } -func SkipIfMissingResource(dynamicClient dynamic.DynamicInterface, gvr schema.GroupVersionResource, namespace string) { +func SkipIfMissingResource(dynamicClient dynamic.Interface, gvr schema.GroupVersionResource, namespace string) { resourceClient := dynamicClient.Resource(gvr).Namespace(namespace) _, err := resourceClient.List(metav1.ListOptions{}) if err != nil { @@ -1086,7 +1086,7 @@ func CheckTestingNSDeletedExcept(c clientset.Interface, skip string) error { // deleteNS deletes the provided namespace, waits for it to be completely deleted, and then checks // whether there are any pods remaining in a non-terminating state. -func deleteNS(c clientset.Interface, dynamicClient dynamic.DynamicInterface, namespace string, timeout time.Duration) error { +func deleteNS(c clientset.Interface, dynamicClient dynamic.Interface, namespace string, timeout time.Duration) error { startTime := time.Now() if err := c.CoreV1().Namespaces().Delete(namespace, nil); err != nil { return err @@ -1232,7 +1232,7 @@ func isDynamicDiscoveryError(err error) bool { } // hasRemainingContent checks if there is remaining content in the namespace via API discovery -func hasRemainingContent(c clientset.Interface, dynamicClient dynamic.DynamicInterface, namespace string) (bool, error) { +func hasRemainingContent(c clientset.Interface, dynamicClient dynamic.Interface, namespace string) (bool, error) { // some tests generate their own framework.Client rather than the default // TODO: ensure every test call has a configured dynamicClient if dynamicClient == nil { diff --git a/test/integration/garbagecollector/garbage_collector_test.go b/test/integration/garbagecollector/garbage_collector_test.go index 83fc2604865..b5dace145b1 100644 --- a/test/integration/garbagecollector/garbage_collector_test.go +++ b/test/integration/garbagecollector/garbage_collector_test.go @@ -168,9 +168,9 @@ func link(t *testing.T, owner, dependent metav1.Object) { func createRandomCustomResourceDefinition( t *testing.T, apiExtensionClient apiextensionsclientset.Interface, - dynamicClient dynamic.DynamicInterface, + dynamicClient dynamic.Interface, namespace string, -) (*apiextensionsv1beta1.CustomResourceDefinition, dynamic.DynamicResourceInterface) { +) (*apiextensionsv1beta1.CustomResourceDefinition, dynamic.ResourceInterface) { // Create a random custom resource definition and ensure it's available for // use. definition := apiextensionstestserver.NewRandomNameCustomResourceDefinition(apiextensionsv1beta1.NamespaceScoped) @@ -193,7 +193,7 @@ type testContext struct { gc *garbagecollector.GarbageCollector clientSet clientset.Interface apiExtensionClient apiextensionsclientset.Interface - dynamicClient dynamic.DynamicInterface + dynamicClient dynamic.Interface startGC func(workers int) // syncPeriod is how often the GC started with startGC will be resynced. syncPeriod time.Duration