-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Sample test code breaks when a second test is added #2856
Comments
On a related note, this controller-runtime issue mentions that deletion of namespaces is not supported by envtest, and that the suggestion (if namespace isolation is important) is to use an external cluster like k3s or kind. Perhaps the issue of namespace isolation should be documented, and the whole "delete / create namespace" code path be removed? |
Hi @mogsie, The example scaffold works well and fine. Kubebuilder uses controller runtime but it is not responsible to implement ENV TEST. Therefore, I understand what you are looking for is an RFE to make ENV TEST allow this scenario. In this way, could you please raise an issue against controller-runtime? Here, the only thing that we can do is to document this scenario to help others. We have desired to have/add a FAQ section and it seems a very good fit for there. Would you like to contribute with it? |
Yes, I'd like to help write a FAQ entry. But the source code I mention is in this repository — the tests work, because there's only one test in them. It's not useful for continuing, regardless of envtest issues. |
Hi @mogsie,
Regards the code IMO: AfterEach(func() {
// TODO(user): Attention if you improve this code by adding other context test you MUST
// be aware of the current delete namespace limitations. More info: https://book.kubebuilder.io/reference/envtest.html#testing-considerations
By("Deleting the Namespace to perform the tests")
_ = k8sClient.Delete(ctx, namespace)
By("Removing the Image ENV VAR which stores the Operand image")
_ = os.Unsetenv("MEMCACHED_IMAGE")
}) WDYT? Could you please help us do these changes? |
What broke? What's expected?
The generated test suite contains the following code (taken from the test data) abbreviated slightly:
Then a single It() which is a test of some sort.
Addina second (empty) It() the above code will break, because the
namespace
object contains metadata not suitable for creating a namespace.Adding a second It() yields the following error (
make test
)Note that fixing this by resetting the Namespace object, only yields another problem, possibly in kubebuilder, that the old namespace isn't really being deleted.
Reproducing this issue
Expected result: The new test passes
Actual results: The test suite fails to create the namespace
KubeBuilder (CLI) Version
master
PROJECT version
No response
Plugin versions
No response
Other versions
No response
Extra Labels
No response
The text was updated successfully, but these errors were encountered: