Skip to content

Commit 9b60c15

Browse files
committed
WIP
Signed-off-by: apostasie <[email protected]>
1 parent 91d3db5 commit 9b60c15

23 files changed

+297
-208
lines changed

Diff for: cmd/nerdctl/container/container_inspect_linux_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/containerd/nerdctl/mod/tigron/expect"
3232
"github.com/containerd/nerdctl/mod/tigron/test"
33+
3334
"github.com/containerd/nerdctl/v2/pkg/infoutil"
3435
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
3536
"github.com/containerd/nerdctl/v2/pkg/labels"

Diff for: cmd/nerdctl/container/container_run_linux_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ func TestRunSigProxy(t *testing.T) {
379379
},
380380

381381
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
382+
// FIXME: os.Interrupt will likely not work on Windows
382383
cmd := nerdtest.RunSigProxyContainer(os.Interrupt, true, nil, data, helpers)
383384
err := cmd.Signal(os.Interrupt)
384385
assert.NilError(helpers.T(), err)
@@ -417,7 +418,7 @@ func TestRunSigProxy(t *testing.T) {
417418
return cmd
418419
},
419420

420-
Expected: test.Expects(127, nil, expect.DoesNotContain(nerdtest.SignalCaught)),
421+
Expected: test.Expects(expect.ExitCodeSignaled, nil, expect.DoesNotContain(nerdtest.SignalCaught)),
421422
},
422423
}
423424

