From a8e7e22a79cda4b20b496c228b7ec30f2146308e Mon Sep 17 00:00:00 2001 From: Gao feng Date: Wed, 19 Oct 2016 19:06:48 +0800 Subject: [PATCH] do not allow to remove infra container Infra container is special, sandbox won't work well without infra container. If user really want to remove it, they should remove sanbox instead. this also fix a panic due to c.state is nil. 1, remove infra container 2, restart ocid 3, ocic ctr list Signed-off-by: Gao feng --- server/container.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/container.go b/server/container.go index c690c68c..c36ebb71 100644 --- a/server/container.go +++ b/server/container.go @@ -381,6 +381,16 @@ func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerReq return nil, err } + sb := s.getSandbox(c.Sandbox()) + if sb == nil { + return nil, fmt.Errorf("failed to find sandbox for container %s", c.ID()) + } + + podInfraContainerName := sb.name + "-infra" + if podInfraContainerName == c.Name() { + return nil, fmt.Errorf("can not delete Infra container %s\n", c.ID()) + } + if err := s.runtime.UpdateStatus(c); err != nil { return nil, fmt.Errorf("failed to update container state: %v", err) }