-
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
✨ Enable using setup-envtest without a separate CLI #2810
base: main
Are you sure you want to change the base?
✨ Enable using setup-envtest without a separate CLI #2810
Conversation
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tomasaschan The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
a12a6c3
to
b3a4f85
Compare
I will rebase this properly once #2811 merges, since I expect conflicts with that anyway. |
17d784a
to
3650b9b
Compare
3650b9b
to
c8aa9b3
Compare
@sbueringer I think this is ready for an initial review now! I still want to get rid of the dependency on |
I've spent some time now trying to rebuild this without a dependency on While it's certainly possible to build a read/write file system abstraction (on top of @sbueringer What do you think? If you agree with this assessment, I can rebase again to get the latest version bumps of everything, and then this should be ready to go! |
c8aa9b3
to
645331e
Compare
There are two main points of re-implementing vs just moving the code: 1. Error handling in the old code base was based on panicking and recovering, where the recover basically just read out a field from the panic value and determined the correct exit code. In a package, we want more nuanced error handling, especially in order to allow test suites to catch the errors and surface them through their own reporting mechanisms. 2. There was a lot of global state in the old code base, "hidden" in the env.Env type that was used as a receiver for all the methods. This re-implementation tries to make the state more explicit, keeping only dependencies (like the remote client and local store) in the environment, while retaining the same behavior as the previous implementation. Tests have been ported over to their respective workflow sub-packages, and a few new ones have been added to cover cases the old test suite for one reason or another did not. Thus, we can be fairly confident that the new implementation does not break old functionality, even if it is a significant rewrite.
645331e
to
5b1508a
Compare
PR needs rebase. 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-sigs/prow repository. |
@tomasaschan Just a heads up. We'll merge a PR directly after 0.19 which drops the support for GCS. Basically because we wanted to do it anyway, but also to simplify maintenance & refactorings like this PR |
Thanks for the heads up! Have you had time to review these changes, and in particular my last comment about keeping the afero dependency? |
Didn't get around to it yet. Just recently found time to catch up on controller-runtime in general and this is a big PR. But I'll try to look at it soon. Definitely feel free to wait with further rebases until then |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
/lifecycle frozen @sbueringer and potentially other maintainers: given the initial hesitation to introduce a dependency on |
@tomasaschan: The In response to this:
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-sigs/prow repository. |
@sbueringer Any chance I can get a more explicit decision on afero than a 👍 on my question above? 😅 |
@tomasaschan Sorry should have brought this up way earlier but somehow I didn't think about that. What is the functionality we are actually looking for from an envtest point of view? Download & extract the binaries if they don't already exist locally? Just seems that if that's mostly what we are looking for, setup-envtest has an insane level of complexity. Also it's probably a lot easier to add a few functions that cover what we need to the envtest package (they can reuse e.g. the http_client underneath) than porting all the commands and workflows over. And sorry I think I lost the overview a bit, the idea of the current PR was to basically move the entire setup-envtest implementation into the main module with some refactorings so that everything can be also called in test code and not only via the CLI, correct? Regarding afero. It has dependencies on e.g. |
@sbueringer My motivation for this PR is outlined in the issue linked from the PR body. In short, I'd like to avoid the need for wrapping the call to Wrt afero, the main reason to use it in setup-envtest is to make the file-system dependent parts testable; afero provides an abstraction that has both file system backed and in-memory backed implementations, meaning it's relatively easy to write tests that verify the file system dependent operations (anything from downloading the right version to choosing the right one based on what's already locally available). I did survey for similar abstractions in the stdlib, but found none - the one that exists is basically read-only. What if the change instead involved pulling envtest out of controller-runtime (rather than pulling setup-envtest into it)? That way, dependencies would not be such an important consideration (depending on envtest is much more optional that depending on all of controller-runtime), and users of envtest could still configure their test harness to run without ad-hoc wrapping scripts. Would that be a more acceptable approach? |
This would only help if controller-runtime itself stops using envtest for its own testing. Otherwise we end up with the same transitive dependencies. If I look at this from an envtest perspective, we basically have to invoke HTTPClient.GetVersion and then add a bit of code around it to ensure the file is written to the right location (+ skip if it's already there), right? I think testing for this can be done without abstracting away the filesystem. |
Plus all of the parsing of desired version, and resolving that (which involves looking at what's available locally, potentially at a custom location, and online, potentially with a custom registry). Additionally, there's still a few places where error handling is basically
The main benefit of in-memory file systems for tests over real ones, IMO, is that the in-memory ones share no state, so there is no coupling between the tests. If we write the tests to interact with a real file system, we'll have all kinds of issues around shared state, test ordering, etc. Do you have a proposed way to avoid that? |
Make paths configurable and use different tmp folder(s) for different tests |
This implements the proposal in #2790.
The implementation is incomplete so far; opening this mostly to show my progress and solicit feedback, as well as to avoid too many conflicts with initiatives like this one.
To do:
use
in the main modulelist
in the main modulecleanup
in the main modulesideload
in the main modulesetup-envtest
module, removing duplicated code etcRemove dependency onafero
go.mod
since I branched off(Optional, possibly in a later PR) Re-implement the arg parsing and help parts of the main module with something a little less home-grown, probably something like https://github.com/spf13/cobra/