Stop stops a list of containers specified by `reqs`.
(ctx context.Context, client *containerd.Client, reqs []string, opt types.ContainerStopOptions)
| 32 | |
| 33 | // Stop stops a list of containers specified by `reqs`. |
| 34 | func Stop(ctx context.Context, client *containerd.Client, reqs []string, opt types.ContainerStopOptions) error { |
| 35 | walker := &containerwalker.ContainerWalker{ |
| 36 | Client: client, |
| 37 | OnFound: func(ctx context.Context, found containerwalker.Found) error { |
| 38 | if found.MatchCount > 1 { |
| 39 | return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req) |
| 40 | } |
| 41 | if err := cleanupNetwork(ctx, found.Container, opt.GOptions); err != nil { |
| 42 | return fmt.Errorf("unable to cleanup network for container: %s", found.Req) |
| 43 | } |
| 44 | if err := healthcheck.RemoveTransientHealthCheckFiles(ctx, found.Container); err != nil { |
| 45 | return fmt.Errorf("unable to cleanup healthcheck timer for container: %s: %w", found.Req, err) |
| 46 | } |
| 47 | if err := containerutil.Stop(ctx, found.Container, opt.Timeout, opt.Signal); err != nil { |
| 48 | if errdefs.IsNotFound(err) { |
| 49 | fmt.Fprintf(opt.Stderr, "No such container: %s\n", found.Req) |
| 50 | return nil |
| 51 | } |
| 52 | return err |
| 53 | } |
| 54 | if err := ocihook.CleanupPortReserverProcess(opt.GOptions.Namespace, found.Container.ID()); err != nil { |
| 55 | return fmt.Errorf("unable to cleanup port reserver process for container: %s: %w", found.Req, err) |
| 56 | } |
| 57 | _, err := fmt.Fprintln(opt.Stdout, found.Req) |
| 58 | return err |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | return walker.WalkAll(ctx, reqs, true) |
| 63 | } |
no test coverage detected
searching dependent graphs…