Skip to content
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

Merged
merged 2 commits into from
Sep 28, 2018

Conversation

samuelkarp
Copy link
Member

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.

@crosbymichael
Copy link
Member

I kinda feel like if you are adding this, you are kinda relying on ctr to much ;)

@samuelkarp
Copy link
Member Author

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.)

@samuelkarp
Copy link
Member Author

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 oci package (where I cribbed most of this implementation from oci.WithImageConfig) seems to only contain oci.SpecOpts right now.

@samuelkarp
Copy link
Member Author

Test Suite Failed
--- FAIL: TestCRISuite (56.64s)
	cri_test.go:122: Failed to run tests in paralllel: exit status 1
FAIL

This looks unrelated to me?

@stevvooe
Copy link
Member

@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 kill. I see no issue in changing this, as it doesn't break the compatibility guarantee.

@stevvooe
Copy link
Member

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.

@samuelkarp
Copy link
Member Author

@crosbymichael Any opinion on whether this should be the default? I'm happy to make the change if you concur with @stevvooe.

@crosbymichael
Copy link
Member

Why not save this as a label/annotation on the runtime spec, the spec can then be fetched out

@samuelkarp
Copy link
Member Author

@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?

@crosbymichael
Copy link
Member

Optional label. we could provide a const in containerd client for the key. What do you think?

@samuelkarp samuelkarp force-pushed the stop-signal branch 2 times, most recently from a7537f7 to 4bb7fb4 Compare September 27, 2018 00:28
@samuelkarp
Copy link
Member Author

@crosbymichael Done.

The command "go get -u github.com/vbatts/git-validation" failed and exited with 1 during .

This failure appears to be unrelated to my commit.

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) {
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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-io
Copy link

codecov-io commented Sep 27, 2018

Codecov Report

Merging #2577 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2577   +/-   ##
=======================================
  Coverage   45.09%   45.09%           
=======================================
  Files          92       92           
  Lines       10132    10132           
=======================================
  Hits         4569     4569           
  Misses       4842     4842           
  Partials      721      721
Flag Coverage Δ
#linux 48.84% <ø> (ø) ⬆️
#windows 41.87% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df60d32...607888c. Read the comment docs.

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>
@samuelkarp
Copy link
Member Author

@crosbymichael Updated per your comments.

@crosbymichael
Copy link
Member

LGTM

Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@estesp estesp merged commit ac01f20 into containerd:master Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants