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 rename #220
Conversation
That is so great for us to have your contribution. @zeppp 1.define api in swagger.yml I admit that will bother a lot, but I think it is also important to maintain a pouch in high quality. Would you like you to update this? And please feel free to tell us if you need any help. Thanks again. |
I will define this in swagger soon. |
I have defined the api in swagger.There is no changes in types because I didn't add new model in swagger. |
apis/server/container_bridge.go
Outdated
return err | ||
} | ||
|
||
resp.WriteHeader(http.StatusOK) |
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.
You defined 204, but here is 200.
Please make this consistent.
cli/rename.go
Outdated
newName := args[1] | ||
|
||
if err := apiClient.ContainerRename(container, newName); err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to rename container %s to %s %v \n", container, newName, 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.
Please do not output error here, you can just return err
, since https://github.com/alibaba/pouch/blob/master/cli/main.go#L31 will output error message.
cli/rename.go
Outdated
rc.cmd = &cobra.Command{ | ||
Use: "rename [container] [newName]", | ||
Short: "Rename a exist container with newName", | ||
Args: cobra.MinimumNArgs(2), |
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/MinimumNArgs/ExactArgs
cli/rename.go
Outdated
|
||
rc.cmd = &cobra.Command{ | ||
Use: "rename [container] [newName]", | ||
Short: "Rename a exist container with newName", |
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 Long description and examples as well, like the create command does: https://github.com/alibaba/pouch/blob/master/cli/create.go#L28 and https://github.com/alibaba/pouch/blob/master/cli/create.go#L33 .
It helps a lot to generate cli docs. It is a feature merged just this morning. So maybe you have no idea about this. 😄
client/container.go
Outdated
@@ -106,3 +106,14 @@ func (client *APIClient) ContainerStartExec(execid string, config *types.ExecSta | |||
|
|||
return client.hijack("/exec/"+execid+"/start", url.Values{}, config, header) | |||
} | |||
|
|||
//ContainerRename rename 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.
// ContainerRename renames a container.
add a whitespace after // and use renames please.
client/container.go
Outdated
//ContainerRename rename a container. | ||
func (client *APIClient) ContainerRename(name string, newName string) error { | ||
q := url.Values{} | ||
q.Add("newName", newName) |
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 swagger.yml, you add a query which is named name
, while here the query name is newName
. Please make sure the name is consistent.
daemon/mgr/container.go
Outdated
@@ -48,6 +48,9 @@ type ContainerMgr interface { | |||
|
|||
// Remove removes a container, it may be running or stopped and so on. | |||
Remove(ctx context.Context, name string, option *ContainerRemoveOption) error | |||
|
|||
// Rename rename 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.
renames
daemon/mgr/container.go
Outdated
@@ -364,6 +367,32 @@ func (cm *ContainerManager) List(ctx context.Context) ([]*types.ContainerInfo, e | |||
return cis, nil | |||
} | |||
|
|||
// Rename rename a exist 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.
renames an existent
daemon/mgr/container.go
Outdated
) | ||
|
||
if cm.NameToID.Get(newName).Exist() { | ||
return errors.New("The newName already exists") |
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.
Try to use pkg https://github.com/alibaba/pouch/blob/master/pkg/httputils/http_error.go to wrap the error with status code 409 which is defined in your swagger.yml.
Thanks a lot! I will modify these soon. |
865b80a
to
b31c07b
Compare
cbe12cf
to
5b584f7
Compare
@zeppp Thanks for your contribution. 🍻 |
Work is done. |
LGTM, thanks a lot for your contribution and lots of update you made. |
Signed-off-by: zeppp zeppp1995@gmail.com
1.Describe what this PR did
pouch rename [container] [newName]
rename a container with new name.2.Does this pull request fix one issue?
3.Describe how you did it
4.Describe how to verify it
5.Special notes for reviews