From 50bea08c5088842dbe5b5cefcb2dc58d29cefcc2 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 30 Sep 2016 12:23:48 -0700 Subject: [PATCH 1/2] Remove containers from state on pod remove Signed-off-by: Mrunal Patel --- server/sandbox.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/sandbox.go b/server/sandbox.go index 5f359f4e..f1a5583e 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -290,7 +290,8 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR return nil, fmt.Errorf("specified sandbox not found: %s", sandboxID) } - podInfraContainer := sb.name + "-infra" + podInfraContainerName := sb.name + "-infra" + var podInfraContainer *oci.Container // Delete all the containers in the sandbox for _, c := range sb.containers.List() { @@ -309,13 +310,17 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR return nil, fmt.Errorf("failed to delete container %s in sandbox %s: %v", c.Name(), sandboxID, err) } - if podInfraContainer == c.Name() { + if podInfraContainerName == c.Name() { + podInfraContainer = c continue } + containerDir := filepath.Join(s.runtime.ContainerDir(), c.Name()) if err := os.RemoveAll(containerDir); err != nil { return nil, fmt.Errorf("failed to remove container %s directory: %v", c.Name(), err) } + + s.removeContainer(c) } // Remove the files related to the sandbox @@ -323,6 +328,7 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR if err := os.RemoveAll(podSandboxDir); err != nil { return nil, fmt.Errorf("failed to remove sandbox %s directory: %v", sandboxID, err) } + s.removeContainer(podInfraContainer) s.releasePodName(sb.name) s.removeSandbox(sandboxID) From 23858b7ed6fb99cc497bad684905ddcb4acf3cd4 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 30 Sep 2016 12:24:16 -0700 Subject: [PATCH 2/2] Add pod list and ctr list calls to ctr lifecycle test Signed-off-by: Mrunal Patel --- test/ctr.bats | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/ctr.bats b/test/ctr.bats index c2f8fe02..5f808fea 100644 --- a/test/ctr.bats +++ b/test/ctr.bats @@ -48,10 +48,16 @@ function teardown() { [ "$status" -eq 0 ] echo "$output" pod_id="$output" + run ocic pod list + echo "$output" + [ "$status" -eq 0 ] run ocic ctr create --config "$TESTDATA"/container_redis.json --pod "$pod_id" echo "$output" [ "$status" -eq 0 ] ctr_id="$output" + run ocic ctr list + echo "$output" + [ "$status" -eq 0 ] run ocic ctr status --id "$ctr_id" echo "$output" [ "$status" -eq 0 ] @@ -61,21 +67,42 @@ function teardown() { run ocic ctr status --id "$ctr_id" echo "$output" [ "$status" -eq 0 ] + run ocic ctr list + echo "$output" + [ "$status" -eq 0 ] run ocic ctr stop --id "$ctr_id" echo "$output" [ "$status" -eq 0 ] run ocic ctr status --id "$ctr_id" echo "$output" [ "$status" -eq 0 ] + run ocic ctr list + echo "$output" + [ "$status" -eq 0 ] run ocic ctr remove --id "$ctr_id" echo "$output" [ "$status" -eq 0 ] + run ocic ctr list + echo "$output" + [ "$status" -eq 0 ] run ocic pod stop --id "$pod_id" echo "$output" [ "$status" -eq 0 ] + run ocic pod list + echo "$output" + [ "$status" -eq 0 ] + run ocic ctr list + echo "$output" + [ "$status" -eq 0 ] run ocic pod remove --id "$pod_id" echo "$output" [ "$status" -eq 0 ] + run ocic pod list + echo "$output" + [ "$status" -eq 0 ] + run ocic ctr list + echo "$output" + [ "$status" -eq 0 ] stop_ocid cleanup_pods }