Skip to content

Commit ec2d958

Browse files
authored
Merge pull request moby#4101 from crazy-max/fix-rootless-tests
integration: fix rootless tests
2 parents b49a887 + 56c89ea commit ec2d958

File tree

8 files changed

+35
-12
lines changed

8 files changed

+35
-12
lines changed

cmd/buildkitd/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type Config struct {
1717
// GRPC configuration settings
1818
GRPC GRPCConfig `toml:"grpc"`
1919

20+
OTEL OTELConfig `toml:"otel"`
21+
2022
Workers struct {
2123
OCI OCIConfig `toml:"oci"`
2224
Containerd ContainerdConfig `toml:"containerd"`
@@ -46,6 +48,10 @@ type TLSConfig struct {
4648
CA string `toml:"ca"`
4749
}
4850

51+
type OTELConfig struct {
52+
SocketPath string `toml:"socketPath"`
53+
}
54+
4955
type GCConfig struct {
5056
GC *bool `toml:"gc"`
5157
GCKeepStorage DiskSpace `toml:"gckeepstorage"`

cmd/buildkitd/config/load_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ insecure-entitlements = ["security.insecure"]
1818
[gc]
1919
enabled=true
2020
21-
2221
[grpc]
2322
address=["buildkit.sock"]
2423
debugAddress="debug.sock"
2524
gid=1234
2625
[grpc.tls]
2726
cert="mycert.pem"
2827
28+
[otel]
29+
socketPath="/tmp/otel-grpc.sock"
30+
2931
[worker.oci]
3032
enabled=true
3133
snapshotter="overlay"
@@ -83,6 +85,8 @@ searchDomains=["example.com"]
8385
require.Equal(t, 1234, *cfg.GRPC.GID)
8486
require.Equal(t, "mycert.pem", cfg.GRPC.TLS.Cert)
8587

88+
require.Equal(t, "/tmp/otel-grpc.sock", cfg.OTEL.SocketPath)
89+
8690
require.NotNil(t, cfg.Workers.OCI.Enabled)
8791
require.Equal(t, int64(123456789), cfg.Workers.OCI.GCKeepStorage.Bytes)
8892
require.Equal(t, true, *cfg.Workers.OCI.Enabled)

cmd/buildkitd/main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ func main() {
200200
Name: "allow-insecure-entitlement",
201201
Usage: "allows insecure entitlements e.g. network.host, security.insecure",
202202
},
203+
cli.StringFlag{
204+
Name: "otel-socket-path",
205+
Usage: "OTEL collector trace socket path",
206+
},
203207
)
204208
app.Flags = append(app.Flags, appFlags...)
205209
app.Flags = append(app.Flags, serviceFlags()...)
@@ -458,6 +462,10 @@ func setDefaultConfig(cfg *config.Config) {
458462
appdefaults.EnsureUserAddressDir()
459463
}
460464
}
465+
466+
if cfg.OTEL.SocketPath == "" {
467+
cfg.OTEL.SocketPath = appdefaults.TraceSocketPath(userns.RunningInUserNS())
468+
}
461469
}
462470

463471
func applyMainFlags(c *cli.Context, cfg *config.Config) error {
@@ -511,6 +519,11 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error {
511519
if tlsca := c.String("tlscacert"); tlsca != "" {
512520
cfg.GRPC.TLS.CA = tlsca
513521
}
522+
523+
if c.IsSet("otel-socket-path") {
524+
cfg.OTEL.SocketPath = c.String("otel-socket-path")
525+
}
526+
514527
applyPlatformFlags(c)
515528

516529
return nil
@@ -661,11 +674,7 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err
661674

662675
var traceSocket string
663676
if tc != nil {
664-
if v, ok := os.LookupEnv("BUILDKIT_TRACE_SOCKET"); ok {
665-
traceSocket = v
666-
} else {
667-
traceSocket = appdefaults.TraceSocketPath(userns.RunningInUserNS())
668-
}
677+
traceSocket = cfg.OTEL.SocketPath
669678
if err := runTraceController(traceSocket, tc); err != nil {
670679
return nil, err
671680
}

docs/buildkitd.toml.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
2929
key = "/etc/buildkit/tls.key"
3030
ca = "/etc/buildkit/tlsca.crt"
3131

32+
[otel]
33+
# OTEL collector trace socket path
34+
socketPath = "/run/buildkit/otel-grpc.sock"
35+
3236
# config for build history API that stores information about completed build commands
3337
[history]
3438
# maxAge is the maximum age of history entries to keep, in seconds.

util/testutil/integration/sandbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
126126
}
127127

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

util/testutil/workers/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", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i",
171+
containerdArgs = append(append([]string{"sudo", "-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", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
214+
buildkitdArgs = append([]string{"sudo", "-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/workers/oci.go

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

7272
var extraEnv []string

util/testutil/workers/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []s
5454

5555
address = getBuildkitdAddr(tmpdir)
5656

57-
args = append(args, "--root", tmpdir, "--addr", address, "--debug")
57+
args = append(args, "--root", tmpdir, "--addr", address, "--otel-socket-path", getTraceSocketPath(tmpdir), "--debug")
5858
cmd := exec.Command(args[0], args[1:]...) //nolint:gosec // test utility
59-
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"))
59+
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "TMPDIR="+filepath.Join(tmpdir, "tmp"))
6060
cmd.Env = append(cmd.Env, extraEnv...)
6161
cmd.SysProcAttr = getSysProcAttr()
6262

0 commit comments

Comments
 (0)