Skip to content

Commit 591acec

Browse files
authored
Debug mode for DLV debugger (#869)
* Debug mode for DLV debugger * Changelog update
1 parent 94ed378 commit 591acec

File tree

8 files changed

+84
-16
lines changed

8 files changed

+84
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Remove unused `status.members.<group>.sidecars-specs` variable
77
- Keep only recent terminations
88
- Add endpoint into member status
9+
- Add debug mode (Golang DLV)
910

1011
## [1.2.6](https://github.com/arangodb/kube-arangodb/tree/1.2.6) (2021-12-15)
1112
- Add ArangoBackup backoff functionality

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ ARG RELEASE_MODE=community
1616
ARG TARGETARCH=amd64
1717
ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator /usr/bin/arangodb_operator
1818

19-
ENTRYPOINT [ "/usr/bin/arangodb_operator" ]
19+
ENTRYPOINT [ "/usr/bin/arangodb_operator" ]

Dockerfile.debug

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM golang:1.16 as builder
2+
3+
ARG TARGETARCH
4+
5+
RUN apt-get update && apt-get install -y build-essential
6+
RUN go install github.com/go-delve/delve/cmd/dlv@latest
7+
8+
FROM alpine:3.14 as artifact
9+
10+
ARG RELEASE_MODE
11+
ARG TARGETARCH
12+
ARG VERSION
13+
14+
LABEL name="kube-arangodb" \
15+
vendor="ArangoDB" \
16+
version="${VERSION}" \
17+
release="${VERSION}" \
18+
summary="ArangoDB Kubernetes Oparator" \
19+
description="ArangoDB Kubernetes Operator" \
20+
maintainer="redhat@arangodb.com"
21+
22+
RUN apk add --no-cache libc6-compat
23+
24+
ADD ./LICENSE /licenses/LICENSE
25+
ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator /usr/bin/arangodb_operator
26+
27+
COPY --from=builder /go/bin/dlv /usr/bin/dlv
28+
29+
ENTRYPOINT ["/usr/bin/dlv", "--listen=:2345", "--headless=true", "--continue", "--accept-multiclient", "--api-version=2", "exec", "/usr/bin/arangodb_operator", "--" ]
30+

MAINTAINERS.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ To run only a single test, set `TESTOPTIONS` to something like
3333
`-test.run=TestRocksDBEncryptionSingle` where
3434
`TestRocksDBEncryptionSingle` is the name of the test.
3535

36+
## Debugging with DLV
37+
38+
To attach DLV debugger, first prepare operator image with DLV server included:
39+
```shell
40+
IMAGETAG=1.2.4dlv DEBUG=true make docker
41+
```
42+
43+
Then deploy it on your k8s and use following command to access DLV server on `localhost:2345` from your local machine:
44+
```shell
45+
kubectl port-forward deployment/arango-arango-deployment-operator 2345
46+
```
47+
3648
## Preparing a release
3749

3850
To prepare for a release, do the following:
@@ -76,3 +88,17 @@ If the release process fails, it may leave:
7688
To resolve remove it using `git tag -d ...`.
7789
- A git tag named `<major>.<minor>.<patch>` in this repository in github.
7890
To resolve remove it manually.
91+
92+
## Development on MacOS
93+
94+
This repo requires GNU command line tools instead BSD one (which are by default available on Mac).
95+
```shell
96+
brew install coreutils ed findutils gawk gnu-sed gnu-tar grep make
97+
```
98+
99+
Please add following to your `~/bashrc` or `~/.zshrc` file (it requires Homebrew to be installed):
100+
101+
```shell
102+
HOMEBREW_PREFIX=$(brew --prefix)
103+
for d in ${HOMEBREW_PREFIX}/opt/*/libexec/gnubin; do export PATH=$d:$PATH; done
104+
```

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ GOASSETSBUILDER := $(GOBUILDDIR)/bin/go-assets-builder$(shell go env GOEXE)
3939

4040
BUILDTIME = $(shell go run "$(ROOT)/tools/dategen/")
4141

42-
DOCKERFILE := Dockerfile
43-
4442
HELM ?= $(shell which helm)
4543

4644
UPPER = $(shell echo '$1' | tr '[:lower:]' '[:upper:]')
@@ -62,6 +60,7 @@ HELM_CMD = $(HELM) template "$(ROOTDIR)/chart/$(CHART_NAME)" \
6260
--set "operator.image=$(OPERATORIMAGE)" \
6361
--set "operator.imagePullPolicy=Always" \
6462
--set "operator.resources=null" \
63+
--set "operator.debug=$(DEBUG)" \
6564
--namespace "$(DEPLOYMENTNAMESPACE)"
6665

6766
ifndef LOCALONLY
@@ -74,6 +73,17 @@ else
7473
IMAGESUFFIX := :dev
7574
endif
7675

76+
ifdef DEBUG
77+
DEBUG := true
78+
DOCKERFILE := Dockerfile.debug
79+
# required by DLV https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_exec.md
80+
COMPILE_DEBUG_FLAGS := -gcflags="all=-N -l"
81+
else
82+
DEBUG := false
83+
DOCKERFILE := Dockerfile
84+
COMPILE_DEBUG_FLAGS :=
85+
endif
86+
7787
ifeq ($(MANIFESTSUFFIX),-)
7888
# Release setting
7989
MANIFESTSUFFIX :=
@@ -257,11 +267,11 @@ bin-all: $(BIN) $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64)
257267

