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

[client-go] Fake Dynamic Client #45431

Merged

Conversation

DirectXMan12
Copy link
Contributor

This commit converts "k8s.io/client-go/dynamic".Client to an interface, and implements fake versions of both ClientPool and Client. This allows components which make uses of these clients to be tested in the same way that clientset-based components can be tested, using the standard testing.Fake machinery.

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 5, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels May 5, 2017
@DirectXMan12
Copy link
Contributor Author

encountered this while trying to write unit tests for the custom metrics adapter for Prometheus. I'm still in the progress of writing those tests and making sure this is sufficient, but I think it should be.

@krousey
Copy link
Contributor

krousey commented May 8, 2017

I don't think dynamic client should return an interface just to enable testing. I think the library that wants to test it's interaction with the dynamic client should assign the return value from New to an interface. That being said, I'm going to re-assign this to someone on the api machinery team.

@krousey krousey assigned lavalamp and unassigned krousey May 8, 2017
@DirectXMan12
Copy link
Contributor Author

I don't think dynamic client should return an interface just to enable testing.

That's what the "normal" clients do. I was under the impression that it was a pretty well-established pattern.

@krousey
Copy link
Contributor

krousey commented May 8, 2017

That's what the "normal" clients do. I was under the impression that it was a pretty well-established pattern.

That's true, it is a pattern. I have the opinion that it's a mistake, but not a completely terrible one. As it is the current pattern, it would fit it. I'm also not the reviewer (anymore).

@soltysh
Copy link
Contributor

soltysh commented May 11, 2017

I'd stick with the pattern we already have in place in the generated clientset, where there's a Interface and Client implements that, (see here). Just my $0.02.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 15, 2017
@DirectXMan12
Copy link
Contributor Author

I'd stick with the pattern we already have in place in the generated clientset, where there's a Interface and Client implements that, (see here). Just my $0.02.

I wanted to avoid a mass renaming, and wanted to follow the pattern established with ClientPool itself, which was already an interface.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 16, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 31, 2017
@DirectXMan12
Copy link
Contributor Author

ping @kubernetes/sig-api-machinery-pr-reviews when you get a chance

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 1, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 1, 2017
@sttts
Copy link
Contributor

sttts commented Jul 10, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 10, 2017
@sttts
Copy link
Contributor

sttts commented Jul 10, 2017

@smarterclayton approved?

@sttts
Copy link
Contributor

sttts commented Jul 10, 2017

/approve no-issue

1 similar comment
@deads2k
Copy link
Contributor

deads2k commented Jul 18, 2017

/approve no-issue

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 18, 2017
@deads2k
Copy link
Contributor

deads2k commented Jul 19, 2017

/retest

1 similar comment
@fejta
Copy link
Contributor

fejta commented Jul 20, 2017

/retest

@lavalamp lavalamp assigned caesarxuchao and unassigned lavalamp Jul 20, 2017
@DirectXMan12
Copy link
Contributor Author

This looks like it might actually be an issue with some code having gotten updated in the mean time. I'll rebase shortly.

This adds an interface form of dynamic.Client and
dynamic.ResourceClient, making those two follow the general client
conventions: `Interface` is an interface, and `Client` is the concrete
implementation.  `ClientPool` retains it's interface status.

This allows us to create a fake implemenation of dyanmic.Interface,
dynamic.ResourceInterface, and dynamic.ClientPool for testing.
@DirectXMan12
Copy link
Contributor Author

ok, this should fix the test issue -- someone updated the signature of DynamicClient in the mean time ;-).

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 21, 2017
@liggitt
Copy link
Member

liggitt commented Jul 21, 2017

/retest

@caesarxuchao
Copy link
Member

golint failures:

Errors from golint:
W0721 23:23:06.250] staging/src/k8s.io/client-go/dynamic/fake/client.go:36:6: type name will be used as fake.FakeClient by other packages, and that stutters; consider calling this Client
W0721 23:23:06.250] staging/src/k8s.io/client-go/dynamic/fake/client.go:68:6: type name will be used as fake.FakeResourceClient by other packages, and that stutters; consider calling this ResourceClient
W0721 23:23:06.250] staging/src/k8s.io/client-go/dynamic/fake/client_pool.go:30:6: type name will be used as fake.FakeClientPool by other packages, and that stutters; consider calling this ClientPool
W0721 23:23:06.250] staging/src/k8s.io/client-go/dynamic/fake/client_pool.go:34:1: comment on exported method FakeClientPool.ClientForGroupVersionResource should be of the form "ClientForGroupVersionResource ..."
W0721 23:23:06.250] 
W0721 23:23:06.251] Please review the above warnings. You can test via "golint" and commit the result.
W0721 23:23:06.251] If the above warnings do not make sense, you can exempt this package from golint
W0721 23:23:06.251] checking by adding it to hack/.golint_failures (if your reviewer is okay with it).

@DirectXMan12
Copy link
Contributor Author

wow, golint is supremely nitpicky

@DirectXMan12
Copy link
Contributor Author

I'm adding this to the golint_failures file, since it follows the pattern in other fake clients

This introduces fake implementations of dynamic.Client and
dynamic.ClientPool.  They function similarly to the fake generated
clientsets, since they're also based in testing.Fake.
@sttts
Copy link
Contributor

sttts commented Jul 25, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 25, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12, deads2k, sttts

Associated issue requirement bypassed by: deads2k, sttts

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 48224, 45431, 45946, 48775, 49396)

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-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet