-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctr: make kill optionally use stop-signal #2577
Conversation
I kinda feel like if you are adding this, you are kinda relying on ctr to much ;) |
I'm mostly just trying to demonstrate how to extract data from the image configuration 😄. I was looking into this because I wanted to see what happened with health checks in the Docker image format (and they're not present in OCI); if I want to extract that data I'll need to go through this same sort of workflow. (I don't rely on ctr in any production code, but I think it's a good place to stick example code that can be useful.) |
I also thought about putting something like this in the containerd client, but I wasn't sure where would make sense in terms of package organization. The |
This looks unrelated to me? |
@samuelkarp It might be better to extract this from the actual OCI config on the task, rather than the image, as that might have changed. For the cli, I think this should be the default for |
Doesn't look like we can get at the current OCI config, so settling for the image is the best option, without an API change: https://github.com/containerd/containerd/blob/master/api/services/tasks/v1/tasks.proto#L112. |
@crosbymichael Any opinion on whether this should be the default? I'm happy to make the change if you concur with @stevvooe. |
Why not save this as a label/annotation on the runtime spec, the spec can then be fetched out |
@crosbymichael Would you suggest that for all containers that containerd runs? Or just an optional well-known annotation that can be set using the containerd client? |
Optional label. we could provide a |
a7537f7
to
4bb7fb4
Compare
@crosbymichael Done.
This failure appears to be unrelated to my commit. |
cmd/ctr/commands/tasks/kill.go
Outdated
task, err := container.Task(ctx, nil) | ||
if err != nil { | ||
return err | ||
} | ||
return task.Kill(ctx, signal, opts...) | ||
}, | ||
} | ||
|
||
func getStopSignal(ctx context.Context, container containerd.Container, defaultSignal syscall.Signal) (syscall.Signal, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this to the containerd package and export it? It seems like people would have to re-implement this each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though moving this unmodified into the containerd
package will create an import cycle; this code depends on commands.ParseSignal
and commands
imports containerd
. Would you want to move commands.ParseSignal
(and the associated commands.signalMap
into containerd
or should I just return the signal as a string
and let the caller deal with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just save the uint as the label value, then it's just a strconv.ParseUint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StopSignal
in the v1.ImageConfig
is a string
, so I'd still need to convert that string to a syscall.Signal
somewhere, likely using commands.ParseSignal
. It ends up being the same import cycle problem, but in storing the signal instead of retrieving it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, i see. I think it would be safe to move the signal map into the containerd client package. It's generally useful.
Codecov Report
@@ Coverage Diff @@
## master #2577 +/- ##
=======================================
Coverage 45.09% 45.09%
=======================================
Files 92 92
Lines 10132 10132
=======================================
Hits 4569 4569
Misses 4842 4842
Partials 721 721
Continue to review full report at Codecov.
|
4bb7fb4
to
5b46a61
Compare
Signed-off-by: Samuel Karp <skarp@amazon.com>
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>
5b46a61
to
607888c
Compare
@crosbymichael Updated per your comments. |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 an option to
ctr task kill
that reads the StopSignal from the image configuration and sends that signal.