(ctx context.Context, container containerd.Container, signal syscall.Signal)
| 80 | } |
| 81 | |
| 82 | func killContainer(ctx context.Context, container containerd.Container, signal syscall.Signal) (err error) { |
| 83 | defer func() { |
| 84 | if err != nil { |
| 85 | containerutil.UpdateErrorLabel(ctx, container, err) |
| 86 | } |
| 87 | }() |
| 88 | if err := containerutil.UpdateExplicitlyStoppedLabel(ctx, container, true); err != nil { |
| 89 | return err |
| 90 | } |
| 91 | task, err := container.Task(ctx, cio.Load) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | |
| 96 | status, err := task.Status(ctx) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | |
| 101 | paused := false |
| 102 | |
| 103 | switch status.Status { |
| 104 | case containerd.Created, containerd.Stopped: |
| 105 | return fmt.Errorf("cannot kill container %s: container is not running", container.ID()) |
| 106 | case containerd.Paused, containerd.Pausing: |
| 107 | paused = true |
| 108 | default: |
| 109 | } |
| 110 | |
| 111 | if err := task.Kill(ctx, signal); err != nil { |
| 112 | return err |
| 113 | } |
| 114 | |
| 115 | // Clean up healthcheck systemd units |
| 116 | if err := healthcheck.RemoveTransientHealthCheckFiles(ctx, container); err != nil { |
| 117 | log.G(ctx).Warnf("failed to clean up healthcheck units for container %s: %s", container.ID(), err) |
| 118 | } |
| 119 | |
| 120 | // signal will be sent once resume is finished |
| 121 | if paused { |
| 122 | if err := task.Resume(ctx); err != nil { |
| 123 | log.G(ctx).Warnf("cannot unpause container %s: %s", container.ID(), err) |
| 124 | } |
| 125 | } |
| 126 | return nil |
| 127 | } |
| 128 | |
| 129 | // cleanupNetwork removes cni network setup, specifically the forwards |
| 130 | func cleanupNetwork(ctx context.Context, container containerd.Container, globalOpts types.GlobalCommandOptions) error { |
no test coverage detected
searching dependent graphs…