Skip to content

Commit

Permalink
refactor(dev): add dlv debuger for virt-handler (#538)
Browse files Browse the repository at this point in the history
add dlv debuger for virt-handler

Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat authored Dec 2, 2024
1 parent 666b5a9 commit 3c86dad
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,36 @@ tasks:
cmds:
- task: cve:bin
- tools/cve/scan-main.sh {{.REPORT_FILE_NAME}}

dlv:virt-handler:build:
desc: "Build image virt-handler with dlv"
cmd: docker build -f ./images/virt-handler/debug/dlv.Dockerfile -t "{{ .DLV_IMAGE }}" .

dlv:virt-handler:build-push:
desc: "Build and Push image virt-handler with dlv"
cmds:
- task: dlv:virt-handler:build
- docker push "{{ .DLV_IMAGE }}"
- task: dlv:virt-handler:print

dlv:virt-handler:print:
desc: "Print commands for debug"
env:
IMAGE: "{{ .DLV_IMAGE }}"
cmd: |
cat <<EOF
kubectl -n d8-virtualization patch ds virt-handler --type='strategic' -p '{
"spec": {
"template": {
"spec": {
"containers": [ {
"name": "virt-handler",
"image": "${IMAGE}",
"ports": [ { "containerPort": 2345, "name": "dlv" } ]
}]
}
}
}
}'
kubectl -n d8-virtualization port-forward pod/<virt-handler-pod> 2345:2345
EOF
64 changes: 64 additions & 0 deletions images/virt-handler/debug/dlv.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM alt:p11@sha256:39f03d3bca1a92dc36835c28c2ba2f22ec15257e950b3930e0a3f034466e8dfb AS basealt
RUN groupadd --gid 1001 nonroot-user && useradd nonroot-user --uid 1001 --gid 1001 --shell /bin/bash --create-home

FROM basealt AS builder

RUN apt-get update

RUN apt-get install -y \
git curl pkg-config \
libvirt-libs libtool libvirt-devel libncurses-devel \
libvirt-client libvirt-daemon libvirt \
gcc gcc-c++ glibc-devel-static \
glibc \
golang && \
apt-get clean && \
rm --recursive --force /var/lib/apt/lists/ftp.altlinux.org* /var/cache/apt/*.bin

ENV VERSION="1.3.1"
ENV GOVERSION="1.22.7"

RUN mkdir /kubevirt-config-files && echo "v$VERSION-dirty" > /kubevirt-config-files/.version

RUN go install github.com/go-delve/delve/cmd/dlv@latest

RUN git clone --depth 1 --branch v$VERSION https://github.com/kubevirt/kubevirt.git /kubevirt
COPY ./images/virt-artifact/patches /patches
WORKDIR /kubevirt
RUN for p in /patches/*.patch ; do git apply --ignore-space-change --ignore-whitespace ${p} && echo OK || (echo FAIL ; exit 1) ; done

RUN go mod edit -go=$GOVERSION && \
go mod download

RUN go mod vendor

ENV GO111MODULE=on
ENV GOOS=linux
ENV CGO_ENABLED=1
ENV GOARCH=amd64

RUN go build -o /kubevirt-binaries/virt-handler ./cmd/virt-handler/
RUN gcc -static cmd/container-disk-v2alpha/main.c -o /kubevirt-binaries/container-disk
RUN go build -o /kubevirt-binaries/virt-chroot ./cmd/virt-chroot/

FROM basealt

RUN apt-get update && apt-get install --yes \
acl \
procps \
nftables \
qemu-img==9.0.2-alt3 \
xorriso==1.5.6-alt1 && \
apt-get clean && \
rm --recursive --force /var/lib/apt/lists/ftp.altlinux.org* /var/cache/apt/*.bin

COPY --from=builder /kubevirt/cmd/virt-handler/virt_launcher.cil /virt_launcher.cil
COPY --from=builder /kubevirt-config-files/.version /.version
COPY --from=builder /kubevirt/cmd/virt-handler/nsswitch.conf /etc/nsswitch.conf

COPY --from=builder /kubevirt-binaries/virt-handler /usr/bin/virt-handler
COPY --from=builder /kubevirt-binaries/virt-chroot /usr/bin/virt-chroot
COPY --from=builder /kubevirt-binaries/container-disk /usr/bin/container-disk
COPY --from=builder /root/go/bin/dlv /usr/bin/dlv

ENTRYPOINT ["/usr/bin/dlv", "--listen=:2345", "--headless=true", "--continue", "--log=true", "--log-output=debugger,debuglineerr,gdbwire,lldbout,rpc", "--accept-multiclient", "--api-version=2", "exec", "/usr/bin/virt-handler", "--"]

0 comments on commit 3c86dad

Please sign in to comment.