258268
$(VBIN_LINUX_AMD64): $(SOURCES) dashboard/assets.go VERSION
259269
@mkdir -p $(BINDIR)/$(RELEASE_MODE)/linux/amd64
260-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --tags "$(RELEASE_MODE)" -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_LINUX_AMD64) ./
270+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --tags "$(RELEASE_MODE)" $(COMPILE_DEBUG_FLAGS) -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_LINUX_AMD64) ./
261271

262272
$(VBIN_LINUX_ARM64): $(SOURCES) dashboard/assets.go VERSION
263273
@mkdir -p $(BINDIR)/$(RELEASE_MODE)/linux/arm64
264-
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build --tags "$(RELEASE_MODE)" -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_LINUX_ARM64) ./
274+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build --tags "$(RELEASE_MODE)" $(COMPILE_DEBUG_FLAGS) -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_LINUX_ARM64) ./
265275

266276
$(BIN): $(VBIN_LINUX_AMD64)
267277
@cp "$(VBIN_LINUX_AMD64)" "$(BIN)"

chart/kube-arangodb/templates/deployment.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ metadata:
2424
app.kubernetes.io/instance: {{ .Release.Name }}
2525
release: {{ .Release.Name }}
2626
spec:
27+
{{- if .Values.operator.debug }}
28+
replicas: 1
29+
{{- else }}
2730
replicas: {{ .Values.operator.replicaCount }}
31+
{{- end }}
2832
strategy:
2933
{{ toYaml .Values.operator.updateStrategy | indent 8 }}
3034
selector:
@@ -134,10 +138,15 @@ spec:
134138
capabilities:
135139
drop:
136140
- 'ALL'
141+
{{- if .Values.operator.debug }}
142+
add:
143+
- 'SYS_PTRACE'
144+
{{- end }}
137145
{{- if .Values.operator.resources }}
138146
resources:
139147
{{ toYaml .Values.operator.resources | indent 22 }}
140148
{{- end }}
149+
{{- if not .Values.operator.debug }}
141150
livenessProbe:
142151
httpGet:
143152
path: /health
@@ -152,6 +161,7 @@ spec:
152161
scheme: HTTPS
153162
initialDelaySeconds: 5
154163
periodSeconds: 10
164+
{{- end }}
155165
tolerations:
156166
- key: "node.kubernetes.io/unreachable"
157167
operator: "Exists"

chart/kube-arangodb/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ operator:
77

88
scope: legacy
99

10+
debug: false
11+
1012
args: []
1113

1214
service:

docs/design/maintenance.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
# Maintenance
22

3-
## Development on MacOS
4-
5-
This repo requires GNU command line tools instead BSD one (which are by default available on Mac).
6-
7-
Please add following to your `~/bashrc` or `~/.zshrc` file (it requires Hombebrew to be installed):
8-
9-
```shell
10-
HOMEBREW_PREFIX=$(brew --prefix)
11-
for d in ${HOMEBREW_PREFIX}/opt/*/libexec/gnubin; do export PATH=$d:$PATH; done
12-
```
13-
143
## ArangoDeployment
154

165
Maintenance on ArangoDeployment can be enabled using annotation.

0 commit comments

Comments
 (0)