-
Notifications
You must be signed in to change notification settings - Fork 491
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
Replace k8s client-go mocks with fakes #2375
Conversation
Huzzah! Any change that removes mock use in favor of fakes has my support and adoration :) We're a little heads down with preparations for 1.0, but I'll review this as soon as I get a minute. |
…ake package Signed-off-by: Brian Barnes <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -117,7 +114,7 @@ oIrPuyjOmscrC627wX3LGUHwPKtNArBT8lKFfda1B1BqAk0q1/ui/A== | |||
) | |||
|
|||
const ( | |||
testToken = "TEST-TOKEN" | |||
_testToken = "TEST-TOKEN" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: SPIRE doesn't use this convention for unexported package-level vars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should reference a specific style guide in the CONTRIBUTING.md. This convention comes directly from here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A style guide has been something we've talked about and wanted to introduce before, it has just never been prioritized. I've opened an issue to track this (#2377). Thanks for bringing it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\o/, thanks @bbarnes52
Signed-off-by: Brian Barnes <[email protected]>
Great analysis and thanks for the fix. I'm looking forward to getting this on an upgrade soon. Minimizing and untangling transitive dependency conflicts w/ k8s.io components is a big win. |
This revision removes the generated mocks for the k8s client-go package from the spire repo. Instead, the various
fake
packages from the client-go repository (the canonical method for stubbing out k8s client calls in unit tests) are used.This has a few benefits:
The tests themselves are cleaner. From https://testing.googleblog.com/2013/05/testing-on-toilet-dont-overuse-mocks.html, "Some signs that you're overusing mocks are if you're mocking out more than one or two classes, or if one of your mocks specifies how more than one or two methods should behave."
The k8s client-go repository does a poor job adhering to Go module management best practices, backwards incompatible changes across minor versions are commonplace. See client-go needs backwards compatibility test kubernetes/client-go#234. By generating mocks for entire packages in the client-go repo, any backwards incompatible changes to the interface of these packages cause the spire repo to be incompatible with the newer version of the
k8s.io/client_go
module (even if spire does not actually use the methods in question). This makes it challenging to depend on the spire repo, as if any other modules in the dependency chain use the k8s client and request a minimum version ofk8s.io/client-go
higher than what spire requests (currently0.18.2
) it is not uncommon for builds to fail due to backwards incompatible changes that affect the generated mocks. For example, here is the error message when we attempted to upgrade the version ofk8s.io/client-go
in our repo:While the root cause here is k8s poor Go module management, we can effectively mitigate this problem by limiting our exposure to the client-go API surface to just the methods we actually use.
Signed-off-by: Brian Barnes [email protected]