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

feature: cli support add kill command #2924

Closed
wants to merge 1 commit into from

Conversation

lang710
Copy link
Contributor

@lang710 lang710 commented Jun 22, 2019

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
df0487e6cc386f9340d27e62ab8a3797e5ccccb5d199bbebb87a0155aa69a84f
root@compatibility:
# pouch kill df0487e6cc386f9340d27e62ab8a3797e5ccccb5d199bbebb87a0155aa69a84f
df0487e6cc386f9340d27e62ab8a3797e5ccccb5d199bbebb87a0155aa69a84f
root@compatibility:# pouch run -d busybox top
75d8d902f78315b065c41e81a2a9967f7a3edf891c36bd50f36ab3b1691d9c73
root@compatibility:
# pouch kill -s 0 75d8d902f78315b065c41e81a2a9967f7a3edf891c36bd50f36ab3b1691d9c73
Error: {"message":"Invalid signal: 0"}

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Jun 22, 2019

Codecov Report

Merging #2924 into master will decrease coverage by 2.05%.
The diff coverage is 51.96%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
#criv1alpha2_test 34.59% <0.98%> (-0.24%) ⬇️
#integration_test_0 35.99% <51.96%> (-0.08%) ⬇️
#integration_test_1 35.80% <0.98%> (+0.30%) ⬆️
#integration_test_2 ?
#integration_test_3 35.34% <0.98%> (-0.30%) ⬇️
#node_e2e_test 33.94% <0.98%> (-0.42%) ⬇️
#unittest 27.78% <0.00%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
client/container_kill.go 0.00% <0.00%> (ø)
daemon/mgr/container.go 59.10% <ø> (-1.25%) ⬇️
pkg/errtypes/errors.go 76.00% <0.00%> (-15.31%) ⬇️
daemon/mgr/container_kill.go 43.75% <43.75%> (ø)
pkg/utils/utils.go 82.35% <60.00%> (-0.92%) ⬇️
ctrd/container.go 52.37% <68.00%> (-1.93%) ⬇️
apis/server/container_bridge.go 88.64% <80.00%> (-1.36%) ⬇️
apis/server/router.go 91.56% <100.00%> (+0.05%) ⬆️
storage/volume/modules/tmpfs/tmpfs.go 28.20% <0.00%> (-47.44%) ⬇️
daemon/events/filter.go 60.00% <0.00%> (-40.00%) ⬇️
... and 42 more

Copy link
Contributor

@ZYecho ZYecho left a 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?

}
}

fmt.Printf("signal: %d\n", uint64(sig))
Copy link
Contributor

Choose a reason for hiding this comment

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

change to logrus.debug

cli/kill.go Outdated Show resolved Hide resolved
@@ -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)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

daemon/mgr/container_kill.go Outdated Show resolved Hide resolved
daemon/mgr/container_kill.go Outdated Show resolved Hide resolved
err := mgr.killWithSignal(ctx, c, signal)
if err == syscall.ESRCH {
e := errNoSuchProcess{c.State.Pid, signal}
logrus.Debug(e)
Copy link
Contributor

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

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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())
Copy link
Contributor

Choose a reason for hiding this comment

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

return err?

Copy link
Contributor Author

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

@ZYecho ZYecho self-requested a review June 23, 2019 02:12
Copy link
Contributor

@ZYecho ZYecho left a 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?

Copy link
Contributor

@zhuangqh zhuangqh left a comment

Choose a reason for hiding this comment

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

  1. 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.
  2. distinguish kill and destroy. destroy is the combination of kill and delete, the latter one will remove the meta data.

@lang710 lang710 force-pushed the addkill branch 2 times, most recently from 1645ffb to 5ff3367 Compare June 23, 2019 08:46
@ZYecho
Copy link
Contributor

ZYecho commented Jun 23, 2019

add more input:#2733

@lang710 lang710 force-pushed the addkill branch 3 times, most recently from ed40008 to fb7eb64 Compare June 24, 2019 05:47

"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/go-check/check"
Copy link
Contributor

Choose a reason for hiding this comment

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

add a blank line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

return err
}

if signal == 0 || syscall.Signal(signal) == syscall.SIGKILL {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

why need this?

Copy link
Contributor Author

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 {
Copy link
Collaborator

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"
Copy link
Collaborator

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

defer c.Unlock()

if c.State.Paused {
return fmt.Errorf("Container %s is paused. Unpause the container before stopping", c.ID)
Copy link
Collaborator

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

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

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.

@pouchrobot
Copy link
Collaborator

ping @lang710
Conflict happens after merging a previous commit.
Please rebase the branch against master and push it back again. Thanks a lot.

@CLAassistant
Copy link

CLAassistant commented Jun 12, 2020

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@rudyfly rudyfly requested a review from cxz66666 July 7, 2022 11:46
@cxz66666
Copy link
Collaborator

ping @lang710
Can you have time to update those questions? Or I will closed this PR. Thank you for your response!

@cxz66666
Copy link
Collaborator

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.

@cxz66666 cxz66666 closed this Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] pouch cli supports kill function
7 participants