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