Skip to content

Commit c7318df

Browse files
authored
Merge pull request moby#4078 from crazy-max/fix-otel-sock
set tracing socket path to runtime dir
2 parents ffbc1ce + b57eeb2 commit c7318df

File tree

10 files changed

+48
-30
lines changed

10 files changed

+48
-30
lines changed

cmd/buildkitd/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,11 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err
661661

662662
var traceSocket string
663663
if tc != nil {
664-
traceSocket = traceSocketPath(cfg.Root)
664+
if v, ok := os.LookupEnv("BUILDKIT_TRACE_SOCKET"); ok {
665+
traceSocket = v
666+
} else {
667+
traceSocket = appdefaults.TraceSocketPath(userns.RunningInUserNS())
668+
}
665669
if err := runTraceController(traceSocket, tc); err != nil {
666670
return nil, err
667671
}

cmd/buildkitd/main_unix.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"crypto/tls"
88
"net"
99
"os"
10-
"path/filepath"
1110
"syscall"
1211

1312
"github.com/containerd/containerd/sys"
@@ -47,10 +46,6 @@ func listenFD(addr string, tlsConfig *tls.Config) (net.Listener, error) {
4746
return nil, errors.New("not supported yet")
4847
}
4948

50-
func traceSocketPath(root string) string {
51-
return filepath.Join(root, "otel-grpc.sock")
52-
}
53-
5449
func getLocalListener(listenerPath string) (net.Listener, error) {
5550
uid := os.Getuid()
5651
l, err := sys.GetLocalListener(listenerPath, uid, uid)

cmd/buildkitd/main_windows.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@ import (
1313
"github.com/pkg/errors"
1414
)
1515

16-
const (
17-
defaultTraceSocketPath = `\\.\pipe\buildkit-otel-grpc`
18-
)
19-
2016
func listenFD(addr string, tlsConfig *tls.Config) (net.Listener, error) {
2117
return nil, errors.New("listening server on fd not supported on windows")
2218
}
2319

24-
func traceSocketPath(root string) string {
25-
return defaultTraceSocketPath
26-
}
27-
2820
func getLocalListener(listenerPath string) (net.Listener, error) {
2921
pc := &winio.PipeConfig{
3022
// Allow generic read and generic write access to authenticated users

util/appdefaults/appdefaults_unix.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,13 @@ func UserConfigDir() string {
7070
}
7171
return ConfigDir
7272
}
73+
74+
func TraceSocketPath(inUserNS bool) string {
75+
if inUserNS {
76+
if xrd := os.Getenv("XDG_RUNTIME_DIR"); xrd != "" {
77+
dirs := strings.Split(xrd, ":")
78+
return filepath.Join(dirs[0], "buildkit", "otel-grpc.sock")
79+
}
80+
}
81+
return "/run/buildkit/otel-grpc.sock"
82+
}

util/appdefaults/appdefaults_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ func UserRoot() string {
3131
func UserConfigDir() string {
3232
return ConfigDir
3333
}
34+
35+
func TraceSocketPath(inUserNS bool) string {
36+
return `\\.\pipe\buildkit-otel-grpc`
37+
}

util/testutil/integration/containerd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ disabled_plugins = ["cri"]
168168
containerdArgs := []string{c.Containerd, "--config", configFile}
169169
rootlessKitState := filepath.Join(tmpdir, "rootlesskit-containerd")
170170
if rootless {
171-
containerdArgs = append(append([]string{"sudo", "-u", fmt.Sprintf("#%d", c.UID), "-i",
171+
containerdArgs = append(append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i",
172172
fmt.Sprintf("CONTAINERD_ROOTLESS_ROOTLESSKIT_STATE_DIR=%s", rootlessKitState),
173173
// Integration test requires the access to localhost of the host network namespace.
174174
// TODO: remove these configurations
@@ -211,7 +211,7 @@ disabled_plugins = ["cri"]
211211
if err != nil {
212212
return nil, nil, err
213213
}
214-
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
214+
buildkitdArgs = append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
215215
"nsenter", "-U", "--preserve-credentials", "-m", "-t", fmt.Sprintf("%d", pid)},
216216
append(buildkitdArgs, "--containerd-worker-snapshotter=native")...)
217217
}

util/testutil/integration/oci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *OCI) New(ctx context.Context, cfg *BackendConfig) (Backend, func() erro
6565
return nil, nil, errors.Errorf("unsupported id pair: uid=%d, gid=%d", s.UID, s.GID)
6666
}
6767
// TODO: make sure the user exists and subuid/subgid are configured.
68-
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
68+
buildkitdArgs = append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
6969
}
7070

7171
var extraEnv []string

util/testutil/integration/sandbox.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"os"
99
"os/exec"
1010
"path/filepath"
11-
"runtime"
1211
"strings"
1312
"testing"
1413
"time"
@@ -181,14 +180,6 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
181180
}, cl, nil
182181
}
183182

184-
func getBuildkitdAddr(tmpdir string) string {
185-
address := "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
186-
if runtime.GOOS == "windows" {
187-
address = "//./pipe/buildkitd-" + filepath.Base(tmpdir)
188-
}
189-
return address
190-
}
191-
192183
func runBuildkitd(ctx context.Context, conf *BackendConfig, args []string, logs map[string]*bytes.Buffer, uid, gid int, extraEnv []string) (address string, cl func() error, err error) {
193184
deferF := &multiCloser{}
194185
cl = deferF.F()
@@ -224,7 +215,7 @@ func runBuildkitd(ctx context.Context, conf *BackendConfig, args []string, logs
224215

225216
args = append(args, "--root", tmpdir, "--addr", address, "--debug")
226217
cmd := exec.Command(args[0], args[1:]...) //nolint:gosec // test utility
227-
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "TMPDIR="+filepath.Join(tmpdir, "tmp"))
218+
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "BUILDKIT_TRACE_SOCKET="+getTraceSocketPath(tmpdir), "TMPDIR="+filepath.Join(tmpdir, "tmp"))
228219
cmd.Env = append(cmd.Env, extraEnv...)
229220
cmd.SysProcAttr = getSysProcAttr()
230221

@@ -269,7 +260,7 @@ func getBackend(sb Sandbox) (*backend, error) {
269260
}
270261

271262
func rootlessSupported(uid int) bool {
272-
cmd := exec.Command("sudo", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
263+
cmd := exec.Command("sudo", "-E", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
273264
b, err := cmd.CombinedOutput()
274265
if err != nil {
275266
bklog.L.Warnf("rootless mode is not supported on this host: %v (%s)", err, string(b))

util/testutil/integration/sandbox_unix.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33

44
package integration
55

6-
import "syscall"
6+
import (
7+
"path/filepath"
8+
"syscall"
9+
)
710

811
func getSysProcAttr() *syscall.SysProcAttr {
912
return &syscall.SysProcAttr{
1013
Setsid: true, // stretch sudo needs this for sigterm
1114
}
1215
}
16+
17+
func getBuildkitdAddr(tmpdir string) string {
18+
return "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
19+
}
20+
21+
func getTraceSocketPath(tmpdir string) string {
22+
return filepath.Join(tmpdir, "otel-grpc.sock")
23+
}

util/testutil/integration/sandbox_windows.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33

44
package integration
55

6-
import "syscall"
6+
import (
7+
"path/filepath"
8+
"syscall"
9+
)
710

811
func getSysProcAttr() *syscall.SysProcAttr {
912
return &syscall.SysProcAttr{}
1013
}
14+
15+
func getBuildkitdAddr(tmpdir string) string {
16+
return "//./pipe/buildkitd-" + filepath.Base(tmpdir)
17+
}
18+
19+
func getTraceSocketPath(tmpdir string) string {
20+
return `\\.\pipe\buildkit-otel-grpc-` + filepath.Base(tmpdir)
21+
}

0 commit comments

Comments
 (0)