Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make a simple dynamic client that is easy to use #62913

Merged
merged 1 commit into from Apr 25, 2018

Conversation

deads2k
Copy link
Contributor

@deads2k deads2k commented Apr 20, 2018

The dynamic client has annoyed me for the last time! The existing one takes arguments at odd levels, requires lots of information to instantiate, does some weird pool thing, and uses unusual types. This creates an interface like this:

type DynamicInterface interface {
	ClusterResource(resource schema.GroupVersionResource) DynamicResourceInterface
	NamespacedResource(resource schema.GroupVersionResource, namespace string) DynamicResourceInterface
}

type DynamicResourceInterface interface {
	Create(obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
	Update(obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
	UpdateStatus(obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
	Delete(name string, options *metav1.DeleteOptions) error
	DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error
	Get(name string, options metav1.GetOptions) (*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)
}

You create it from just a rest.Config, no mapper, no path resolving func, no trying to set up codecs ahead of time, no unnecessary pool. It just works.

I updated the namespace controller to use it and I updated the existing dynamic client to leverage it so that I get all their tests for "free".

@kubernetes/sig-api-machinery-pr-reviews
@liggitt @smarterclayton @bparees @sttts @ironcladlou I know each of us has struggled with the dynamic client in our time.
@lavalamp @caesarxuchao This is vastly simplifying. I'm eager to drop the old ClientPool. client-go will technically have another incompatible semver this release. I'm up for changing it in tree.

client-go developers: the new dynamic client is easier to use and the old is deprecated, you must switch.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 20, 2018
url = append(url, name)

// subresources only work on things with names
if len(c.subresource) > 0 {
Copy link
Member

@liggitt liggitt Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this case should error, not construct a different URL... if I try to construct a request to delete a pod binding subresource and accidentally use an empty name var, I should error, not delete all pods in the namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this case should error, not construct a different URL... if I try to construct a request to delete a pod binding subresource and accidentally use an empty name var, I should error, not delete all pods in the namespace.

Fixed in callers with proper error. If someone uses an empty name, I put a panic below as a backstop, but its a programmer error.

@timothysc timothysc removed their request for review April 20, 2018 16:45
@deads2k deads2k force-pushed the client-04-dynamic branch 2 times, most recently from 7ee2ac9 to d6cb8fb Compare April 20, 2018 16:56
@smarterclayton
Copy link
Contributor

+1 this is what dynamic client should look like to consumers.

@deads2k deads2k force-pushed the client-04-dynamic branch 2 times, most recently from 5d8535a to cfead73 Compare April 20, 2018 20:52
@deads2k
Copy link
Contributor Author

deads2k commented Apr 20, 2018

/retest

@deads2k
Copy link
Contributor Author

deads2k commented Apr 21, 2018

note to self, gc sets incorrect namespace for cluster scoped resources here:

owner, err = client.Resource(resource, item.identity.Namespace).Get(reference.Name, metav1.GetOptions{})

@deads2k deads2k force-pushed the client-04-dynamic branch 2 times, most recently from 14b417b to c1a3d7a Compare April 23, 2018 13:22
@deads2k
Copy link
Contributor Author

deads2k commented Apr 23, 2018

/retest

1 similar comment
@deads2k
Copy link
Contributor Author

deads2k commented Apr 23, 2018

/retest

@deads2k
Copy link
Contributor Author

deads2k commented Apr 23, 2018

/retest

kops seems to be having difficulty

@deads2k deads2k force-pushed the client-04-dynamic branch 2 times, most recently from d030237 to 3632037 Compare April 25, 2018 12:55
@deads2k
Copy link
Contributor Author

deads2k commented Apr 25, 2018

comments addressed.

@deads2k deads2k added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 25, 2018
@sttts
Copy link
Contributor

sttts commented Apr 25, 2018

lgtm

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 63137, 62913). If you want to cherry-pick this change to another branch, please follow the instructions here.

@lavalamp
Copy link
Member

/assign @yliaog @roycaihw

@lavalamp
Copy link
Member

/assign @yliaog

opts = &metav1.DeleteOptions{}
}
if opts == nil {
opts = &metav1.DeleteOptions{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicates?

@yliaog
Copy link
Contributor

yliaog commented Apr 26, 2018

if old ClientPool is dropped, what's the plan to enable sharing the REST clients?

@liggitt
Copy link
Member

liggitt commented Apr 26, 2018

if old ClientPool is dropped, what's the plan to enable sharing the REST clients?

the previous implementation required constructing a new client per group/version, which led to the need for a client pool.

with the implementation in this PR, a single restClient inside a single dynamic client can be used for requests to any Group/Version/Resource, so there's no need for a client pool.

liggitt added a commit to liggitt/kubernetes that referenced this pull request Apr 27, 2018
kubernetes#62913 switched from using a client pool, where each groupVersionResource got its own rest client, to a single client.

This increases the QPS to account for increased requests using a single rest client rate limiter.
k8s-github-robot pushed a commit that referenced this pull request Apr 27, 2018
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Bump QPS on namespace controller

#62913 switched from using a client pool, where each groupVersionResource got its own rest client, to a single client.

This increases the QPS to account for increased requests using a single rest client rate limiter.

Fixes #63240

```release-note
NONE
```

func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) {
if len(c.subresource) > 0 {
return nil, fmt.Errorf("create not supported for subresources")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We support subresource creation for pods/binding, pods/eviction and some deployments/rollback.

vikaschoudhary16 pushed a commit to vikaschoudhary16/kubernetes that referenced this pull request May 18, 2018
kubernetes#62913 switched from using a client pool, where each groupVersionResource got its own rest client, to a single client.

This increases the QPS to account for increased requests using a single rest client rate limiter.
@deads2k deads2k deleted the client-04-dynamic branch July 3, 2018 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants