-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
✨ Add Kubernetes Gomega extension with to make testing controllers easier #1767
Conversation
|
Welcome @schrej! |
Hi @schrej. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
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.
@schrej thanks for reviving this effort.
While I get EqualObject and HaveField, and I would really like to have them merged, I'm still grokking the Komega client.
If others feel the same, might be breaking this in separated PR could help...
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.
In the interest of keeping the review surface small, I'm wondering if we should break this PR up a bit. The addition of the EqualObject
matcher makes this PR quite a lot bigger and, as it is code that is already reviewed and accepted within CAPI, maybe should be reviewed separately if we intend to transfer it to this repo. That way we can focus the discussion on the design of the gomega extension and other new code within the PR? WDYT?
pkg/envtest/komega/default.go
Outdated
// Default is the Komega used by the package global functions. | ||
// NOTE: Replace it with a custom instance or use WithDefaultClient. | ||
// Otherwise the package global functions will panic. | ||
var Default Komega = &komega{} |
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.
Is the intention here that you can import this and use it in the same way that you would with the default Gomega? Rather than having to have the Komega
in scope, you just komega.CreateObject().Should(Succeed())
?
Only nit is that these names don't match the interface at the moment, would it be good to be consistent?
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.
The intention for the different names was to be a bit more clear that it's about Kubernetes objects when there is no komega
in front of it. Also there would be collision with Eventually and Consistently.
Naming isn't great yet though.
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.
Ok that makes sense, just one nit, I don't think it needs to be exported does it? Looking at the usage in this file we can probably make it private
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.
We can, and that even reduces friction with importing both gomega and komega as .
.
87675c9
to
be1fcf6
Compare
I've removed the matcher as requested. I'll open another PR once this is in, so it's not as confusing. I've left |
be1fcf6
to
33e6134
Compare
pkg/envtest/komega/default.go
Outdated
// Default is the Komega used by the package global functions. | ||
// NOTE: Replace it with a custom instance or use WithDefaultClient. | ||
// Otherwise the package global functions will panic. | ||
var Default Komega = &komega{} |
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.
Ok that makes sense, just one nit, I don't think it needs to be exported does it? Looking at the usage in this file we can probably make it private
is |
33e6134
to
ec47819
Compare
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.
Apart from the HaveField
naming conflict, I think this is looking pretty good
ab25b63
to
bf5d641
Compare
@fabriziopandini @vincepri do you have an opinion on that? |
/lgtm I don't have a strong opinion on the naming, but the Komega is looking really clean now and with the gomega HaveField should be really useful for trimming the fat in controller tests |
After further investigation I don't think it makes sense to add generics at this time. As Stefan pointed out it will obviously require go 1.18, and force all depending projects to use 1.18 as well. Since methods don't support type parameters (only structs), it's also hard to implement it in a beneficial way. |
Ok. All comments should be addressed now. No generics. |
Not related to the changes. |
/approve |
Leaving lgtm for one of the new approvers for this |
f772b9d
to
9b054aa
Compare
/retest |
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.
Couple of nits otherwise LGTM
0dc4549
to
3d4dfd2
Compare
The helpers can be used to write tests using the gomega library in conjunction with the Kubernetes API, or a mock of it. Co-Authored-By: Joel Speed <joel.speed@hotmail.co.uk>
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
Thanks for all your work on this @schrej
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, JoelSpeed, schrej The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This is an attempt to revive #1364 by @JoelSpeed. It's essentially the same with a few changes:
. sigs.k8s.io/controller-runtime/pkg/envtest/komega
and use it similar to GomegaMatcher
tokomega
since it's actually not a Gomega MatcherWith...
functions to copy komegaThis still needs a lot of tests and documentation.
cc @Danil-Grigorev @joelanford @fabriziopandini since you were interested in the original PR