container_list: guard against list filter being nil
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
bc4319c7a8
commit
8bdb7b912d
1 changed files with 28 additions and 26 deletions
|
@ -38,38 +38,40 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
|
||||||
logrus.Debugf("ListContainersRequest %+v", req)
|
logrus.Debugf("ListContainersRequest %+v", req)
|
||||||
|
|
||||||
var ctrs []*pb.Container
|
var ctrs []*pb.Container
|
||||||
filter := req.Filter
|
filter := req.GetFilter()
|
||||||
ctrList, err := s.ContainerServer.ListContainers()
|
ctrList, err := s.ContainerServer.ListContainers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter using container id and pod id first.
|
if filter != nil {
|
||||||
if filter.Id != "" {
|
// Filter using container id and pod id first.
|
||||||
id, err := s.CtrIDIndex().Get(filter.Id)
|
if filter.Id != "" {
|
||||||
if err != nil {
|
id, err := s.CtrIDIndex().Get(filter.Id)
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
c := s.ContainerServer.GetContainer(id)
|
|
||||||
if c != nil {
|
|
||||||
if filter.PodSandboxId != "" {
|
|
||||||
if c.Sandbox() == filter.PodSandboxId {
|
|
||||||
ctrList = []*oci.Container{c}
|
|
||||||
} else {
|
|
||||||
ctrList = []*oci.Container{}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ctrList = []*oci.Container{c}
|
|
||||||
}
|
}
|
||||||
}
|
c := s.ContainerServer.GetContainer(id)
|
||||||
} else {
|
if c != nil {
|
||||||
if filter.PodSandboxId != "" {
|
if filter.PodSandboxId != "" {
|
||||||
pod := s.ContainerServer.GetSandbox(filter.PodSandboxId)
|
if c.Sandbox() == filter.PodSandboxId {
|
||||||
if pod == nil {
|
ctrList = []*oci.Container{c}
|
||||||
ctrList = []*oci.Container{}
|
} else {
|
||||||
} else {
|
ctrList = []*oci.Container{}
|
||||||
ctrList = pod.Containers().List()
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ctrList = []*oci.Container{c}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if filter.PodSandboxId != "" {
|
||||||
|
pod := s.ContainerServer.GetSandbox(filter.PodSandboxId)
|
||||||
|
if pod == nil {
|
||||||
|
ctrList = []*oci.Container{}
|
||||||
|
} else {
|
||||||
|
ctrList = pod.Containers().List()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue