mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Pass typed options to dynamic client
This commit is contained in:
		@@ -460,7 +460,7 @@ func gcListWatcher(client *dynamic.Client, resource schema.GroupVersionResource)
 | 
			
		||||
			apiResource := metav1.APIResource{Name: resource.Resource}
 | 
			
		||||
			return client.ParameterCodec(dynamic.VersionedParameterEncoderWithV1Fallback).
 | 
			
		||||
				Resource(&apiResource, metav1.NamespaceAll).
 | 
			
		||||
				List(&options)
 | 
			
		||||
				List(options)
 | 
			
		||||
		},
 | 
			
		||||
		WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
 | 
			
		||||
			// APIResource.Kind is not used by the dynamic client, so
 | 
			
		||||
@@ -470,7 +470,7 @@ func gcListWatcher(client *dynamic.Client, resource schema.GroupVersionResource)
 | 
			
		||||
			apiResource := metav1.APIResource{Name: resource.Resource}
 | 
			
		||||
			return client.ParameterCodec(dynamic.VersionedParameterEncoderWithV1Fallback).
 | 
			
		||||
				Resource(&apiResource, metav1.NamespaceAll).
 | 
			
		||||
				Watch(&options)
 | 
			
		||||
				Watch(options)
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -341,7 +341,7 @@ func (d *namespacedResourcesDeleter) deleteCollection(
 | 
			
		||||
	// resource deletions generically.  it will ensure all resources in the namespace are purged prior to releasing
 | 
			
		||||
	// namespace itself.
 | 
			
		||||
	orphanDependents := false
 | 
			
		||||
	err := dynamicClient.Resource(&apiResource, namespace).DeleteCollection(&metav1.DeleteOptions{OrphanDependents: &orphanDependents}, &metav1.ListOptions{})
 | 
			
		||||
	err := dynamicClient.Resource(&apiResource, namespace).DeleteCollection(&metav1.DeleteOptions{OrphanDependents: &orphanDependents}, metav1.ListOptions{})
 | 
			
		||||
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		return true, nil
 | 
			
		||||
@@ -379,7 +379,7 @@ func (d *namespacedResourcesDeleter) listCollection(
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	apiResource := metav1.APIResource{Name: gvr.Resource, Namespaced: true}
 | 
			
		||||
	obj, err := dynamicClient.Resource(&apiResource, namespace).List(&metav1.ListOptions{})
 | 
			
		||||
	obj, err := dynamicClient.Resource(&apiResource, namespace).List(metav1.ListOptions{})
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		unstructuredList, ok := obj.(*unstructured.UnstructuredList)
 | 
			
		||||
		if !ok {
 | 
			
		||||
 
 | 
			
		||||
@@ -112,7 +112,7 @@ type ResourceClient struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// List returns a list of objects for this resource.
 | 
			
		||||
func (rc *ResourceClient) List(opts runtime.Object) (runtime.Object, error) {
 | 
			
		||||
func (rc *ResourceClient) List(opts metav1.ListOptions) (runtime.Object, error) {
 | 
			
		||||
	parameterEncoder := rc.parameterCodec
 | 
			
		||||
	if parameterEncoder == nil {
 | 
			
		||||
		parameterEncoder = defaultParameterEncoder
 | 
			
		||||
@@ -120,7 +120,7 @@ func (rc *ResourceClient) List(opts runtime.Object) (runtime.Object, error) {
 | 
			
		||||
	return rc.cl.Get().
 | 
			
		||||
		NamespaceIfScoped(rc.ns, rc.resource.Namespaced).
 | 
			
		||||
		Resource(rc.resource.Name).
 | 
			
		||||
		VersionedParams(opts, parameterEncoder).
 | 
			
		||||
		VersionedParams(&opts, parameterEncoder).
 | 
			
		||||
		Do().
 | 
			
		||||
		Get()
 | 
			
		||||
}
 | 
			
		||||
@@ -149,7 +149,7 @@ func (rc *ResourceClient) Delete(name string, opts *metav1.DeleteOptions) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DeleteCollection deletes a collection of objects.
 | 
			
		||||
func (rc *ResourceClient) DeleteCollection(deleteOptions *metav1.DeleteOptions, listOptions runtime.Object) error {
 | 
			
		||||
func (rc *ResourceClient) DeleteCollection(deleteOptions *metav1.DeleteOptions, listOptions metav1.ListOptions) error {
 | 
			
		||||
	parameterEncoder := rc.parameterCodec
 | 
			
		||||
	if parameterEncoder == nil {
 | 
			
		||||
		parameterEncoder = defaultParameterEncoder
 | 
			
		||||
@@ -157,7 +157,7 @@ func (rc *ResourceClient) DeleteCollection(deleteOptions *metav1.DeleteOptions,
 | 
			
		||||
	return rc.cl.Delete().
 | 
			
		||||
		NamespaceIfScoped(rc.ns, rc.resource.Namespaced).
 | 
			
		||||
		Resource(rc.resource.Name).
 | 
			
		||||
		VersionedParams(listOptions, parameterEncoder).
 | 
			
		||||
		VersionedParams(&listOptions, parameterEncoder).
 | 
			
		||||
		Body(deleteOptions).
 | 
			
		||||
		Do().
 | 
			
		||||
		Error()
 | 
			
		||||
@@ -192,7 +192,7 @@ func (rc *ResourceClient) Update(obj *unstructured.Unstructured) (*unstructured.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Watch returns a watch.Interface that watches the resource.
 | 
			
		||||
func (rc *ResourceClient) Watch(opts runtime.Object) (watch.Interface, error) {
 | 
			
		||||
func (rc *ResourceClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
 | 
			
		||||
	parameterEncoder := rc.parameterCodec
 | 
			
		||||
	if parameterEncoder == nil {
 | 
			
		||||
		parameterEncoder = defaultParameterEncoder
 | 
			
		||||
@@ -201,7 +201,7 @@ func (rc *ResourceClient) Watch(opts runtime.Object) (watch.Interface, error) {
 | 
			
		||||
		Prefix("watch").
 | 
			
		||||
		NamespaceIfScoped(rc.ns, rc.resource.Namespaced).
 | 
			
		||||
		Resource(rc.resource.Name).
 | 
			
		||||
		VersionedParams(opts, parameterEncoder).
 | 
			
		||||
		VersionedParams(&opts, parameterEncoder).
 | 
			
		||||
		Watch()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -136,7 +136,7 @@ func TestList(t *testing.T) {
 | 
			
		||||
		}
 | 
			
		||||
		defer srv.Close()
 | 
			
		||||
 | 
			
		||||
		got, err := cl.Resource(resource, tc.namespace).List(&metav1.ListOptions{})
 | 
			
		||||
		got, err := cl.Resource(resource, tc.namespace).List(metav1.ListOptions{})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Errorf("unexpected error when listing %q: %v", tc.name, err)
 | 
			
		||||
			continue
 | 
			
		||||
@@ -293,7 +293,7 @@ func TestDeleteCollection(t *testing.T) {
 | 
			
		||||
		}
 | 
			
		||||
		defer srv.Close()
 | 
			
		||||
 | 
			
		||||
		err = cl.Resource(resource, tc.namespace).DeleteCollection(nil, &metav1.ListOptions{})
 | 
			
		||||
		err = cl.Resource(resource, tc.namespace).DeleteCollection(nil, metav1.ListOptions{})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Errorf("unexpected error when deleting collection %q: %v", tc.name, err)
 | 
			
		||||
			continue
 | 
			
		||||
@@ -469,7 +469,7 @@ func TestWatch(t *testing.T) {
 | 
			
		||||
		}
 | 
			
		||||
		defer srv.Close()
 | 
			
		||||
 | 
			
		||||
		watcher, err := cl.Resource(resource, tc.namespace).Watch(&metav1.ListOptions{})
 | 
			
		||||
		watcher, err := cl.Resource(resource, tc.namespace).Watch(metav1.ListOptions{})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Errorf("unexpected error when watching %q: %v", tc.name, err)
 | 
			
		||||
			continue
 | 
			
		||||
 
 | 
			
		||||
@@ -363,7 +363,7 @@ func SkipIfMissingResource(clientPool dynamic.ClientPool, gvr schema.GroupVersio
 | 
			
		||||
		Failf("Unexpected error getting dynamic client for %v: %v", gvr.GroupVersion(), err)
 | 
			
		||||
	}
 | 
			
		||||
	apiResource := metav1.APIResource{Name: gvr.Resource, Namespaced: true}
 | 
			
		||||
	_, err = dynamicClient.Resource(&apiResource, namespace).List(&metav1.ListOptions{})
 | 
			
		||||
	_, err = dynamicClient.Resource(&apiResource, namespace).List(metav1.ListOptions{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// not all resources support list, so we ignore those
 | 
			
		||||
		if apierrs.IsMethodNotSupported(err) || apierrs.IsNotFound(err) || apierrs.IsForbidden(err) {
 | 
			
		||||
@@ -1080,7 +1080,7 @@ func hasRemainingContent(c clientset.Interface, clientPool dynamic.ClientPool, n
 | 
			
		||||
			Logf("namespace: %s, resource: %s, ignored listing per whitelist", namespace, apiResource.Name)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		obj, err := dynamicClient.Resource(&apiResource, namespace).List(&metav1.ListOptions{})
 | 
			
		||||
		obj, err := dynamicClient.Resource(&apiResource, namespace).List(metav1.ListOptions{})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			// not all resources support list, so we ignore those
 | 
			
		||||
			if apierrs.IsMethodNotSupported(err) || apierrs.IsNotFound(err) || apierrs.IsForbidden(err) {
 | 
			
		||||
 
 | 
			
		||||
@@ -93,7 +93,7 @@ func TestDynamicClient(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// check dynamic list
 | 
			
		||||
	obj, err := dynamicClient.Resource(&resource, ns.Name).List(&metav1.ListOptions{})
 | 
			
		||||
	obj, err := dynamicClient.Resource(&resource, ns.Name).List(metav1.ListOptions{})
 | 
			
		||||
	unstructuredList, ok := obj.(*unstructured.UnstructuredList)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		t.Fatalf("expected *unstructured.UnstructuredList, got %#v", obj)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user