From 34780d67ad2b63af7bad1faed5db9cffe814a0d6 Mon Sep 17 00:00:00 2001 From: Iceber Gu Date: Fri, 16 Apr 2021 15:44:57 +0800 Subject: [PATCH] runtime/shim: check the namespace flag first Signed-off-by: Iceber Gu --- runtime/v2/shim/shim.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/v2/shim/shim.go b/runtime/v2/shim/shim.go index 68c81c9b7..29bded5f9 100644 --- a/runtime/v2/shim/shim.go +++ b/runtime/v2/shim/shim.go @@ -167,12 +167,17 @@ func run(id string, initFunc Init, config Config) error { return nil } + if namespaceFlag == "" { + return fmt.Errorf("shim namespace cannot be empty") + } + setRuntime() signals, err := setupSignals(config) if err != nil { return err } + if !config.NoSubreaper { if err := subreaper(); err != nil { return err @@ -180,17 +185,12 @@ func run(id string, initFunc Init, config Config) error { } ttrpcAddress := os.Getenv(ttrpcAddressEnv) - publisher, err := NewPublisher(ttrpcAddress) if err != nil { return err } - defer publisher.Close() - if namespaceFlag == "" { - return fmt.Errorf("shim namespace cannot be empty") - } ctx := namespaces.WithNamespace(context.Background(), namespaceFlag) ctx = context.WithValue(ctx, OptsKey{}, Opts{BundlePath: bundlePath, Debug: debugFlag}) ctx = log.WithLogger(ctx, log.G(ctx).WithField("runtime", id)) @@ -199,6 +199,7 @@ func run(id string, initFunc Init, config Config) error { if err != nil { return err } + switch action { case "delete": logger := logrus.WithFields(logrus.Fields{