github.com/georgethebeatle/containerd@v0.2.5/supervisor/get_containers.go (about)

     1  package supervisor
     2  
     3  import "github.com/docker/containerd/runtime"
     4  
     5  // GetContainersTask holds needed parameters to retrieve a list of
     6  // containers
     7  type GetContainersTask struct {
     8  	baseTask
     9  	ID       string
    10  	GetState func(c runtime.Container) (interface{}, error)
    11  
    12  	Containers []runtime.Container
    13  	States     []interface{}
    14  }
    15  
    16  func (s *Supervisor) getContainers(t *GetContainersTask) error {
    17  
    18  	if t.ID != "" {
    19  		ci, ok := s.containers[t.ID]
    20  		if !ok {
    21  			return ErrContainerNotFound
    22  		}
    23  		t.Containers = append(t.Containers, ci.container)
    24  		if t.GetState != nil {
    25  			st, err := t.GetState(ci.container)
    26  			if err != nil {
    27  				return err
    28  			}
    29  			t.States = append(t.States, st)
    30  		}
    31  
    32  		return nil
    33  	}
    34  
    35  	for _, ci := range s.containers {
    36  		t.Containers = append(t.Containers, ci.container)
    37  		if t.GetState != nil {
    38  			st, err := t.GetState(ci.container)
    39  			if err != nil {
    40  				return err
    41  			}
    42  			t.States = append(t.States, st)
    43  		}
    44  	}
    45  
    46  	return nil
    47  }