ctr: make kill use stop-signal by default
The OCI image specification includes a `StopSignal` field in the image configuration, denoting the system call signal to be sent to the container to exit. This commit adds a new `WithImageStopSignal` container option that can be used for storing the `StopSignal` field as a label on the container. This commit also adjusts `ctr run` to call `WithImageStopSignal` and `ctr tasks kill` to send the signal stored in that label by default. Signed-off-by: Samuel Karp <skarp@amazon.com>
This commit is contained in:
@@ -76,6 +76,23 @@ func WithContainerLabels(labels map[string]string) NewContainerOpts {
|
||||
}
|
||||
}
|
||||
|
||||
// WithImageStopSignal sets a well-known containerd label (StopSignalLabel)
|
||||
// on the container for storing the stop signal specified in the OCI image
|
||||
// config
|
||||
func WithImageStopSignal(image Image, defaultSignal string) NewContainerOpts {
|
||||
return func(ctx context.Context, _ *Client, c *containers.Container) error {
|
||||
if c.Labels == nil {
|
||||
c.Labels = make(map[string]string)
|
||||
}
|
||||
stopSignal, err := GetOCIStopSignal(ctx, image, defaultSignal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Labels[StopSignalLabel] = stopSignal
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithSnapshotter sets the provided snapshotter for use by the container
|
||||
//
|
||||
// This option must appear before other snapshotter options to have an effect.
|
||||
|
||||
Reference in New Issue
Block a user