integration: set otel socket path through buildkit config

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-09-26 19:16:59 +02:00
parent 28a9fd5528
commit 5db24ae99b
4 changed files with 51 additions and 37 deletions

View File

@@ -57,8 +57,8 @@ type Sandbox interface {
// BackendConfig is used to configure backends created by a worker.
type BackendConfig struct {
Logs map[string]*bytes.Buffer
ConfigFile string
Logs map[string]*bytes.Buffer
DaemonConfig []ConfigUpdater
}
type Worker interface {
@@ -303,7 +303,7 @@ mirrors=["%s"]
`, in, mc)
}
func writeConfig(updaters []ConfigUpdater) (string, error) {
func WriteConfig(updaters []ConfigUpdater) (string, error) {
tmpdir, err := os.MkdirTemp("", "bktest_config")
if err != nil {
return "", err
@@ -320,7 +320,7 @@ func writeConfig(updaters []ConfigUpdater) (string, error) {
if err := os.WriteFile(filepath.Join(tmpdir, buildkitdConfigFile), []byte(s), 0644); err != nil {
return "", err
}
return tmpdir, nil
return filepath.Join(tmpdir, buildkitdConfigFile), nil
}
func runMirror(t *testing.T, mirroredImages map[string]string) (host string, _ func() error, err error) {

View File

@@ -7,7 +7,6 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
@@ -78,15 +77,14 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
Logs: make(map[string]*bytes.Buffer),
}
var upt []ConfigUpdater
for _, v := range mv.values {
if u, ok := v.value.(ConfigUpdater); ok {
upt = append(upt, u)
cfg.DaemonConfig = append(cfg.DaemonConfig, u)
}
}
if mirror != "" {
upt = append(upt, withMirrorConfig(mirror))
cfg.DaemonConfig = append(cfg.DaemonConfig, withMirrorConfig(mirror))
}
deferF := &MultiCloser{}
@@ -99,17 +97,6 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
}
}()
if len(upt) > 0 {
dir, err := writeConfig(upt)
if err != nil {
return nil, nil, err
}
deferF.Append(func() error {
return os.RemoveAll(dir)
})
cfg.ConfigFile = filepath.Join(dir, buildkitdConfigFile)
}
b, closer, err := w.New(ctx, cfg)
if err != nil {
return nil, nil, err

View File

@@ -76,9 +76,27 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
return nil, nil, err
}
bkcfg, err := config.LoadFile(cfg.ConfigFile)
deferF := &integration.MultiCloser{}
cl = deferF.F()
defer func() {
if err != nil {
deferF.F()()
cl = nil
}
}()
cfgFile, err := integration.WriteConfig(cfg.DaemonConfig)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to load buildkit config file %s", cfg.ConfigFile)
return nil, nil, err
}
deferF.Append(func() error {
return os.RemoveAll(filepath.Dir(cfgFile))
})
bkcfg, err := config.LoadFile(cfgFile)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to load buildkit config file %s", cfgFile)
}
dcfg := dockerd.Config{
@@ -107,16 +125,6 @@ func (c Moby) New(ctx context.Context, cfg *integration.BackendConfig) (b integr
return nil, nil, errors.Wrapf(err, "failed to marshal dockerd config")
}
deferF := &integration.MultiCloser{}
cl = deferF.F()
defer func() {
if err != nil {
deferF.F()()
cl = nil
}
}()
var proxyGroup errgroup.Group
deferF.Append(proxyGroup.Wait)

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
@@ -32,10 +33,6 @@ func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []s
}
}()
if conf.ConfigFile != "" {
args = append(args, "--config="+conf.ConfigFile)
}
tmpdir, err := os.MkdirTemp("", "bktest_buildkitd")
if err != nil {
return "", nil, err
@@ -49,12 +46,20 @@ func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []s
if err := os.Chown(filepath.Join(tmpdir, "tmp"), uid, gid); err != nil {
return "", nil, err
}
deferF.Append(func() error { return os.RemoveAll(tmpdir) })
cfgfile, err := integration.WriteConfig(append(conf.DaemonConfig, withOTELSocketPath(getTraceSocketPath(tmpdir))))
if err != nil {
return "", nil, err
}
deferF.Append(func() error {
return os.RemoveAll(filepath.Dir(cfgfile))
})
args = append(args, "--config="+cfgfile)
address = getBuildkitdAddr(tmpdir)
args = append(args, "--root", tmpdir, "--addr", address, "--otel-socket-path", getTraceSocketPath(tmpdir), "--debug")
args = append(args, "--root", tmpdir, "--addr", address, "--debug")
cmd := exec.Command(args[0], args[1:]...) //nolint:gosec // test utility
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "TMPDIR="+filepath.Join(tmpdir, "tmp"))
cmd.Env = append(cmd.Env, extraEnv...)
@@ -87,3 +92,17 @@ func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []s
return address, cl, err
}
func withOTELSocketPath(socketPath string) integration.ConfigUpdater {
return otelSocketPath(socketPath)
}
type otelSocketPath string
func (osp otelSocketPath) UpdateConfigFile(in string) string {
return fmt.Sprintf(`%s
[otel]
socketPath = %q
`, in, osp)
}