From 25a73811eeb555bd948f6b474f55147cd10b94cf Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 22 Aug 2016 16:47:11 -0700 Subject: [PATCH] Add server impl for RemoveContainer Signed-off-by: Mrunal Patel --- server/runtime.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/server/runtime.go b/server/runtime.go index c1927d08..ed358937 100644 --- a/server/runtime.go +++ b/server/runtime.go @@ -488,17 +488,30 @@ func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest } if err := s.runtime.StopContainer(c); err != nil { - return nil, fmt.Errorf("failed to stop container %s in sandbox %s: %v", c.Name(), *containerName, err) + return nil, fmt.Errorf("failed to stop container %s: %v", *containerName, err) } return &pb.StopContainerResponse{}, nil - return nil, nil } // RemoveContainer removes the container. If the container is running, the container // should be force removed. -func (s *Server) RemoveContainer(context.Context, *pb.RemoveContainerRequest) (*pb.RemoveContainerResponse, error) { - return nil, nil +func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*pb.RemoveContainerResponse, error) { + containerName := req.ContainerId + + if *containerName == "" { + return nil, fmt.Errorf("PodSandboxId should not be empty") + } + c := s.state.containers[*containerName] + if c == nil { + return nil, fmt.Errorf("specified container not found: %s", *containerName) + } + + if err := s.runtime.DeleteContainer(c); err != nil { + return nil, fmt.Errorf("failed to delete container %s: %v", *containerName, err) + } + + return &pb.RemoveContainerResponse{}, nil } // ListContainers lists all containers by filters.