Debugging Kubebuilder tests

108 Views Asked by At

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 make targets manifests generate fmt vet envtest (which are run automatically when we run make test). Didn't work, since the shell script execution runs in one window, and then the go test execution runs in a fresh window inside GoLand. Ends up not being able to even start the control plane since the make envtest is 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 test in the terminal, and then running Attach to process inside GoLand, to attach to the go process of go test ./.... But that fails with an error:

      could not attach to pid 84628: stub exited while waiting for connection: exit status 0
      

      Meanwhile, attaching to other processes (like kube-apiserver and etcd) 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/null but that fails with:
      could not launch process: not an executable file
      could not remove /dev/null: remove /dev/null: operation not permitted
      

I'm happy to share any more details.

Any ideas as to how I can debug this? Thanks in advance!

0

There are 0 best solutions below