Change Container interface to include Info

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-02-15 16:59:58 -08:00
parent c869eb0c61
commit 47ececd6b8
8 changed files with 23 additions and 23 deletions

View File

@ -124,7 +124,7 @@ func getTempDir(id string) (string, error) {
return tmpDir, nil
}
func waitContainer(events execution.ContainerService_EventsClient, respose *execution.CreateResponse) (uint32, error) {
func waitContainer(events execution.ContainerService_EventsClient, response *execution.CreateResponse) (uint32, error) {
for {
e, err := events.Recv()
if err != nil {
@ -133,8 +133,8 @@ func waitContainer(events execution.ContainerService_EventsClient, respose *exec
if e.Type != container.Event_EXIT {
continue
}
if e.ID == respose.ID &&
e.Pid == respose.Pid {
if e.ID == response.ID &&
e.Pid == response.Pid {
return e.ExitStatus, nil
}
}

View File

@ -56,7 +56,7 @@ func (c *collector) collect(r Runtime) error {
// It forwards events until the channels are closed or the EventWriter
// returns an error
// This is a blocking call
func (c *collector) forward(w EventWriter) (err error) {
func (c *collector) forward(w EventWriter) error {
client := &eventClient{
w: w,
eCh: make(chan error, 1),
@ -64,9 +64,7 @@ func (c *collector) forward(w EventWriter) (err error) {
c.mu.Lock()
c.eventClients[client] = struct{}{}
c.mu.Unlock()
if serr := <-client.eCh; serr != nil {
err = serr
}
err := <-client.eCh
c.mu.Lock()
delete(c.eventClients, client)
c.mu.Unlock()

View File

@ -2,11 +2,14 @@ package containerd
import "golang.org/x/net/context"
type ContainerInfo struct {
ID string
Runtime string
}
type Container interface {
// ID of the container
ID() string
// Runtime returns the runtime name that the container was created with
Runtime() string
// Information of the container
Info() ContainerInfo
// Start the container's user defined process
Start(context.Context) error
// State returns the container's state

View File

@ -25,12 +25,11 @@ type Container struct {
shim shim.ShimClient
}
func (c *Container) ID() string {
return c.id
}
func (Container) Runtime() string {
return runtimeName
func (c *Container) Info() containerd.ContainerInfo {
return containerd.ContainerInfo{
ID: c.id,
Runtime: runtimeName,
}
}
func (c *Container) Start(ctx context.Context) error {

View File

@ -51,7 +51,6 @@ type Runtime struct {
func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateOpts) (containerd.Container, error) {
path, err := r.newBundle(id, opts.Spec)
if err != nil {
os.RemoveAll(path)
return nil, err
}
s, err := newShim(path)

View File

@ -72,7 +72,7 @@ type Runtime interface {
Create(ctx context.Context, id string, opts CreateOpts) (Container, error)
// Containers returns all the current containers for the runtime
Containers() ([]Container, error)
// Delete returns the container in the runtime
// Delete removes the container in the runtime
Delete(ctx context.Context, c Container) error
// Events returns events for the runtime and all containers created by the runtime
Events(context.Context) <-chan *Event

View File

@ -47,6 +47,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateRequest) (*api.Create
}
state, err := c.State(ctx)
if err != nil {
s.s.Delete(ctx, r.ID)
return nil, err
}
return &api.CreateResponse{
@ -92,7 +93,7 @@ func (s *Service) List(ctx context.Context, r *api.ListRequest) (*api.ListRespon
status = container.Status_PAUSED
}
resp.Containers = append(resp.Containers, &container.Container{
ID: c.ID(),
ID: c.Info().ID,
Pid: state.Pid(),
Status: status,
})

View File

@ -22,7 +22,7 @@ func NewSupervisor(ctx context.Context, runtimes map[string]Runtime) (*Superviso
return nil, err
}
for _, c := range containers {
s.containers[c.ID()] = c
s.containers[c.Info().ID] = c
}
}
return s, nil
@ -59,7 +59,7 @@ func (s *Supervisor) Create(ctx context.Context, id, runtime string, opts Create
if err != nil {
return nil, err
}
s.containers[c.ID()] = c
s.containers[c.Info().ID] = c
return c, nil
}
@ -71,7 +71,7 @@ func (s *Supervisor) Delete(ctx context.Context, id string) error {
if !ok {
return ErrContainerNotExist
}
err := s.runtimes[c.Runtime()].Delete(ctx, c)
err := s.runtimes[c.Info().Runtime].Delete(ctx, c)
if err != nil {
return err
}