Skip to content

Commit 72ed812

Browse files
authored
Merge pull request #722 from valaparthvi/debug-development-doc
📜 Enhance debugging development doc
2 parents fdad193 + de05fad commit 72ed812

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

docs/book/src/04_developer/01_development.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ The following instructions are for development purposes.
6464
```bash
6565
kind create cluster --config kind-cluster-with-extramounts.yaml
6666
```
67-
68-
10. Now start tilt by running the following command in the directory where you cloned Cluster API repo in step 1:
67+
> NOTE: You can also use your existing kind cluster by using the environment variable `CAPI_KIND_CLUSTER_NAME`.
68+
10. Export `CLUSTER_TOPOLOGY=true` to enable support for managed topologies and ClusterClass.
69+
11. Now start tilt by running the following command in the directory where you cloned Cluster API repo in step 1:
6970

7071
```bash
7172
tilt up
@@ -79,8 +80,11 @@ This section explains how to attach debugger to the CAPRKE2 process running in a
7980
connecting a debugger to this process, you would be able to step through the code through your IDE. This guide
8081
covers two popular IDEs - IntelliJ GoLand and VS Code.
8182

82-
On the Tilt web UI and confirm the port on which `caprke2_controller` is exposed. By default, it should be
83-
localhost:30001.
83+
On the Tilt web UI and confirm the port on which `caprke2_controller` is exposed. By default, it should be localhost:30002.
84+
85+
If you want to debug CAPRKE2 bootstrap controller, find where `capbpr_controller` is exposed. By default, it should be localhost:30001.
86+
87+
To learn about debugging Core CAPI Controller, refer to [the official doc](https://cluster-api.sigs.k8s.io/developer/core/tilt).
8488

8589
### GoLand
8690

@@ -89,6 +93,10 @@ localhost:30001.
8993
Remote'.
9094
3. Enter the 'Host' and 'Port' values based on where `caprke2_controller` is exposed.
9195

96+
You can setup a similar debugger for the Bootstrap controller.
97+
98+
To debug Bootstrap and Control Plane simultaneously, you can add a new configuration as before but select 'Compound' and then select the Go Remote setups for both controllers.
99+
92100
### VS Code
93101

94102
1. If you don't already have a `launch.json` setup, go to 'Run and Debug' in the Activity Bar and click on 'create a
@@ -111,11 +119,11 @@ localhost:30001.
111119
]
112120
}
113121
```
114-
122+
---
115123
Insert a breakpoint, e.g., in the [`updateStatus`](https://github.com/rancher/cluster-api-provider-rke2/blob/5163e6233301262c5bcfebab58189aa278b1f51e/controlplane/internal/controllers/rke2controlplane_controller.go#L298) method which responsible for updating the status of the `RKE2ControlPlane`
116124
resource and run the configuration. To check if you can step into the code, create a workload cluster by using the
117125
example provided in the [documentation](../03_examples/03_docker.md). If things were configured correctly, code
118-
execution would halt at the breakpoint and you should be able to step through it.
126+
execution would halt at the breakpoint, and you should be able to step through it.
119127

120128
## Troubleshooting
121129

@@ -125,4 +133,33 @@ run `tilt logs` in a separate terminal without stopping the `tilt up` command th
125133
### Common Issues
126134

127135
1. Make sure you run the `kind` and `tilt` commands mentioned above from correct directory.
128-
2. A `go mod vendor` might be required in your clone of CAPI repo. `tilt logs` should make this obvious.
136+
2. A `go mod vendor` might be required in your clone of CAPI repo. `tilt logs` should make this obvious.
137+
138+
# Unit Testing
139+
Unit tests use envtest, and to ensure you can run them locally, you need to install the envtest binary.
140+
141+
```shell
142+
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
143+
KUBEBUILDER_ASSETS=$(setup-envtest use -p path <k8s-version>)
144+
```
145+
146+
Set the envvar `KUBEBUILDER_ASSETS` and its value in your code editor's test configuration.
147+
148+
# E2E Testing
149+
To run or debug a test from your code editor, you would need to setup the configuration with some environment variables and arguments.
150+
To run an e2e test, we use `make e2e-test` in the CI, we will replicate the same settings in our code editor configuration.
151+
152+
## Goland
153+
Create a Run/Debug configuration with the following settings:
154+
Environment variables:
155+
1. LOCAL_IMAGES=/path/to/cluster-api-provider-rke2/out/images
156+
2. CAPI_KUSTOMIZE_PATH=/path/to/cluster-api-provider-rke2/hack/tools/bin/kustomize-v5.5.0
157+
158+
Go tool arguments:
159+
1. `--tags=e2e`
160+
161+
Program arguments:
162+
1. `-e2e.artifacts-folder="/path/to/cluster-api-provider-rke2/_artifacts"`
163+
2. `-e2e.config="/path/to/cluster-api-provider-rke2/test/e2e/config/e2e_conf.yaml"`
164+
3. `-e2e.use-existing-cluster=false`
165+
4. `-e2e.skip-resource-cleanup=false`

0 commit comments

Comments
 (0)