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: add "pouch rm" #214
Conversation
cli/rm.go
Outdated
r.cli = c | ||
r.cmd = &cobra.Command{ | ||
Use: "rm container", | ||
Short: "remove a container", |
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.
I think this command supports removing multiple containers. Could we change Short message to Remove one or more containers
to be more precise?
client/container.go
Outdated
defer ensureCloseReader(resp) | ||
|
||
if resp.StatusCode != http.StatusNoContent { | ||
body, err := ioutil.ReadAll(resp.Body) |
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.
Is there any necessary for us to add a new struct in swagger.yml, for exmaple ContainerRmResponse
or something like that? And maybe this will make API data transferring more structed.
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.
if remove success, there is no content in body as same as docker. Only ocurring error, the body contain the error message.
like this:
{"message":"container: 26ecc8f964f2831a4106d79808af2995a3517f0277bcd398a92c590cba0aeee7 is not stopped, can't remove 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.
if string(body) is empty string, this function will return an error. Is it reasonable?
Actually if resp.StatusCode != http.StatusNoContent
returns true, it means this is a non-2xx response. Then the error message will not be in resp
, I think it is in err
of resp, err := client.delete("/images/"+name, q)
. This is guaranteed by HTTP framework. So I am wondering if this block is reasonable. @HusterWan @skoo87
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.
Not as you said, if resp.StatusCode != http.StatusNoContent returns true, it means pouchd returns non-204 response. pouchd server remove container success, will returns 204 status code. if not 204, that is remove container failed. you should look at the server api code. the action is same as docker, it's reasonable.
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.
I am afraid I was wrong. I search moby's client code, in its cli, when requesting, he will do like this:
func (cli *Client) sendRequest(ctx context.Context, method, path string, query url.Values, body io.Reader, headers headers) (serverResponse, error) {
req, err := cli.buildRequest(method, cli.getAPIPath(path, query), body, headers)
if err != nil {
return serverResponse{}, err
}
resp, err := cli.doRequest(ctx, req)
if err != nil {
return resp, err
}
// !!!!!!!! this part is important, transfer error in body to the second return parameter of func
if err := cli.checkResponseErr(resp); err != nil {
return resp, err
}
return resp, 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.
Yes, you are right. I realized it's a problem after I answer you yesterday.
apis/server/container_bridge.go
Outdated
|
||
option := &mgr.ContainerRemoveOption{ | ||
Force: httputils.BoolValue(req, "force"), | ||
Volume: httputils.BoolValue(req, "v"), |
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.
I do not think we have implemented remove flags v
and l
.
Can we remove both two, or mark this and implement them in the future?
If the answer is latter one, I think we had better track this in an issue or mark that in code comments.
Shall we add this API in swagger.yml ? |
there is not structure what be needed to define in swagger. |
I agree with you that no struct needs added. While I am afraid we need to the api things like:
After this, we can generate API doc with tools. If not, this API will not be generated in API docs. Auto-generation of API documents I have discussed with @CodeJuan, and will work it out soon. |
I agree with you, I updated. @allencloud |
please review it, thanks @allencloud |
apis/swagger.yml
Outdated
|
||
/containers/{name}: | ||
post: | ||
summary: "Remove one or more containers" |
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.
This api only removes one container. So if Remove one container
is better?
cli/rm.go
Outdated
r.cmd = &cobra.Command{ | ||
Use: "rm container", | ||
Short: "Remove one or more containers", | ||
Args: cobra.MinimumNArgs(1), |
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 Long
and Example
in command definition like https://github.com/alibaba/pouch/blob/master/cli/create.go#L28-L33 ?
Then we can automatically generate docs? How about that?
func (mgr *ContainerManager) Remove(ctx context.Context, name string, option *ContainerRemoveOption) error { | ||
c, err := mgr.container(name) |
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 the future, I think we need to classify a StatusNotFound code here, since we may not find container by input name.
We need to do this, in follow-up pull requests.
daemon/mgr/container.go
Outdated
defer c.Unlock() | ||
|
||
if !c.IsStopped() && !c.IsCreated() && !option.Force { | ||
return fmt.Errorf("container: %s is not stopped, can't remove it", 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.
When removing a running container without flag force, I think pouchd would return an error container: %s is not stopped, can't remove it
.
I suggest using fmt.Errorf("container %s is not stopped, cannot remove it without flag force", c.ID())
to tell others to use force
flag.
apis/swagger.yml
Outdated
@@ -298,7 +298,24 @@ paths: | |||
schema: | |||
$ref: "#/definitions/Error" | |||
tags: ["Container"] | |||
|
|||
/containers/{name}: | |||
post: |
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.
this part should be delete
, not post.
cli/rm.go
Outdated
Remove a container object in Pouchd. | ||
If a container is stopped or created, you can remove it. | ||
If the container is running, you can also remove it with flag force. | ||
When the container be removed, the all resource of the container will |
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.
s/be/is
"pouch rm" is used to remove a container which is stopped or created, if a container is running, you can use "pouch rm -f" to force to remove the container. Signed-off-by: skoo87 <marckywu@gmail.com>
updated @allencloud |
LGTM |
"pouch rm" is used to remove a container which is stopped or created,
if a container is running, you can use "pouch rm -f" to force to remove
the container.
Signed-off-by: skoo87 marckywu@gmail.com