summaryrefslogtreecommitdiffhomepage
path: root/runsc/cmd/delete.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-05-29 17:57:26 -0700
committerShentubot <shentubot@google.com>2018-05-29 17:58:12 -0700
commit812e83d3bbb99d4fa1ece4712a1ac85e84fe6ec3 (patch)
tree559b9a5a5fc2b37899bf2ffb915e1ed4eadf6bfa /runsc/cmd/delete.go
parentc5dc873e441706e8aaff7389e26c862f1386c6a8 (diff)
Supress error when deleting non-existing container with --force
This addresses the first issue reported in #59. CRI-O expects runsc to return success to delete when --force is used with a non-existing container. PiperOrigin-RevId: 198487418 Change-Id: If7660e8fdab1eb29549d0a7a45ea82e20a1d4f4a
Diffstat (limited to 'runsc/cmd/delete.go')
-rw-r--r--runsc/cmd/delete.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/runsc/cmd/delete.go b/runsc/cmd/delete.go
index 769a11c45..46de5f348 100644
--- a/runsc/cmd/delete.go
+++ b/runsc/cmd/delete.go
@@ -15,9 +15,13 @@
package cmd
import (
+ "fmt"
+ "os"
+
"context"
"flag"
"github.com/google/subcommands"
+ "gvisor.googlesource.com/gvisor/pkg/log"
"gvisor.googlesource.com/gvisor/runsc/boot"
"gvisor.googlesource.com/gvisor/runsc/container"
)
@@ -56,19 +60,28 @@ func (d *Delete) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}
}
conf := args[0].(*boot.Config)
+ if err := d.execute(f.Args(), conf); err != nil {
+ Fatalf("%v", err)
+ }
+ return subcommands.ExitSuccess
+}
- for i := 0; i < f.NArg(); i++ {
- id := f.Arg(i)
+func (d *Delete) execute(ids []string, conf *boot.Config) error {
+ for _, id := range ids {
c, err := container.Load(conf.RootDir, id)
if err != nil {
- Fatalf("error loading container %q: %v", id, err)
+ if os.IsNotExist(err) && d.force {
+ log.Warningf("couldn't find container %q: %v", id, err)
+ return nil
+ }
+ return fmt.Errorf("error loading container %q: %v", id, err)
}
if !d.force && (c.Status == container.Running) {
- Fatalf("cannot stop running container without --force flag")
+ return fmt.Errorf("cannot stop running container without --force flag")
}
if err := c.Destroy(); err != nil {
- Fatalf("error destroying container: %v", err)
+ return fmt.Errorf("error destroying container: %v", err)
}
}
- return subcommands.ExitSuccess
+ return nil
}