Is there a way to debug the tests while developing a Kubernetes Operator (using the Kubebuilder framework)?
For instance, I have the following files with the same package controller:
- internal/controller/component_a.go
- internal/controller/component_b.go
- and other files up till component_f.go
And then, as usual, I have the suite_test.go & component_test.go files in the same directory as the components (with the same package name controller).
Running make test works perfectly fine, but I'm wondering if there's a way to attach a debugger and add breakpoints somehow.
I've currently tried a couple of ways to attach a debugger:
- Tried replicating the exact same configuration in GoLand:
Added a run configuration with a Before Launch configuration to execute a Shell script with (Script Text selected) and the contents as the contents of the
maketargetsmanifests generate fmt vet envtest(which are run automatically when we runmake test). Didn't work, since the shell script execution runs in one window, and then thego testexecution runs in a fresh window inside GoLand. Ends up not being able to even start the control plane since themake envtestis crucial to set up the envtest binaries.Added a run configuration with Before Launch configuration as Make targets. Didn't work. Complains about the same as above.
Tried running the
make testin the terminal, and then runningAttach to processinside GoLand, to attach to the go process ofgo test ./.... But that fails with an error:could not attach to pid 84628: stub exited while waiting for connection: exit status 0Meanwhile, attaching to other processes (like
kube-apiserverandetcd) works like a charm, but I have no use attaching to them :).
- Tried to run the tests via
dlv test:- Tried running
dlv test ./... -output /dev/nullbut that fails with:could not launch process: not an executable file could not remove /dev/null: remove /dev/null: operation not permitted
- Tried running
I'm happy to share any more details.
Any ideas as to how I can debug this? Thanks in advance!