diff --git a/server/sandbox_list.go b/server/sandbox_list.go index 3e0044cf..c70e6fd2 100644 --- a/server/sandbox_list.go +++ b/server/sandbox_list.go @@ -60,10 +60,6 @@ func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxReque // it's better not to panic continue } - if err := s.Runtime().UpdateStatus(podInfraContainer); err != nil { - return nil, err - } - cState := s.Runtime().ContainerStatus(podInfraContainer) created := cState.Created.UnixNano() rStatus := pb.PodSandboxState_SANDBOX_NOTREADY diff --git a/server/sandbox_remove.go b/server/sandbox_remove.go index e72e1b26..d94470c4 100644 --- a/server/sandbox_remove.go +++ b/server/sandbox_remove.go @@ -38,10 +38,6 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR // Delete all the containers in the sandbox for _, c := range containers { - if err := s.Runtime().UpdateStatus(c); err != nil { - return nil, fmt.Errorf("failed to update container state: %v", err) - } - cState := s.Runtime().ContainerStatus(c) if cState.Status == oci.ContainerStateCreated || cState.Status == oci.ContainerStateRunning { if err := s.Runtime().StopContainer(c, -1); err != nil { diff --git a/server/sandbox_run.go b/server/sandbox_run.go index a26b4bb1..f1159832 100644 --- a/server/sandbox_run.go +++ b/server/sandbox_run.go @@ -78,19 +78,9 @@ func (s *Server) runContainer(container *oci.Container, cgroupParent string) err if err := s.Runtime().CreateContainer(container, cgroupParent); err != nil { return err } - - if err := s.Runtime().UpdateStatus(container); err != nil { - return err - } - if err := s.Runtime().StartContainer(container); err != nil { return err } - - if err := s.Runtime().UpdateStatus(container); err != nil { - return err - } - return nil } diff --git a/server/sandbox_status.go b/server/sandbox_status.go index 17db0a98..be37862f 100644 --- a/server/sandbox_status.go +++ b/server/sandbox_status.go @@ -16,11 +16,6 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR } podInfraContainer := sb.InfraContainer() - if err = s.Runtime().UpdateStatus(podInfraContainer); err != nil { - return nil, err - } - s.ContainerStateToDisk(podInfraContainer) - cState := s.Runtime().ContainerStatus(podInfraContainer) netNsPath, err := podInfraContainer.NetNsPath() diff --git a/server/sandbox_stop.go b/server/sandbox_stop.go index 7687272b..ecff1cfe 100644 --- a/server/sandbox_stop.go +++ b/server/sandbox_stop.go @@ -70,9 +70,6 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque containers = append(containers, podInfraContainer) for _, c := range containers { - if err := s.Runtime().UpdateStatus(c); err != nil { - return nil, err - } cStatus := s.Runtime().ContainerStatus(c) if cStatus.Status != oci.ContainerStateStopped { if err := s.Runtime().StopContainer(c, -1); err != nil { diff --git a/server/server.go b/server/server.go index 141eccbc..601eec89 100644 --- a/server/server.go +++ b/server/server.go @@ -313,15 +313,28 @@ func (s *Server) StartExitMonitor() { logrus.Debugf("event: %v", event) if event.Op&fsnotify.Create == fsnotify.Create { containerID := filepath.Base(event.Name) - logrus.Debugf("container exited: %v", containerID) + logrus.Debugf("container or sandbox exited: %v", containerID) c := s.GetContainer(containerID) if c != nil { + logrus.Debugf("container exited and found: %v", containerID) err := s.Runtime().UpdateStatus(c) if err != nil { logrus.Warnf("Failed to update container status %s: %v", c, err) } else { s.ContainerStateToDisk(c) } + } else { + sb := s.GetSandbox(containerID) + if sb != nil { + c := sb.InfraContainer() + logrus.Debugf("sandbox exited and found: %v", containerID) + err := s.Runtime().UpdateStatus(c) + if err != nil { + logrus.Warnf("Failed to update sandbox infra container status %s: %v", c, err) + } else { + s.ContainerStateToDisk(c) + } + } } } case err := <-watcher.Errors: