server: fix panic when listing sandboxes
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
56f2b34def
commit
4578cc93d1
2 changed files with 12 additions and 0 deletions
|
@ -313,6 +313,7 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
|
|||
}
|
||||
|
||||
s.releasePodName(sb.name)
|
||||
s.removeSandbox(sandboxID)
|
||||
|
||||
return &pb.RemovePodSandboxResponse{}, nil
|
||||
}
|
||||
|
@ -380,6 +381,11 @@ func (s *Server) ListPodSandbox(context.Context, *pb.ListPodSandboxRequest) (*pb
|
|||
for _, sb := range s.state.sandboxes {
|
||||
podInfraContainerName := sb.name + "-infra"
|
||||
podInfraContainer := sb.getContainer(podInfraContainerName)
|
||||
if podInfraContainer == nil {
|
||||
// this can't really happen, but if it does because of a bug
|
||||
// it's better not to panic
|
||||
continue
|
||||
}
|
||||
if err := s.runtime.UpdateStatus(podInfraContainer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -179,6 +179,12 @@ func (s *Server) hasSandbox(id string) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
func (s *Server) removeSandbox(id string) {
|
||||
s.stateLock.Lock()
|
||||
delete(s.state.sandboxes, id)
|
||||
s.stateLock.Unlock()
|
||||
}
|
||||
|
||||
func (s *Server) addContainer(c *oci.Container) {
|
||||
s.stateLock.Lock()
|
||||
sandbox := s.state.sandboxes[c.Sandbox()]
|
||||
|
|
Loading…
Reference in a new issue