Diff for: cmd/nerdctl/issues/main_linux_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestIssue108(t *testing.T) {
3939
{
4040
Description: "-it --net=host",
4141
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
42-
cmd := helpers.Command("run", "-it", "--rm", "--net=host", testutil.CommonImage, "echo", "this was always working")
42+
cmd := helpers.Command("run", "--quiet", "-it", "--rm", "--net=host", testutil.CommonImage, "echo", "this was always working")
4343
cmd.WithPseudoTTY()
4444
return cmd
4545
},
@@ -48,7 +48,7 @@ func TestIssue108(t *testing.T) {
4848
{
4949
Description: "--net=host -it",
5050
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
51-
cmd := helpers.Command("run", "--rm", "--net=host", "-it", testutil.CommonImage, "echo", "this was not working due to issue #108")
51+
cmd := helpers.Command("run", "--quiet", "--rm", "--net=host", "-it", testutil.CommonImage, "echo", "this was not working due to issue #108")
5252
cmd.WithPseudoTTY()
5353
return cmd
5454
},

Diff for: cmd/nerdctl/system/system_events_linux_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import (
3030

3131
func testEventFilterExecutor(data test.Data, helpers test.Helpers) test.TestableCommand {
3232
cmd := helpers.Command("events", "--filter", data.Get("filter"), "--format", "json")
33-
cmd.WithTimeout(3 * time.Second)
33+
// 3 seconds is too short on slow rig (EL8)
34+
cmd.WithTimeout(10 * time.Second)
3435
cmd.Background()
3536
helpers.Ensure("run", "--rm", testutil.CommonImage)
3637
return cmd

Diff for: go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ require (
117117
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
118118
github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 // indirect
119119
github.com/pkg/errors v0.9.1 // indirect
120-
github.com/rs/zerolog v1.34.0 // indirect
121120
github.com/sasha-s/go-deadlock v0.3.5 // indirect
122121
github.com/sirupsen/logrus v1.9.3 // indirect
123122
github.com/smallstep/pkcs7 v0.1.1 // indirect

Diff for: go.sum

-4
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
180180
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
181181
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
182182
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
183-
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
184183
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
185184
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
186185
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
@@ -263,9 +262,6 @@ github.com/rootless-containers/bypass4netns v0.4.2 h1:JUZcpX7VLRfDkLxBPC6fyNalJG
263262
github.com/rootless-containers/bypass4netns v0.4.2/go.mod h1:iOY28IeFVqFHnK0qkBCQ3eKzKQgSW5DtlXFQJyJMAQk=
264263
github.com/rootless-containers/rootlesskit/v2 v2.3.4 h1:EHiqqiq+ntTfdnQtIgDR3etiuqKkRCPr1qpoizJxW/E=
265264
github.com/rootless-containers/rootlesskit/v2 v2.3.4/go.mod h1:AJNM4jS0jFIF8GvBfnm4I0498zosnHGCIMRhUoEUmFg=
266-
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
267-
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
268-
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
269265
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
270266
github.com/sasha-s/go-deadlock v0.3.5 h1:tNCOEEDG6tBqrNDOX35j/7hL5FcFViG6awUGROb2NsU=
271267
github.com/sasha-s/go-deadlock v0.3.5/go.mod h1:bugP6EGbdGYObIlx7pUZtWqlvo8k9H6vCBBsiChJQ5U=

Diff for: mod/tigron/.golangci.yml

-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ linters:
3030
- github.com/creack/pty
3131
- golang.org/x/sync
3232
- golang.org/x/term
33-
- gotest.tools/v3
34-
- github.com/rs/zerolog
35-
- github.com/rs/zerolog/log
3633
- go.uber.org/goleak
3734
staticcheck:
3835
checks:

Diff for: mod/tigron/expect/comparators.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package expect
1818

1919
import (
20+
"encoding/hex"
2021
"fmt"
2122
"regexp"
2223
"strings"
@@ -45,7 +46,8 @@ func Contains(compare string) test.Comparator {
4546
return func(stdout, info string, t *testing.T) {
4647
t.Helper()
4748
assertive.Check(t, strings.Contains(stdout, compare),
48-
fmt.Sprintf("Output does not contain: %q", compare)+info)
49+
fmt.Sprintf("Output does not contain: %q", compare),
50+
info)
4951
}
5052
}
5153

@@ -56,7 +58,7 @@ func DoesNotContain(compare string) test.Comparator {
5658
return func(stdout, info string, t *testing.T) {
5759
t.Helper()
5860
assertive.Check(t, !strings.Contains(stdout, compare),
59-
fmt.Sprintf("Output should not contain: %q", compare)+info)
61+
fmt.Sprintf("Output should not contain: %q", compare), info)
6062
}
6163
}
6264

@@ -65,10 +67,14 @@ func Equals(compare string) test.Comparator {
6567
//nolint:thelper
6668
return func(stdout, info string, t *testing.T) {
6769
t.Helper()
70+
71+
hexdump := hex.Dump([]byte(stdout))
6872
assertive.Check(
6973
t,
7074
compare == stdout,
71-
fmt.Sprintf("Output is not equal to: %q", compare)+info,
75+
fmt.Sprintf("Output is not equal to: %q", compare),
76+
"\n"+hexdump,
77+
info,
7278
)
7379
}
7480
}

Diff for: mod/tigron/go.mod

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ go 1.23.0
44

55
require (
66
github.com/creack/pty v1.1.24
7-
github.com/rs/zerolog v1.34.0
87
go.uber.org/goleak v1.3.0
98
golang.org/x/sync v0.11.0
109
golang.org/x/term v0.29.0
1110
)
1211

13-
require (
14-
github.com/mattn/go-colorable v0.1.13 // indirect
15-
github.com/mattn/go-isatty v0.0.19 // indirect
16-
golang.org/x/sys v0.31.0 // indirect
17-
)
12+
require golang.org/x/sys v0.31.0 // indirect

Diff for: mod/tigron/go.sum

-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
21
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
32
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
43
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
54
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
7-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
8-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
9-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
10-
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
11-
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
12-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
135
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
146
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15-
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
16-
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
17-
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
187
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
198
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
209
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
2110
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
2211
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
2312
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
24-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
25-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
26-
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2713
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
2814
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
2915
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=

Diff for: mod/tigron/internal/com/command.go

+32-17
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import (
2727
"syscall"
2828
"time"
2929

30-
"github.com/rs/zerolog"
31-
"github.com/rs/zerolog/log"
30+
"github.com/containerd/nerdctl/mod/tigron/internal/logger"
3231
)
3332

3433
const (
@@ -43,7 +42,7 @@ var (
4342
// binary missing).
4443
ErrFailedStarting = errors.New("command failed starting")
4544
// ErrSignaled is returned by Wait() if a signal was sent to the command while running.
46-
ErrSignaled = errors.New("command execution signalled")
45+
ErrSignaled = errors.New("command execution signaled")
4746
// ErrExecutionFailed is returned by Wait() when a command executes but returns a non-zero error
4847
// code.
4948
ErrExecutionFailed = errors.New("command returned a non-zero exit code")
@@ -61,6 +60,11 @@ var (
6160
errExecutionCancelled = errors.New("command execution cancelled")
6261
)
6362

63+
type contextKey string
64+
65+
// LoggerKey defines the key to attach a logger to on the context.
66+
const LoggerKey = contextKey("logger")
67+
6468
// Result carries the resulting output of a command once it has finished.
6569
type Result struct {
6670
Environ []string
@@ -76,7 +80,7 @@ type execution struct {
7680
cancel context.CancelFunc
7781
command *exec.Cmd
7882
pipes *stdPipes
79-
log zerolog.Logger
83+
log logger.Logger
8084
err error
8185
}
8286

@@ -193,17 +197,30 @@ func (gc *Command) Run(parentCtx context.Context) error {
193197

194198
// Create a contextual command, set the logger
195199
cmd = gc.buildCommand(ctx)
196-
logg := log.Logger.With().Ctx(ctx).Str("module", "com").Str("command", cmd.String()).Logger()
200+
201+
// Get a debug-logger from the context
202+
var (
203+
log logger.Logger
204+
ok bool
205+
)
206+
207+
if log, ok = parentCtx.Value(LoggerKey).(logger.Logger); !ok {
208+
log = nil
209+
}
210+
211+
// FIXME: this is manual silencing - should be possible to enable this with some debug flag
212+
conLog := logger.NewLogger(log).Set("command", cmd.String())
213+
emLog := logger.NewLogger(nil).Set("command", cmd.String())
197214

198215
gc.exec = &execution{
199216
context: ctx,
200217
cancel: ctxCancel,
201218
command: cmd,
202-
log: logg,
219+
log: conLog,
203220
}
204221

205222
// Prepare pipes
206-
pipes, err = newStdPipes(ctx, logg, gc.ptyStdout, gc.ptyStderr, gc.ptyStdin, gc.writers)
223+
pipes, err = newStdPipes(ctx, emLog, gc.ptyStdout, gc.ptyStderr, gc.ptyStdin, gc.writers)
207224
if err != nil {
208225
ctxCancel()
209226

@@ -223,7 +240,7 @@ func (gc *Command) Run(parentCtx context.Context) error {
223240
// Start it
224241
if err = cmd.Start(); err != nil {
225242
// On failure, can the context, wrap whatever we have and return
226-
gc.exec.log.Warn().Err(err).Msg("start failed")
243+
gc.exec.log.Log("start failed", err)
227244

228245
gc.exec.err = errors.Join(ErrFailedStarting, err)
229246

@@ -239,13 +256,11 @@ func (gc *Command) Run(parentCtx context.Context) error {
239256
// There is no good reason for this to happen, so, log it
240257
err = gc.wrap()
241258

242-
gc.exec.log.Error().
243-
Err(ctx.Err()).
244-
Err(err).
245-
Str("stdout", gc.result.Stdout).
246-
Str("stderr", gc.result.Stderr).
247-
Int("exit", gc.result.ExitCode).
248-
Send()
259+
gc.exec.log.Log("stdout", gc.result.Stdout)
260+
gc.exec.log.Log("stderr", gc.result.Stderr)
261+
gc.exec.log.Log("exitcode", gc.result.ExitCode)
262+
gc.exec.log.Log("err", err)
263+
gc.exec.log.Log("ctxerr", ctx.Err())
249264

250265
return err
251266
default:
@@ -328,7 +343,7 @@ func (gc *Command) wrap() error {
328343
if cmd.ProcessState != nil {
329344
var ok bool
330345
if status, ok = cmd.ProcessState.Sys().(syscall.WaitStatus); !ok {
331-
log.Panic().Msg("failed casting process state sys")
346+
panic("failed casting process state sys")
332347
}
333348

334349
if status.Signaled() {
@@ -415,7 +430,7 @@ func (gc *Command) buildCommand(ctx context.Context) *exec.Cmd {
415430
// Attach platform ProcAttr and get optional custom cancellation routine
416431
if cancellation := addAttr(cmd); cancellation != nil {
417432
cmd.Cancel = func() error {
418-
gc.exec.log.Trace().Msg("command cancelled")
433+
gc.exec.log.Log("command cancelled")
419434

420435
// Call the platform dependent cancellation routine
421436
return cancellation()

Diff for: mod/tigron/internal/com/command_other.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func addAttr(cmd *exec.Cmd) func() error {
2727
// Default shutdown will leave child processes behind in certain circumstances
2828
cmd.SysProcAttr = &syscall.SysProcAttr{
2929
Setsid: true,
30+
// FIXME: understand why we would want that
31+
// Setctty: true,
3032
}
3133

3234
return func() error {

0 commit comments

Comments
 (0)