-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
E2E: handling extra files #69103
E2E: handling extra files #69103
Conversation
/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.
Minor comments + 2 commits, please.
1 for changes
1 for auto-generated.
"github.com/onsi/ginkgo" | ||
) | ||
|
||
var filesources = make([]FileSource, 0, 5) |
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.
Why not just make it a nil slice?
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.
No particular reason, I just thought that pre-allocating some memory might be useful. But I agree, that's something that the first append() can also do, so I'll make it nil.
// doesn't have to implement error checking. | ||
func ReadOrDie(filePath string) []byte { | ||
if len(filesources) == 0 { | ||
ginkgo.Fail(fmt.Sprintf("No file sources registered (yet?), cannot retrieve test file %s.", filePath)) |
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.
Do we need a dependence on ginkgo in this utility functions, or should we return an error and fail outside?
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.
After looking at the call sites I think you wrap everything into an error handler and pass in a closure to call the ginkgo with the error without you having to take on owning ginkgo details in this sub-package.
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.
This is part of test/e2e/framework, which already is tied to Ginkgo, so it seemed okay to use that also here. It makes the API a bit simpler. What about just calling panic
? The effect will be the same (also get's caught by Ginkgo and logged).
It's not just ReadOrDie
, Exists
also fails on errors to simplify the call sites.
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.
Passing via a well defined, simple closure it not too pesky and would meet the goal of minimizing the proliferation of ginkgo dependencies and being about to have the failure be clearly visible from the call sites.
@timothysc I force-pushed two commits, one for the source code changes and one for the Bazel BUILD files. I kept the test/e2e/examples.go changes because if we merge all of this at once, we do not need PR #68187 anymore. This version uses Here's output for a test that triggers such a panic because the file name was changed such that the file isn't found. I've shortened the list of files. The original error lists all of the builtin files:
|
error += filesource.DescribeFiles() | ||
error += "\n" | ||
} | ||
panic(error) |
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.
panic is probably not the right solution but a simple callback parameter for the error. Or to change the signatures outside to handle the error.
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.
Okay, I'll add that.
@timothysc I pushed a version which takes a callback that gets invoked on failures. To make the API still easy to use, the signature is exactly that of ginkgo.Fail. Otherwise callers would have to use a closure. Some callers can handle an error and don't use Ginkgo. For those I added a |
/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.
/lgtm
/approve
Thanks for doing this!
/kind feature |
/retest Review the full test history for this PR. Silence the bot with an |
The new test/e2e/framework/testfiles package makes it possible to write tests that do not depend on a specific way of providing additional test files at runtime. Such tests and the framework are then more easily reused in other test suites. In the test/e2e suite file access is enabled based on the existing "repo-root" command line parameter and the built-in bindata. Tests using the new API will first check for files under "repo-root" and then fall back to the builtin data. This way, users of a test binary can modify those files without having to rebuild the binary. "repo-root" is still needed because at least some tests check for additional files (secret.yaml, via ingress_utils.go) that are not part of the upstream source code and thus may or may not be built into a test binary. Tests using bindata or repo-root directly get modified to use the new API, or removed when they are obsolete: test/e2e/examples.go depended on files that were removed in kubernetes#61246 and thus can no longer be run in Kubernetes. Moving the tests to kubernetes/examples is tracked in kubernetes/examples#214. The file removal did not break the automated E2E testing probably because the tests are under the Feature:Example tag and thus not enabled during normal CI runs. Removing also the obsolete tests makes it simpler to rework the "repo-root" setting because less code uses it. Related-to: kubernetes#66649 and kubernetes#23987
Generated via hack/update-bazel.sh.
/retest |
@timothysc I had to rebase because 60f736e introduced a new direct call to the There's also some test failure in pull-kubernetes-integration which I don't understand ("test-cmd run_rs_tests" fails) - a flake or does this PR really cause that test to fail now? |
/retest |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pohly, timothysc 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 |
/retest |
1 similar comment
/retest |
What this PR does / why we need it:
There is an on-going effort to make test/e2e.test self-contained by building all files that are needed at runtime into the binary via bindata. Tests which support that do so by retrieving files from the test/e2e/generated package. The downside of that approach is that such tests only work in Kubernetes itself. As described in issue #66649, making tests reusable outside of Kubernetes is useful, for example for testing other CSI drivers.
This PR adds an API (test/e2e/framework/testfiles) that decouples tests from the actual code that retrieves files. In the test/e2e test suite, access via --repo-root is kept in addition to retrieval from bindata, so everything works as before.
The goal is not to get rid of --repo-root. However, by converting some tests to use the new API, those tests no longer depend on --repo-root, so we get a step closer to that goal - if it still is a goal. Some tests depend on extra files (for example, test/e2e/framework/ingress/ingress_utils.go for providing the optional secret.yaml) which cannot be built into the binary.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Partial fix #66649 (main goal)
Partial fix #23987 (side effect)
Special notes for your reviewer:
This depends on PR #68187 getting merged first. The first commit here is from that PR.
This is a subset of PR #68483.
Release note:
/sig testing