Skip to content

nerdctl kill shouldn't set containerd.io/restart.explicitly-stopped label for non-stop signals #5171

Description

@AkihiroSuda

func killContainer(ctx context.Context, container containerd.Container, signal syscall.Signal) (err error) {
defer func() {
if err != nil {
containerutil.UpdateErrorLabel(ctx, container, err)
}
}()
if err := containerutil.UpdateExplicitlyStoppedLabel(ctx, container, true); err != nil {
return err
}
task, err := container.Task(ctx, cio.Load)
if err != nil {
return err
}
status, err := task.Status(ctx)
if err != nil {
return err
}
paused := false
switch status.Status {
case containerd.Created, containerd.Stopped:
return fmt.Errorf("cannot kill container %s: container is not running", container.ID())
case containerd.Paused, containerd.Pausing:
paused = true
default:
}
if err := task.Kill(ctx, signal); err != nil {
return err
}
// Clean up healthcheck systemd units
if err := healthcheck.RemoveTransientHealthCheckFiles(ctx, container); err != nil {
log.G(ctx).Warnf("failed to clean up healthcheck units for container %s: %s", container.ID(), err)
}
// signal will be sent once resume is finished
if paused {
if err := task.Resume(ctx); err != nil {
log.G(ctx).Warnf("cannot unpause container %s: %s", container.ID(), err)
}
}
return nil
}

nerdctl kill can be used for non-stop signals such as HUP, so it shouldn't unconditionally set containerd.io/restart.explicitly-stopped label

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions