-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #4513: Allow to remote debug the Operator
- Loading branch information
Showing
6 changed files
with
156 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,3 +176,7 @@ config/**/*.gen.json | |
# Fabric8 CRDs | ||
java/target | ||
pkg/resources/resources.go | ||
|
||
MAC OS files | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
docs/modules/ROOT/pages/contributing/remote-debugging.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
[[debugging]] | ||
= Debugging Camel-K | ||
|
||
In this article, we describe the steps needed to be able to remote debug the Camel-K operator directly from the K8s cluster. | ||
By doing so you are sure that the operator is executed in the same context as your target environment which is not the case | ||
if the operator is launched on the local machine. | ||
|
||
[[publish-image]] | ||
== Publish the image | ||
|
||
The first thing to do is to build a specific docker image of the Camel-K operator for the debug mode, indeed the `kamel` program | ||
will then be built without compiler optimizations, and inlining but also the docker image will launch the operator through | ||
https://github.com/go-delve/delve[`delve`] to be able to remote debug the operator. | ||
|
||
[source,shell] | ||
---- | ||
DEBUG_MODE=true make images | ||
---- | ||
|
||
Once done, a tag of type `docker.io/apache/camel-k:2.0.0-SNAPSHOT-debug` is pushed into your local docker image registry. | ||
|
||
In case you are using Minikube, before executing the previous command make sure to set up properly the environment | ||
variables of your terminal by executing the command `eval $(minikube -p minikube docker-env)`, in that case the image is | ||
directly pushed into the registry of Minikube. | ||
|
||
For other cluster like for example `kind` where the registry is accessible from the host `localhost:5001`, simply tag the | ||
image to match with the new host and port with the next command: | ||
|
||
[source,shell] | ||
---- | ||
docker tag docker.io/apache/camel-k:2.0.0-SNAPSHOT-debug localhost:5001/apache/camel-k:2.0.0-SNAPSHOT-debug | ||
---- | ||
|
||
Then push the image to the target registry with next command: | ||
[source,shell] | ||
---- | ||
docker push localhost:5001/apache/camel-k:2.0.0-SNAPSHOT-debug | ||
---- | ||
|
||
To ensure that the image has been pushed with success, launch the following command | ||
[source,shell] | ||
---- | ||
curl http://localhost:5001/v2/_catalog | ||
{"repositories":["apache/camel-k"]} | ||
---- | ||
|
||
[[install-operator]] | ||
== Install the operator | ||
|
||
Since the docker image is ready to be used, we can now install the operator with the debugging flags to make sure that | ||
the operator will be launched properly with the debug port open on the corresponding pod. | ||
|
||
First, let's create a namespace in which the operator will be installed, here the namespace is `test`. | ||
[source,shell] | ||
---- | ||
kubectl create ns test | ||
namespace/test created | ||
---- | ||
|
||
Then install the operator with the image that we built before | ||
[source,shell] | ||
---- | ||
./kamel install --olm=false --operator-image apache/camel-k:2.0.0-SNAPSHOT-debug --debugging -n test | ||
---- | ||
It will install the operator using `apache/camel-k:2.0.0-SNAPSHOT-debug` as docker image in debug mode. | ||
|
||
[[port-forward]] | ||
== Open the port on the pod | ||
|
||
The operator is now waiting for a remote connection, but to make it possible, we need to make the debugging port of the | ||
pod accessible from outside the cluster thanks to the following `port-forward` command: | ||
|
||
[source,shell] | ||
---- | ||
kubectl port-forward -n test $(kubectl get po -l app=camel-k -oname -n test) 4040:4040 | ||
Forwarding from 127.0.0.1:4040 -> 4040 | ||
Forwarding from [::1]:4040 -> 4040 | ||
---- | ||
This command port forwards the port `4040` of the pod to the local port `4040` which makes it accessible from localhost. | ||
Where `4040` is the default port of delve set on the pod, but it can be changed when installing the operator with the flag | ||
`--debugging-port=4040` | ||
|
||
[[configure-ide]] | ||
== Configure your IDE | ||
|
||
At this stage, you simply need to configure your favorite IDE to remote debug the operator using `localhost` as host and | ||
`4040` as port: | ||
|
||
* https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#step-3-create-the-remote-run-debug-configuration-on-the-client-computer[Configure IDEA] | ||
* https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#remote-debugging[Configure VSCode] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters