Skip to content

Commit 70ab9b3

Browse files
slash commands for setup dev environment and debugging of the operator locally
1 parent 0e91945 commit 70ab9b3

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed

.claude/commands/debug-operator.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Debug NetObserv Operator Locally
2+
3+
This command prepares the environment for debugging the operator locally.
4+
5+
**Prerequisites:** You must have already set up the development environment using `/setup-dev-env` before running this command.
6+
7+
## Steps
8+
9+
### 1. Scale down the in-cluster operator
10+
11+
Scale down the operator running in the cluster to avoid conflicts:
12+
13+
```bash
14+
kubectl scale deployment netobserv-controller-manager -n netobserv --replicas=0
15+
```
16+
17+
### 2. Remove the validating webhook
18+
19+
Delete the webhook to allow free modification of the FlowCollector CR during local development:
20+
21+
```bash
22+
kubectl delete validatingwebhookconfiguration netobserv-validating-webhook-configuration
23+
```
24+
25+
### 3. Run the operator locally
26+
27+
Use the AskUserQuestion tool to ask which debugging method to use:
28+
29+
**Question:** "How do you want to run the operator locally?"
30+
- **Header:** "Debug method"
31+
- **Options:**
32+
1. "go run - Simple execution without debugging"
33+
2. "delve interactive - Terminal debugging with dlv commands"
34+
3. "delve headless + VSCode - UI debugging with breakpoints"
35+
36+
**Based on the user's selection, execute the corresponding command:**
37+
38+
#### Option 1: go run
39+
```bash
40+
go run ./main.go \
41+
-ebpf-agent-image=quay.io/netobserv/netobserv-ebpf-agent:main \
42+
-flowlogs-pipeline-image=quay.io/netobserv/flowlogs-pipeline:main \
43+
-console-plugin-image=quay.io/netobserv/network-observability-console-plugin:main \
44+
-namespace=netobserv
45+
```
46+
47+
#### Option 2: delve interactive
48+
```bash
49+
dlv debug ./main.go -- \
50+
-ebpf-agent-image=quay.io/netobserv/netobserv-ebpf-agent:main \
51+
-flowlogs-pipeline-image=quay.io/netobserv/flowlogs-pipeline:main \
52+
-console-plugin-image=quay.io/netobserv/network-observability-console-plugin:main \
53+
-namespace=netobserv
54+
```
55+
56+
After starting, inform the user they can use these delve commands:
57+
- `break main.main` - set breakpoint
58+
- `continue` - continue execution
59+
- `next` - step to next line
60+
- `print <variable>` - inspect variables
61+
62+
#### Option 3: delve headless + VSCode
63+
64+
**Step 1:** Start Delve in headless mode:
65+
```bash
66+
dlv debug ./main.go --headless --listen=:2345 --api-version=2 --accept-multiclient -- \
67+
-ebpf-agent-image=quay.io/netobserv/netobserv-ebpf-agent:main \
68+
-flowlogs-pipeline-image=quay.io/netobserv/flowlogs-pipeline:main \
69+
-console-plugin-image=quay.io/netobserv/network-observability-console-plugin:main \
70+
-namespace=netobserv
71+
```
72+
73+
**Step 2:** Inform the user:
74+
75+
"Delve is now running in headless mode on port 2345. To connect from VSCode:
76+
1. Open the Debug view (Ctrl+Shift+D / Cmd+Shift+D)
77+
2. Select 'Connect to Delve (Operator Debug)' from the dropdown
78+
3. Press F5 or click 'Start Debugging'
79+
80+
You can now set breakpoints in VSCode and debug the operator."
81+
82+
### 4. Example: Debug FlowCollector reconciliation
83+
84+
**To help the user get started with debugging:**
85+
86+
The main reconciliation logic is in `internal/controller/flowcollector/flowcollector_controller.go` (look for the `Reconcile` function around line 100-150).
87+
88+
**If using VSCode debugging:**
89+
1. Open `internal/controller/flowcollector/flowcollector_controller.go`
90+
2. Click the left margin next to the line number inside the `Reconcile` function to set a breakpoint
91+
3. Trigger a reconciliation by running:
92+
```bash
93+
kubectl patch flowcollector cluster --type=merge -p '{"spec":{"processor":{"logLevel":"debug"}}}'
94+
```
95+
96+
The debugger will pause at your breakpoint, allowing you to inspect the FlowCollector object and step through the reconciliation logic.
97+
98+
## Cleanup
99+
100+
When finished debugging:
101+
102+
1. Stop the local operator (Ctrl+C in terminal, or stop debugging in VSCode)
103+
104+
2. Scale the in-cluster operator back up:
105+
```bash
106+
kubectl scale deployment netobserv-controller-manager -n netobserv --replicas=1
107+
```
108+
109+
**Note:** The validating webhook will be automatically recreated by the operator.

.claude/commands/setup-dev-env.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Setup NetObserv Development Environment
2+
3+
This command sets up a complete development environment for NetObserv.
4+
5+
## Gather Configuration
6+
7+
First, use the AskUserQuestion tool to gather the necessary configuration:
8+
9+
**Question 1:** What platform are you using?
10+
- Options: OpenShift, Kubernetes
11+
- Header: "Platform"
12+
- Store the answer to determine if `make set-release-kind-downstream` should be run in step 2.
13+
14+
**Question 2:** Are you using custom images?
15+
- Options: "Yes, custom images", "No, use defaults (netobserv/main)"
16+
- Header: "Images"
17+
18+
**If the user selected custom images**, ask follow-up questions to get:
19+
- USER (quay.io username/repo, e.g., "leandroberetta")
20+
- VERSION (image tag, e.g., "v1.2.3" or "main")
21+
22+
Set the variables:
23+
- If using defaults: `USER=netobserv` and `VERSION=main`
24+
- If using custom: `USER=<user_value>` and `VERSION=<version_value>`
25+
26+
## Steps
27+
28+
### 1. Deploy the operator
29+
30+
Run the deployment command with the configured values:
31+
32+
**If custom USER and VERSION:**
33+
```bash
34+
USER=<user_value> VERSION=<version_value> make deploy
35+
```
36+
37+
**If using defaults:**
38+
```bash
39+
USER=netobserv make deploy
40+
```
41+
42+
### 2. Configure for OpenShift (if applicable)
43+
44+
**Only run this if the user selected OpenShift** in the platform question:
45+
46+
```bash
47+
make set-release-kind-downstream
48+
```
49+
50+
Skip this step for Kubernetes.
51+
52+
### 3. Deploy Loki
53+
54+
```bash
55+
make deploy-loki
56+
```
57+
58+
### 4. Deploy sample FlowCollector CR
59+
60+
```bash
61+
make deploy-sample-cr
62+
```
63+
64+
### 5. Verify deployment
65+
66+
Run these commands to verify all components are running:
67+
68+
```bash
69+
kubectl get pods -n netobserv
70+
kubectl get flowcollector cluster -o yaml
71+
```
72+
73+
## Cleanup
74+
75+
To remove the entire environment:
76+
77+
```bash
78+
make undeploy
79+
```

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Connect to Delve (Operator Debug)",
6+
"type": "go",
7+
"request": "attach",
8+
"mode": "remote",
9+
"remotePath": "${workspaceFolder}",
10+
"port": 2345,
11+
"host": "localhost",
12+
"showLog": true,
13+
"trace": "verbose"
14+
}
15+
]
16+
}

0 commit comments

Comments
 (0)