Skip to content

Commit

Permalink
add dlv for virt-controller
Browse files Browse the repository at this point in the history
Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat committed Nov 13, 2024
1 parent dde4eb7 commit 20a2253
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ vars:
target: ""
VALIDATION_FILES: "tools/validation/{main,messages,diff,no_cyrillic,doc_changes,copyright}.go"

DLV_IMAGE:
sh: if [ -z $DLV_IMAGE ]; then echo "ttl.sh/$(uuidgen | awk '{print tolower($0)}'):10m" ; else echo $DLV_IMAGE ; fi

tasks:
check-werf:
cmds:
Expand Down Expand Up @@ -147,3 +150,36 @@ tasks:
cmds:
- task: cve:bin
- tools/cve/scan-main.sh {{.REPORT_FILE_NAME}}

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

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

dlv:virt-controller:print:
desc: "Print subcommands for debug"
env:
IMAGE: "{{ .DLV_IMAGE }}"
cmd: |
cat <<EOF
kubectl -n d8-virtualization patch deploy virt-controller --type='strategic' -p '{
"spec": {
"template": {
"spec": {
"containers": [ {
"name": "virt-controller",
"image": "${IMAGE}",
"ports": [ { "containerPort": 2345, "name": "dlv" } ]
}]
}
}
}
}'
EOF
echo 'kubectl -n d8-virtualization port-forward $(kubectl -n d8-virtualization get pod -l kubevirt.internal.virtualization.deckhouse.io=virt-controller -oname | head -1) 2345:2345'
31 changes: 31 additions & 0 deletions images/virt-controller/debug/dlv.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM golang:1.22.7 AS builder

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

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=0
ENV GOARCH=amd64

RUN go build -o /kubevirt-binaries/virt-controller ./cmd/virt-controller/

FROM busybox

WORKDIR /app
COPY --from=builder /kubevirt-binaries/virt-controller /app/virt-controller
COPY --from=builder /go/bin/dlv /app/dlv
USER 65532:65532
ENTRYPOINT ["./dlv", "--listen=:2345", "--headless=true", "--continue", "--log=true", "--log-output=debugger,debuglineerr,gdbwire,lldbout,rpc", "--accept-multiclient", "--api-version=2", "exec", "/app/virt-controller", "--"]

0 comments on commit 20a2253

Please sign in to comment.