-
Notifications
You must be signed in to change notification settings - Fork 950
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
feature: cli support add kill command #2924
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2924 +/- ##
==========================================
- Coverage 68.23% 66.17% -2.06%
==========================================
Files 291 293 +2
Lines 18328 18445 +117
==========================================
- Hits 12506 12206 -300
- Misses 4368 4761 +393
- Partials 1454 1478 +24
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
in killWithSignal
, I didn't find any call to containerd, so when pouch kill -2 xxx
, what will happen?
apis/server/container_bridge.go
Outdated
} | ||
} | ||
|
||
fmt.Printf("signal: %d\n", uint64(sig)) |
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.
change to logrus.debug
@@ -68,6 +68,9 @@ type ContainerMgr interface { | |||
// List returns the list of containers. | |||
List(ctx context.Context, option *ContainerListOption) ([]*Container, error) | |||
|
|||
// Kill one or more running containers | |||
Kill(ctx context.Context, name string, signal uint64) (err 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.
the desc here I think is kill one running container, wdyt?
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.
err := mgr.killWithSignal(ctx, c, signal) | ||
if err == syscall.ESRCH { | ||
e := errNoSuchProcess{c.State.Pid, signal} | ||
logrus.Debug(e) |
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.
please add more msg to this err
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.
return nil | ||
} | ||
|
||
if c.IsRunning() { |
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 killDeadProcess
don't lock the container here?
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.
The function killDeadProcess will call the function killWithSignal. The latter will lock the container.
err = fmt.Errorf("Cannot kill container %s: %s", c.ID, err) | ||
if strings.Contains(err.Error(), "container not found") || | ||
strings.Contains(err.Error(), "no such process") { | ||
logrus.Warnf("container kill failed because of 'container not found' or 'no such process': %s", err.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.
return err?
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.
Actually, return fmt.Errorf("Cannot kill container %s: %s", c.ID, err).
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.
in killWithSignal, I didn't find any call to containerd, so when pouch kill -2 xxx, what will happen?
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.
- the process inside the container is in another PID namespace. directly do
syscall.Kill
will kill the process on host. using containerd task kill instead. - distinguish
kill
anddestroy
.destroy
is the combination ofkill
anddelete
, the latter one will remove the meta data.
1645ffb
to
5ff3367
Compare
add more input:#2733 |
ed40008
to
fb7eb64
Compare
|
||
"github.com/alibaba/pouch/test/command" | ||
"github.com/alibaba/pouch/test/environment" | ||
"github.com/go-check/check" |
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.
add a blank line
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.
Thanks.
daemon/mgr/container_kill.go
Outdated
return err | ||
} | ||
|
||
if signal == 0 || syscall.Signal(signal) == syscall.SIGKILL { |
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.
could you explain when signal = 0?
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.
Thanks for your advice. I think that signal == 0 is redundant.
} | ||
// the caller need to execute the all hooks. | ||
pack.l.Lock() | ||
pack.skipStopHooks = true |
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 need this?
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.
Actually I don't know if it is necessary to add these things. But if you want to kill a container, you should skip the stop hooks.
Signed-off-by: Lang Chi <21860405@zju.edu.cn>
} | ||
} | ||
|
||
if err := s.ContainerMgr.Kill(ctx, name, uint64(sig)); err != nil { |
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.
please just return s.ContainerMgr.Kill(ctx, name, uint64(sig))
to simplify code.
"github.com/pkg/errors" | ||
|
||
"github.com/alibaba/pouch/pkg/errtypes" | ||
"github.com/sirupsen/logrus" |
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.
please restruct the package import sequence.
} | ||
} | ||
|
||
if pid := c.State.Pid; pid != 0 { |
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.
Please use fast return
to reduce ident:
https://github.com/alibaba/pouch/blob/master/docs/contributions/code_styles.md#rule006---return-fast-to-indent-less
defer c.Unlock() | ||
|
||
if c.State.Paused { | ||
return fmt.Errorf("Container %s is paused. Unpause the container before stopping", c.ID) |
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.
before killing?
@@ -0,0 +1,49 @@ | |||
## pouch kill |
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.
Please remove this file. This file is auto-generated. https://github.com/alibaba/pouch/tree/master/docs#commandline
What's more, all commandline docs are auto generated via source code
|
||
// ParseSignal translates a string to a valid syscall signal. | ||
// It returns an error if the signal map doesn't include the given signal. | ||
func ParseSignal(rawSignal string) (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.
please add unit test for this function. Thanks.
ping @lang710 |
|
ping @lang710 |
Seem that author doesn't response for a long time, I open another PR but some different details(don't skip hooks), so I will close PR. |
Signed-off-by: Lang Chi 21860405@zju.edu.cn
Ⅰ. Describe what this PR did
cli support add kill command
Ⅱ. Does this pull request fix one issue?
fixes #2917
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
Added
Ⅳ. Describe how to verify it
root@compatibility:
# pouch run -d busybox top# pouch kill df0487e6cc386f9340d27e62ab8a3797e5ccccb5d199bbebb87a0155aa69a84fdf0487e6cc386f9340d27e62ab8a3797e5ccccb5d199bbebb87a0155aa69a84f
root@compatibility:
df0487e6cc386f9340d27e62ab8a3797e5ccccb5d199bbebb87a0155aa69a84f
root@compatibility:
# pouch run -d busybox top# pouch kill -s 0 75d8d902f78315b065c41e81a2a9967f7a3edf891c36bd50f36ab3b1691d9c7375d8d902f78315b065c41e81a2a9967f7a3edf891c36bd50f36ab3b1691d9c73
root@compatibility:
Error: {"message":"Invalid signal: 0"}
Ⅴ. Special notes for reviews