wilfred-s commented on code in PR #569:
URL: https://github.com/apache/yunikorn-site/pull/569#discussion_r3800774001


##########
docs/developer_guide/env_setup.md:
##########
@@ -255,3 +255,108 @@ Or follow these simplified steps:
 
 More documentation can be found
 
[here](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/).
+
+## Debug scheduler in a remote cluster
+
+This section explains how to deploy a debug-enabled scheduler image to a 
remote cluster and attach a debugger from your local machine using 
[Delve](https://github.com/go-delve/delve).
+
+### Prerequisites
+
+- A remote Kubernetes cluster accessible via `kubectl` (see 
[above](#access-remote-kubernetes-cluster))
+- A container registry you can push to (Docker Hub, private registry, etc.)
+- [Delve](https://github.com/go-delve/delve) installed locally:
+  ```shell script
+  go install github.com/go-delve/delve/cmd/dlv@latest
+  ```
+
+### Build a debug image
+
+Compile the scheduler with optimizations and inlining disabled so that the 
debugger can map breakpoints correctly:
+
+```shell script
+cd yunikorn-k8shim
+CGO_ENABLED=0 go build -gcflags="all=-N -l" -o _output/shim ./pkg/cmd/shim
+```
+
+Create a Dockerfile for the debug image. This installs Delve and uses it as 
the entrypoint:
+
+```dockerfile
+FROM golang:1.22 AS dlv-builder
+RUN go install github.com/go-delve/delve/cmd/dlv@latest
+
+FROM ubuntu:22.04
+COPY --from=dlv-builder /go/bin/dlv /usr/local/bin/dlv
+COPY _output/shim /scheduler
+EXPOSE 2345
+ENTRYPOINT ["dlv", "exec", "/scheduler", "--headless", "--listen=:2345", 
"--api-version=2", "--accept-multiclient"]
+```
+
+Build and tag the image:
+
+```shell script
+docker build -t <your-registry>/yunikorn:scheduler-debug -f Dockerfile.debug .
+```
+
+### Push image to registry
+
+```shell script
+docker push <your-registry>/yunikorn:scheduler-debug
+```
+
+Alternatively, update the `REGISTRY` variable in the `Makefile` (see [Build 
Docker images](build.md#build-docker-images)) and adapt the build target.

Review Comment:
   We can use `REGISTRY` shell variable in the call to make: 
`REGISTRY="reg.local.host" make image`
   
   Additionally we can add building debug images into the k8shim makefile like 
we have done for reproducible builds: `REPRODUCIBLE_BUILDS=1 make image` make 
it something like `DEBUG_BUILDS=1 make image`
   based on the flag we add `-gcflags="all=-N -l"` to the build command. 
   Adding a variable in the command line we build, example after the `-a` option
   ```
        -a ${GCFLAGS} \
   ```
   If DEBUG_BUILDS is not set GCFLAGS is empty otherwise it is set to 
`GCFLAGS='-gcflags="all=-N -l"'`
   It can then be combined with the `REGISTRY` variable and keep everything in 
one place.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to