The following guide details how to debug the Azure Service Operator locally using the power of DevContainers and Kind.
Running the debugger in VSCode from within a DevContainer, you'll be able to interact with the operator just as you would if it was running within kubernetes using kubectl
.
- DevContainer is up and running.
- The operator is deployed and running within a local k8s cluster.
Before we start, verify your local k8s cluster is running and the operator is deployed using kubectl get pods -n azureoperator-system
.
If it is not, run make set-kindcluster
to spin up a new local k8s cluster using Kind with the operator deployed.
For this example we'll be working with:
If you're not familiar with how ResourceGroup works, spend some time reviewing resourcegroup_controller.go
, more specifically the Reconcile
func which can be found on this line.
-
Set your breakpoints. Place our breakpoint anywhere within the
Reconcile
func. -
Create a folder in the root of the project called
.vscode
and create a new file in that folder calledlaunch.json
. -
Copy and paste the following inside
launch.json
.{ "version": "0.2.0", "configurations": [ { "name": "Debug", "type": "go", "request": "launch", "mode": "auto", "program": "${workspaceFolder}/main.go", "env": {}, "args": [] } ] }
-
From your menu bar, click
Debug
->Start Debugging
(or simply hitF5
). -
From your console panel, click the
DEBUG CONSOLE
tab and verify the debugger is running. You should see something like this: INSERT IMAGE -
Now click on the
TERMINAL
tab and enterkubectl apply -f config/samples/azure_v1alpha1_resourcegroup.yaml
.
If you've done everything right, you should see your breakpoint hit.
Happy debugging!