MCPcopy Create free account
hub / github.com/containerd/nerdctl / Kill

Function Kill

pkg/cmd/container/kill.go:48–80  ·  view source on GitHub ↗

Kill kills a list of containers

(ctx context.Context, client *containerd.Client, reqs []string, options types.ContainerKillOptions)

Source from the content-addressed store, hash-verified

46
47// Kill kills a list of containers
48func Kill(ctx context.Context, client *containerd.Client, reqs []string, options types.ContainerKillOptions) error {
49 if !strings.HasPrefix(options.KillSignal, "SIG") {
50 options.KillSignal = "SIG" + options.KillSignal
51 }
52
53 parsedSignal, err := signal.ParseSignal(options.KillSignal)
54 if err != nil {
55 return err
56 }
57
58 walker := &containerwalker.ContainerWalker{
59 Client: client,
60 OnFound: func(ctx context.Context, found containerwalker.Found) error {
61 if found.MatchCount > 1 {
62 return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
63 }
64 if err := cleanupNetwork(ctx, found.Container, options.GOptions); err != nil {
65 return fmt.Errorf("unable to cleanup network for container: %s, %q", found.Req, err)
66 }
67 if err := killContainer(ctx, found.Container, parsedSignal); err != nil {
68 if errdefs.IsNotFound(err) {
69 fmt.Fprintf(options.Stderr, "No such container: %s\n", found.Req)
70 os.Exit(1)
71 }
72 return err
73 }
74 _, err := fmt.Fprintln(options.Stdout, found.Container.ID())
75 return err
76 },
77 }
78
79 return walker.WalkAll(ctx, reqs, true)
80}
81
82func killContainer(ctx context.Context, container containerd.Container, signal syscall.Signal) (err error) {
83 defer func() {

Callers 1

killActionFunction · 0.92

Calls 3

WalkAllMethod · 0.95
cleanupNetworkFunction · 0.85
killContainerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…