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: add "volume" flag when remove container #1255

Merged
merged 1 commit into from
May 3, 2018

Conversation

rudyfly
Copy link
Collaborator

@rudyfly rudyfly commented Apr 28, 2018

Ⅰ. Describe what this PR did

Add "volume" flag when remove container, it is used to remove these
volumes that is created by container.

Ⅱ. Does this pull request fix one issue?

NONE

Ⅲ. Describe how you did it

Ⅳ. Describe how to verify it

  1. create volume
# pouch volume create -n rmVolume-test-volume
Scope:
Status:       map[mount:/data/pouch/volume sifter:Default]
CreatedAt:    2018-4-28 15:27:28
Driver:       local
Labels:       map[]
Mountpoint:   /data/pouch/volume/rmVolume-test-volume
Name:         rmVolume-test-volume
  1. run container with volume
# pouch run --name rmVolume-test -d -v rmVolume-test-volume:/mnt -v /home  busybox:latest top
  1. check volumes
# pouch volume ls
DRIVER   VOLUME NAME
local    rmVolume-test-volume
local    2b435c1fada0cf10064f3e9e39de3b82737bbdd6207d6f4f1e9e830ee76f2812
  1. remove container with -v
# pouch rm -vf rmVolume-test
  1. check the volume exist
# pouch volume ls
DRIVER   VOLUME NAME
local    rmVolume-test-volume

Ⅴ. Special notes for reviews

Signed-off-by: Rudy Zhang rudyflyzhang@gmail.com

@codecov-io
Copy link

codecov-io commented Apr 28, 2018

Codecov Report

Merging #1255 into master will increase coverage by 0.04%.
The diff coverage is 2.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1255      +/-   ##
==========================================
+ Coverage   15.24%   15.28%   +0.04%     
==========================================
  Files         172      172              
  Lines       10715    10684      -31     
==========================================
  Hits         1633     1633              
+ Misses       8962     8930      -32     
- Partials      120      121       +1
Impacted Files Coverage Δ
daemon/mgr/container_types.go 25.31% <ø> (ø) ⬆️
pkg/errtypes/errors.go 31.57% <0%> (-3.72%) ⬇️
daemon/mgr/container.go 0% <0%> (ø) ⬆️
daemon/mgr/volume.go 0% <0%> (ø) ⬆️
cli/run.go 0% <0%> (ø) ⬆️
daemon/mgr/cri.go 0% <0%> (ø) ⬆️
apis/server/container_bridge.go 0% <0%> (ø) ⬆️
cli/rm.go 0% <0%> (ø) ⬆️
apis/server/volume_bridge.go 0% <0%> (ø) ⬆️
client/container_remove.go 81.81% <50%> (-18.19%) ⬇️
... and 10 more

cli/rm.go Outdated
flagSet := r.cmd.Flags()

flagSet.BoolVarP(&r.force, "force", "f", false, "if the container is running, force to remove it")
flagSet.BoolVarP(&r.removeVolume, "volumes", "v", false, "remove container's volumes that create by the container")
Copy link
Contributor

Choose a reason for hiding this comment

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

it's better to use removeVolume instead of removeVolumes

@@ -2271,6 +2271,12 @@ func (mgr *ContainerManager) detachVolumes(ctx context.Context, c *ContainerMeta
}

mgr.VolumeMgr.Detach(ctx, name, option)
Copy link
Contributor

@HusterWan HusterWan May 3, 2018

Choose a reason for hiding this comment

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

Detach is to umount volume mountpoint, so if the volume is attached to multi containers, does this action will cause other containers' volumes unused?

Another thing: do we distinct volumes created by user and pouchd, because users may delete volumes created by themself, so we just need delete volumes created by pouchd?

@@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/client"
"github.com/pkg/errors"
Copy link
Contributor

Choose a reason for hiding this comment

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

add new blank line here

@rudyfly rudyfly force-pushed the remove-volume branch 2 times, most recently from 3eed41b to 50fd6cd Compare May 3, 2018 06:49
@rudyfly
Copy link
Collaborator Author

rudyfly commented May 3, 2018

PTAL @HusterWan @fuweid

@@ -24,7 +26,7 @@ func TestContainerRemoveNotFoundError(t *testing.T) {
client := &APIClient{
HTTPCli: newMockClient(errorMockResponse(http.StatusNotFound, "Not Found")),
}
err := client.ContainerRemove(context.Background(), "no contaienr", true)
err := client.ContainerRemove(context.Background(), "no contaienr", &types.ContainerRemoveOptions{Force: true})
Copy link
Contributor

Choose a reason for hiding this comment

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

%s/contaienr/container :)

}

cid, ok := options[types.OptionRef]
if ok && len(cid) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

cid == "" will be better WDYT???

Copy link
Contributor

Choose a reason for hiding this comment

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

@HusterWan I think two kinds are the same. Just keep the consistent in one project.

Add "volume" flag when remove container, it is used to remove these
volumes that is created by container.

Signed-off-by: Rudy Zhang <rudyflyzhang@gmail.com>
@HusterWan
Copy link
Contributor

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label May 3, 2018
@HusterWan HusterWan merged commit 9459d46 into AliyunContainerService:master May 3, 2018
@rudyfly rudyfly deleted the remove-volume branch October 29, 2018 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
areas/storage kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants