sandbox: Reduce number of calls to UpdateStatus

Also, we distinguish between container and a pod infra
container in the exit monitor as pod infra containers
aren't stored in the main container index.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
Mrunal Patel 2017-08-14 16:33:10 -07:00 committed by Mrunal Patel
parent ea4b6fa55d
commit ce17c5214d
6 changed files with 14 additions and 27 deletions

View file

@ -60,10 +60,6 @@ func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxReque
// it's better not to panic // it's better not to panic
continue continue
} }
if err := s.Runtime().UpdateStatus(podInfraContainer); err != nil {
return nil, err
}
cState := s.Runtime().ContainerStatus(podInfraContainer) cState := s.Runtime().ContainerStatus(podInfraContainer)
created := cState.Created.UnixNano() created := cState.Created.UnixNano()
rStatus := pb.PodSandboxState_SANDBOX_NOTREADY rStatus := pb.PodSandboxState_SANDBOX_NOTREADY

View file

@ -38,10 +38,6 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
// Delete all the containers in the sandbox // Delete all the containers in the sandbox
for _, c := range containers { 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) cState := s.Runtime().ContainerStatus(c)
if cState.Status == oci.ContainerStateCreated || cState.Status == oci.ContainerStateRunning { if cState.Status == oci.ContainerStateCreated || cState.Status == oci.ContainerStateRunning {
if err := s.Runtime().StopContainer(c, -1); err != nil { if err := s.Runtime().StopContainer(c, -1); err != nil {

View file

@ -78,19 +78,9 @@ func (s *Server) runContainer(container *oci.Container, cgroupParent string) err
if err := s.Runtime().CreateContainer(container, cgroupParent); err != nil { if err := s.Runtime().CreateContainer(container, cgroupParent); err != nil {
return err return err
} }
if err := s.Runtime().UpdateStatus(container); err != nil {
return err
}
if err := s.Runtime().StartContainer(container); err != nil { if err := s.Runtime().StartContainer(container); err != nil {
return err return err
} }
if err := s.Runtime().UpdateStatus(container); err != nil {
return err
}
return nil return nil
} }

View file

@ -16,11 +16,6 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
} }
podInfraContainer := sb.InfraContainer() podInfraContainer := sb.InfraContainer()
if err = s.Runtime().UpdateStatus(podInfraContainer); err != nil {
return nil, err
}
s.ContainerStateToDisk(podInfraContainer)
cState := s.Runtime().ContainerStatus(podInfraContainer) cState := s.Runtime().ContainerStatus(podInfraContainer)
netNsPath, err := podInfraContainer.NetNsPath() netNsPath, err := podInfraContainer.NetNsPath()

View file

@ -70,9 +70,6 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
containers = append(containers, podInfraContainer) containers = append(containers, podInfraContainer)
for _, c := range containers { for _, c := range containers {
if err := s.Runtime().UpdateStatus(c); err != nil {
return nil, err
}
cStatus := s.Runtime().ContainerStatus(c) cStatus := s.Runtime().ContainerStatus(c)
if cStatus.Status != oci.ContainerStateStopped { if cStatus.Status != oci.ContainerStateStopped {
if err := s.Runtime().StopContainer(c, -1); err != nil { if err := s.Runtime().StopContainer(c, -1); err != nil {

View file

@ -313,15 +313,28 @@ func (s *Server) StartExitMonitor() {
logrus.Debugf("event: %v", event) logrus.Debugf("event: %v", event)
if event.Op&fsnotify.Create == fsnotify.Create { if event.Op&fsnotify.Create == fsnotify.Create {
containerID := filepath.Base(event.Name) containerID := filepath.Base(event.Name)
logrus.Debugf("container exited: %v", containerID) logrus.Debugf("container or sandbox exited: %v", containerID)
c := s.GetContainer(containerID) c := s.GetContainer(containerID)
if c != nil { if c != nil {
logrus.Debugf("container exited and found: %v", containerID)
err := s.Runtime().UpdateStatus(c) err := s.Runtime().UpdateStatus(c)
if err != nil { if err != nil {
logrus.Warnf("Failed to update container status %s: %v", c, err) logrus.Warnf("Failed to update container status %s: %v", c, err)
} else { } else {
s.ContainerStateToDisk(c) 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: case err := <-watcher.Errors: