Skip to content

Commit 2a24a5f

Browse files
chore: update delve to 1.7.2 (#88)
Pull in go-delve/delve#2684 to warn on unsupported Go versions Support Go 1.13 and 1.14 by defaulting `--check-go-version` to false Co-authored-by: Brian de Alwis <[email protected]>
1 parent bf07473 commit 2a24a5f

File tree

5 files changed

+232
-20
lines changed

5 files changed

+232
-20
lines changed

go/helper-image/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARG BUILDPLATFORM
44
ARG TARGETOS
55
ARG TARGETARCH
66

7-
ARG DELVE_VERSION=1.6.0
7+
ARG DELVE_VERSION=1.7.2
88

99
RUN curl --location --output delve-$DELVE_VERSION.tar.gz https://github.com/go-delve/delve/archive/v$DELVE_VERSION.tar.gz \
1010
&& tar xzf delve-$DELVE_VERSION.tar.gz \
@@ -13,10 +13,11 @@ RUN curl --location --output delve-$DELVE_VERSION.tar.gz https://github.com/go-d
1313
# Patch delve to change default for --only-same-user to false
1414
# Required as `kubectl port-forward` to dlv port is refused.
1515
# We must install patch(1) to apply the patch.
16-
COPY delve-only-same-user.patch .
16+
COPY delve-*.patch .
1717
RUN apt-get update && apt-get install -y --no-install-recommends \
1818
patch \
19-
&& patch -p0 -d delve-source < delve-only-same-user.patch
19+
&& patch -p0 -d delve-source < delve-only-same-user.patch \
20+
&& patch -p0 -d delve-source < delve-pr2684.patch
2021

2122
# Produce an as-static-as-possible dlv binary to work on musl and glibc
2223
RUN cd delve-source && CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /go/dlv -ldflags '-s -w -extldflags "-static"' ./cmd/dlv/

go/helper-image/delve-only-same-user.patch

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ the outside of the pod, and so connecting to the dlv port is refused.
44

55
[1] https://github.com/go-delve/delve/pull/1764
66

7-
--- cmd/dlv/cmds/commands.go
8-
+++ cmd/dlv/cmds/commands.go
9-
@@ -114,7 +114,7 @@ func New(docCall bool) *cobra.Command {
10-
rootCommand.PersistentFlags().StringVar(&buildFlags, "build-flags", buildFlagsDefault, "Build flags, to be passed to the compiler.")
11-
rootCommand.PersistentFlags().StringVar(&workingDir, "wd", ".", "Working directory for running the program.")
12-
rootCommand.PersistentFlags().BoolVarP(&checkGoVersion, "check-go-version", "", true, "Checks that the version of Go in use is compatible with Delve.")
7+
--- cmd/dlv/cmds/commands.go.orig 2021-09-23 00:05:04.000000000 -0400
8+
+++ cmd/dlv/cmds/commands.go 2021-10-30 22:03:43.000000000 -0400
9+
@@ -130,8 +130,8 @@
10+
rootCommand.PersistentFlags().StringVar(&initFile, "init", "", "Init file, executed by the terminal client.")
11+
rootCommand.PersistentFlags().StringVar(&buildFlags, "build-flags", buildFlagsDefault, "Build flags, to be passed to the compiler. For example: --build-flags=\"-tags=integration -mod=vendor -cover -v\"")
12+
rootCommand.PersistentFlags().StringVar(&workingDir, "wd", "", "Working directory for running the program.")
13+
- rootCommand.PersistentFlags().BoolVarP(&checkGoVersion, "check-go-version", "", true, "Checks that the version of Go in use is compatible with Delve.")
1314
- rootCommand.PersistentFlags().BoolVarP(&checkLocalConnUser, "only-same-user", "", true, "Only connections from the same user that started this instance of Delve are allowed to connect.")
15+
+ rootCommand.PersistentFlags().BoolVarP(&checkGoVersion, "check-go-version", "", false, "Checks that the version of Go in use is compatible with Delve.")
1416
+ rootCommand.PersistentFlags().BoolVarP(&checkLocalConnUser, "only-same-user", "", false, "Only connections from the same user that started this instance of Delve are allowed to connect.")
1517
rootCommand.PersistentFlags().StringVar(&backend, "backend", "default", `Backend selection (see 'dlv help backend').`)
16-
17-
// 'attach' subcommand.
18+
rootCommand.PersistentFlags().StringArrayVarP(&redirects, "redirect", "r", []string{}, "Specifies redirect rules for target process (see 'dlv help redirect')")
19+
rootCommand.PersistentFlags().BoolVar(&allowNonTerminalInteractive, "allow-non-terminal-interactive", false, "Allows interactive sessions of Delve that don't have a terminal as stdin, stdout and stderr")

go/helper-image/delve-pr2684.patch

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
This patch corresponds to PR 2684 that causes Delve to warn when
2+
debugging programs built with an unsupported Go version. This patch
3+
drops the documentation changes as they did not apply cleanly to 1.7.2.
4+
5+
https://github.com/go-delve/delve/pull/2684
6+
https://github.com/go-delve/delve/commit/efc44831754e5e66b66ec7375a3ca424426310ad
7+
8+
9+
commit efc44831754e5e66b66ec7375a3ca424426310ad
10+
Author: polinasok <[email protected]>
11+
Date: Sat Sep 25 08:41:00 2021 -0700
12+
13+
pkg/goversion: visibly warn the user with --check-go-version=false (#2684)
14+
15+
16+
Co-authored-by: Polina Sokolova <[email protected]>
17+
18+
diff --git pkg/goversion/compat.go pkg/goversion/compat.go
19+
index b19528eb..053ae138 100644
20+
--- pkg/goversion/compat.go
21+
+++ pkg/goversion/compat.go
22+
@@ -2,6 +2,8 @@ package goversion
23+
24+
import (
25+
"fmt"
26+
+
27+
+ "github.com/go-delve/delve/pkg/logflags"
28+
)
29+
30+
var (
31+
@@ -9,22 +11,33 @@ var (
32+
MinSupportedVersionOfGoMinor = 15
33+
MaxSupportedVersionOfGoMajor = 1
34+
MaxSupportedVersionOfGoMinor = 17
35+
- goTooOldErr = fmt.Errorf("Version of Go is too old for this version of Delve (minimum supported version %d.%d, suppress this error with --check-go-version=false)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor)
36+
- dlvTooOldErr = fmt.Errorf("Version of Delve is too old for this version of Go (maximum supported version %d.%d, suppress this error with --check-go-version=false)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor)
37+
+ goTooOldErr = fmt.Sprintf("Go version %%s is too old for this version of Delve (minimum supported version %d.%d, suppress this error with --check-go-version=false)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor)
38+
+ goTooOldWarn = fmt.Sprintf("WARNING: undefined behavior - Go version %%s is too old for this version of Delve (minimum supported version %d.%d)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor)
39+
+ dlvTooOldErr = fmt.Sprintf("Version of Delve is too old for Go version %%s (maximum supported version %d.%d, suppress this error with --check-go-version=false)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor)
40+
+ dlvTooOldWarn = fmt.Sprintf("WARNING: undefined behavior - version of Delve is too old for Go version %%s (maximum supported version %d.%d)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor)
41+
)
42+
43+
// Compatible checks that the version specified in the producer string is compatible with
44+
// this version of delve.
45+
-func Compatible(producer string) error {
46+
+func Compatible(producer string, warnonly bool) error {
47+
ver := ParseProducer(producer)
48+
if ver.IsDevel() {
49+
return nil
50+
}
51+
+ verstr := fmt.Sprintf("%d.%d.%d", ver.Major, ver.Minor, ver.Rev)
52+
if !ver.AfterOrEqual(GoVersion{MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor, -1, 0, 0, ""}) {
53+
- return goTooOldErr
54+
+ if warnonly {
55+
+ logflags.WriteError(fmt.Sprintf(goTooOldWarn, verstr))
56+
+ return nil
57+
+ }
58+
+ return fmt.Errorf(goTooOldErr, verstr)
59+
}
60+
if ver.AfterOrEqual(GoVersion{MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor + 1, -1, 0, 0, ""}) {
61+
- return dlvTooOldErr
62+
+ if warnonly {
63+
+ logflags.WriteError(fmt.Sprintf(dlvTooOldWarn, verstr))
64+
+ return nil
65+
+ }
66+
+ return fmt.Errorf(dlvTooOldErr, verstr)
67+
}
68+
return nil
69+
}
70+
diff --git pkg/logflags/logflags.go pkg/logflags/logflags.go
71+
index 756e7ae6..db34e502 100644
72+
--- pkg/logflags/logflags.go
73+
+++ pkg/logflags/logflags.go
74+
@@ -136,6 +136,14 @@ func writeListeningMessage(server, addr string) {
75+
}
76+
}
77+
78+
+func WriteError(msg string) {
79+
+ if logOut != nil {
80+
+ fmt.Fprintln(logOut, msg)
81+
+ } else {
82+
+ fmt.Fprintln(os.Stderr, msg)
83+
+ }
84+
+}
85+
+
86+
var errLogstrWithoutLog = errors.New("--log-output specified without --log")
87+
88+
// Setup sets debugger flags based on the contents of logstr.
89+
diff --git service/debugger/debugger.go service/debugger/debugger.go
90+
index bb74c9ac..400fdcdd 100644
91+
--- service/debugger/debugger.go
92+
+++ service/debugger/debugger.go
93+
@@ -223,9 +223,6 @@ func (d *Debugger) canRestart() bool {
94+
}
95+
96+
func (d *Debugger) checkGoVersion() error {
97+
- if !d.config.CheckGoVersion {
98+
- return nil
99+
- }
100+
if d.isRecording() {
101+
// do not do anything if we are still recording
102+
return nil
103+
@@ -234,7 +231,7 @@ func (d *Debugger) checkGoVersion() error {
104+
if producer == "" {
105+
return nil
106+
}
107+
- return goversion.Compatible(producer)
108+
+ return goversion.Compatible(producer, !d.config.CheckGoVersion)
109+
}
110+
111+
func (d *Debugger) TargetGoVersion() string {

go/skaffold.yaml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ metadata:
66
requires:
77
- path: ../integration
88
activeProfiles:
9-
- name: integration
10-
activatedBy: [integration]
9+
- name: integration
10+
activatedBy: [integration]
1111

1212
build:
1313
local:
1414
useBuildkit: true
1515
artifacts:
16-
- image: skaffold-debug-go
17-
context: helper-image
18-
custom:
19-
buildCommand: ../../buildx.sh
16+
- image: skaffold-debug-go
17+
context: helper-image
18+
custom:
19+
buildCommand: ../../buildx.sh
2020

2121
test:
2222
- image: skaffold-debug-go
@@ -26,10 +26,9 @@ deploy:
2626
logs:
2727
prefix: auto
2828
kubectl:
29-
manifests: [] # overwritten in integration profile
29+
manifests: [] # overwritten in integration profile
3030

3131
profiles:
32-
3332
# local: never push to remote registries
3433
- name: local
3534
build:
@@ -71,13 +70,22 @@ profiles:
7170
docker:
7271
buildArgs:
7372
GOVERSION: 1.16
73+
- op: add
74+
path: /build/artifacts/-
75+
value:
76+
image: go117app
77+
context: test/goapp
78+
docker:
79+
buildArgs:
80+
GOVERSION: 1.17
7481
deploy:
7582
kubectl:
7683
manifests:
7784
- test/k8s-test-go113.yaml
7885
- test/k8s-test-go114.yaml
7986
- test/k8s-test-go115.yaml
8087
- test/k8s-test-go116.yaml
88+
- test/k8s-test-go117.yaml
8189

8290
# release: pushes images to production with :latest
8391
- name: release
@@ -100,4 +108,3 @@ profiles:
100108
path: /test/0/image
101109
from: skaffold-debug-go
102110
value: go
103-

go/test/k8s-test-go117.yaml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# This test approximates `skaffold debug` for a go app.
2+
apiVersion: v1
3+
kind: Pod
4+
metadata:
5+
name: go117pod
6+
labels:
7+
app: hello
8+
protocol: dlv
9+
runtime: go117
10+
spec:
11+
containers:
12+
- name: go117app
13+
image: go117app
14+
args:
15+
- /dbg/go/bin/dlv
16+
- exec
17+
- --log
18+
- --headless
19+
- --continue
20+
- --accept-multiclient
21+
# listen on 0.0.0.0 as it is exposed as a service
22+
- --listen=0.0.0.0:56286
23+
- --api-version=2
24+
- ./app
25+
ports:
26+
- containerPort: 8080
27+
- containerPort: 56286
28+
name: dlv
29+
readinessProbe:
30+
httpGet:
31+
path: /
32+
port: 8080
33+
volumeMounts:
34+
- mountPath: /dbg
35+
name: go-debugging-support
36+
initContainers:
37+
- image: skaffold-debug-go
38+
name: install-go-support
39+
resources: {}
40+
volumeMounts:
41+
- mountPath: /dbg
42+
name: go-debugging-support
43+
volumes:
44+
- emptyDir: {}
45+
name: go-debugging-support
46+
47+
---
48+
apiVersion: v1
49+
kind: Service
50+
metadata:
51+
name: hello-dlv-go117
52+
spec:
53+
ports:
54+
- name: http
55+
port: 8080
56+
protocol: TCP
57+
- name: dlv
58+
port: 56286
59+
protocol: TCP
60+
selector:
61+
app: hello
62+
protocol: dlv
63+
runtime: go117
64+
65+
---
66+
apiVersion: batch/v1
67+
kind: Job
68+
metadata:
69+
name: connect-to-go117
70+
labels:
71+
project: container-debug-support
72+
type: integration-test
73+
spec:
74+
ttlSecondsAfterFinished: 10
75+
backoffLimit: 1
76+
template:
77+
spec:
78+
restartPolicy: Never
79+
initContainers:
80+
- name: wait-for-go117pod
81+
image: kubectl
82+
command: [sh, -c, "while ! curl -s hello-dlv-go117:8080 2>/dev/null; do echo waiting for app; sleep 1; done"]
83+
containers:
84+
- name: dlv-to-go117
85+
image: skaffold-debug-go
86+
command: [sh, -c, '
87+
(echo bt; echo exit -c) > init.txt;
88+
set -x;
89+
/duct-tape/go/bin/dlv connect --init init.txt hello-dlv-go117:56286']
90+
91+

0 commit comments

Comments
 (0)