From 515d68099be0fe72dc0dad53b116fe2718892381 Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Mon, 9 Jan 2023 17:49:03 -0800 Subject: [PATCH 1/2] shim: enable debug logging for delete Signed-off-by: Samuel Karp --- runtime/v2/binary.go | 20 +++++++++++++------- runtime/v2/shim/shim.go | 9 ++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/runtime/v2/binary.go b/runtime/v2/binary.go index 0b14af67b..3e6c52232 100644 --- a/runtime/v2/binary.go +++ b/runtime/v2/binary.go @@ -26,6 +26,9 @@ import ( gruntime "runtime" "strings" + "github.com/containerd/ttrpc" + "github.com/sirupsen/logrus" + "github.com/containerd/containerd/api/runtime/task/v2" "github.com/containerd/containerd/log" "github.com/containerd/containerd/namespaces" @@ -34,8 +37,6 @@ import ( "github.com/containerd/containerd/protobuf/types" "github.com/containerd/containerd/runtime" client "github.com/containerd/containerd/runtime/v2/shim" - "github.com/containerd/ttrpc" - "github.com/sirupsen/logrus" ) type shimBinaryConfig struct { @@ -153,6 +154,15 @@ func (b *binary) Delete(ctx context.Context) (*runtime.Exit, error) { if gruntime.GOOS != "windows" && gruntime.GOOS != "freebsd" { bundlePath = b.bundle.Path } + args := []string{ + "-id", b.bundle.ID, + "-bundle", b.bundle.Path, + } + switch logrus.GetLevel() { + case logrus.DebugLevel, logrus.TraceLevel: + args = append(args, "-debug") + } + args = append(args, "delete") cmd, err := client.Command(ctx, &client.CommandConfig{ @@ -161,11 +171,7 @@ func (b *binary) Delete(ctx context.Context) (*runtime.Exit, error) { TTRPCAddress: b.containerdTTRPCAddress, Path: bundlePath, Opts: nil, - Args: []string{ - "-id", b.bundle.ID, - "-bundle", b.bundle.Path, - "delete", - }, + Args: args, }) if err != nil { diff --git a/runtime/v2/shim/shim.go b/runtime/v2/shim/shim.go index 19a248503..f12228b98 100644 --- a/runtime/v2/shim/shim.go +++ b/runtime/v2/shim/shim.go @@ -312,6 +312,9 @@ func run(ctx context.Context, manager Manager, initFunc Init, name string, confi // Handle explicit actions switch action { case "delete": + if debugFlag { + logrus.SetLevel(logrus.DebugLevel) + } logger := log.G(ctx).WithFields(logrus.Fields{ "pid": os.Getpid(), "namespace": namespaceFlag, @@ -400,14 +403,14 @@ func run(ctx context.Context, manager Manager, initFunc Init, name string, confi initContext.TTRPCAddress = ttrpcAddress // load the plugin specific configuration if it is provided - //TODO: Read configuration passed into shim, or from state directory? - //if p.Config != nil { + // TODO: Read configuration passed into shim, or from state directory? + // if p.Config != nil { // pc, err := config.Decode(p) // if err != nil { // return nil, err // } // initContext.Config = pc - //} + // } result := p.Init(initContext) if err := initialized.Add(result); err != nil { From 5f1a42543cd84e7046c477a23fd339a76d8df624 Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Mon, 9 Jan 2023 17:50:16 -0800 Subject: [PATCH 2/2] shim: move reap log line to debug Fixes https://github.com/containerd/containerd/issues/7941 Signed-off-by: Samuel Karp --- runtime/v2/shim/shim_unix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/v2/shim/shim_unix.go b/runtime/v2/shim/shim_unix.go index 82d3e7eb6..90a7dbb07 100644 --- a/runtime/v2/shim/shim_unix.go +++ b/runtime/v2/shim/shim_unix.go @@ -71,7 +71,7 @@ func serveListener(path string) (net.Listener, error) { } func reap(ctx context.Context, logger *logrus.Entry, signals chan os.Signal) error { - logger.Info("starting signal loop") + logger.Debug("starting signal loop") for { select {