How do I actively test my code while developing #3768
-
Currently following the To give an analogy -- say I'm working on the backend of a webserver. I create a new route that gets the input from a form and writes it to a database. Here's how I would go about implementing said route:
you get the idea. There's an active feedback loop in the above workflow so that there's no guesswork involved. In the same way say if I was implementing the reconciliation logic on my own here's how I would start:
so on and so forth. Are there any docs that highlight what this process is like, if not, any ideas on how I could do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @awalvie, OverviewTo validate your controller logic, you can use ENVTEST. Check out the examples under the controllers to create the suite and the test for each controller here. Note that you should have a test for each controller. Additionally, you can perform end-to-end (e2e) tests to check your solution, with an example available under the testdata here. When creating a project with the Kubebuilder CLI, an initial scaffold is provided in If you use the Deploy Image plugin (more information here), it generates the scaffold to deploy and manage an image, including an implemented test. See this example here. The Kubebuilder docs provide a section on writing tests with examples here. Remember that following up the Operator Pattern, we declare the desired state and loop (reconcile) until it is ensured. It's recommended to re-trigger the reconciliation based on events raised, like updates, deletions, or creations of a Custom Resource that you are watching. Therefore, you can use kubectl, for example, to apply the CR and check the logs to know what is happening. 💡 Check the code generated by the Deploy Image plugin to understand Conditional Status and best practices. Review the Kubernetes API conventions here. The implementation can be seen in the code generated by the Deploy Image plugin here. Also, use the e2e tests implemented in Kubebuilder as a reference, available here. Iterative Development ProcessFor an iterative development process in Kubebuilder:
Testing and Logging
Iterative Development
Feedback Loop
Additional Tips
I am closing this as sorted out, but feel free to reopen it if needed, or open new discussion topics for more specific questions after reviewing all the content and examples shared. |
Beta Was this translation helpful? Give feedback.
Hi @awalvie,
Overview
To validate your controller logic, you can use ENVTEST. Check out the examples under the controllers to create the suite and the test for each controller here. Note that you should have a test for each controller.
Additionally, you can perform end-to-end (e2e) tests to check your solution, with an example available under the testdata here. When creating a project with the Kubebuilder CLI, an initial scaffold is provided in
test/e2e
for your e2e tests. You can also refer tosuite_test.go
for using envtest.If you use the Deploy Image plugin (more information here), it generates the scaffold to deploy and manage an image, including an implemented test. See this example h…