diff --git a/client.go b/client.go index 9db4a75f7..00cb3d68c 100644 --- a/client.go +++ b/client.go @@ -158,7 +158,7 @@ func WithRuntime(name string) NewContainerOpts { // NewContainer will create a new container in container with the provided id // the id must be unique within the namespace -func (c *Client) NewContainer(ctx context.Context, id string, spec *specs.Spec, opts ...NewContainerOpts) (Container, error) { +func (c *Client) NewContainer(ctx context.Context, id string, image Image, spec *specs.Spec, opts ...NewContainerOpts) (Container, error) { data, err := json.Marshal(spec) if err != nil { return nil, err @@ -170,6 +170,7 @@ func (c *Client) NewContainer(ctx context.Context, id string, spec *specs.Spec, TypeUrl: specs.Version, Value: data, }, + Image: image.Name(), } for _, o := range opts { if err := o(ctx, c, &container); err != nil { diff --git a/client_test.go b/client_test.go index 5671fe600..2cdcebdff 100644 --- a/client_test.go +++ b/client_test.go @@ -9,6 +9,7 @@ const defaultAddress = "/run/containerd/containerd.sock" func TestNewClient(t *testing.T) { if testing.Short() { + t.Skip() return } client, err := New(defaultAddress) @@ -25,6 +26,7 @@ func TestNewClient(t *testing.T) { func TestImagePull(t *testing.T) { if testing.Short() { + t.Skip() return } client, err := New(defaultAddress) diff --git a/client_windows.go b/client_windows.go index 7de5677a0..548024e5b 100644 --- a/client_windows.go +++ b/client_windows.go @@ -8,7 +8,7 @@ import ( ) func dialer(address string, timeout time.Duration) (net.Conn, error) { - return winio.DialPipe(bindAddress, &timeout) + return winio.DialPipe(address, &timeout) } func dialAddress(address string) string { diff --git a/container.go b/container.go index 1886f227a..7b9bffd8d 100644 --- a/container.go +++ b/container.go @@ -50,10 +50,12 @@ func (c *container) Spec() (*specs.Spec, error) { // Delete deletes an existing container // an error is returned if the container has running tasks -func (c *container) Delete(ctx context.Context) error { +func (c *container) Delete(ctx context.Context) (err error) { // TODO: should the client be the one removing resources attached // to the container at the moment before we have GC? - err := c.client.SnapshotService().Remove(ctx, c.c.RootFS) + if c.c.RootFS != "" { + err = c.client.SnapshotService().Remove(ctx, c.c.RootFS) + } if _, cerr := c.client.ContainerService().Delete(ctx, &containers.DeleteContainerRequest{ ID: c.c.ID, @@ -79,17 +81,19 @@ func (c *container) NewTask(ctx context.Context, ioCreate IOCreation) (Task, err Stdout: i.Stdout, Stderr: i.Stderr, } - // get the rootfs from the snapshotter and add it to the request - mounts, err := c.client.SnapshotService().Mounts(ctx, c.c.RootFS) - if err != nil { - return nil, err - } - for _, m := range mounts { - request.Rootfs = append(request.Rootfs, &mount.Mount{ - Type: m.Type, - Source: m.Source, - Options: m.Options, - }) + if c.c.RootFS != "" { + // get the rootfs from the snapshotter and add it to the request + mounts, err := c.client.SnapshotService().Mounts(ctx, c.c.RootFS) + if err != nil { + return nil, err + } + for _, m := range mounts { + request.Rootfs = append(request.Rootfs, &mount.Mount{ + Type: m.Type, + Source: m.Source, + Options: m.Options, + }) + } } response, err := c.client.TaskService().Create(ctx, request) if err != nil { diff --git a/container_test.go b/container_test.go index bbe67b241..309e8f4fa 100644 --- a/container_test.go +++ b/container_test.go @@ -7,6 +7,7 @@ import ( func TestContainerList(t *testing.T) { if testing.Short() { + t.Skip() return } client, err := New(defaultAddress) @@ -27,6 +28,7 @@ func TestContainerList(t *testing.T) { func TestNewContainer(t *testing.T) { if testing.Short() { + t.Skip() return } client, err := New(defaultAddress) diff --git a/image.go b/image.go index 6e48a52f3..972778daf 100644 --- a/image.go +++ b/image.go @@ -3,6 +3,7 @@ package containerd import "github.com/containerd/containerd/images" type Image interface { + Name() string } var _ = (Image)(&image{}) @@ -12,3 +13,7 @@ type image struct { i images.Image } + +func (i *image) Name() string { + return i.i.Name +} diff --git a/spec.go b/spec.go index 5fa9425d4..53e1fd5f5 100644 --- a/spec.go +++ b/spec.go @@ -4,17 +4,7 @@ import specs "github.com/opencontainers/runtime-spec/specs-go" type SpecOpts func(s *specs.Spec) error -func WithImageRef(ref string) SpecOpts { - return func(s *specs.Spec) error { - if s.Annotations == nil { - s.Annotations = make(map[string]string) - } - s.Annotations["image"] = ref - return nil - } -} - -func WithArgs(args ...string) SpecOpts { +func WithProcessArgs(args ...string) SpecOpts { return func(s *specs.Spec) error { s.Process.Args = args return nil diff --git a/task.go b/task.go index 8acf1d300..9b185ab7e 100644 --- a/task.go +++ b/task.go @@ -14,6 +14,8 @@ import ( "github.com/containerd/fifo" ) +const UnknownExitStatus = 255 + type IO struct { Terminal bool Stdin string @@ -230,12 +232,12 @@ func (t *task) Status(ctx context.Context) (string, error) { func (t *task) Wait(ctx context.Context) (uint32, error) { events, err := t.client.TaskService().Events(ctx, &execution.EventsRequest{}) if err != nil { - return 255, err + return UnknownExitStatus, err } for { e, err := events.Recv() if err != nil { - return 255, err + return UnknownExitStatus, err } if e.Type != taskapi.Event_EXIT { continue @@ -255,7 +257,7 @@ func (t *task) Delete(ctx context.Context) (uint32, error) { ContainerID: t.containerID, }) if err != nil { - return 255, err + return UnknownExitStatus, err } return r.ExitStatus, cerr }