Export GRPC services from client
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
608e6daaa4
commit
a2b0824720
36
client.go
36
client.go
@ -84,7 +84,7 @@ type Client struct {
|
||||
|
||||
// Containers returns all containers created in containerd
|
||||
func (c *Client) Containers(ctx context.Context) ([]Container, error) {
|
||||
r, err := c.containers().List(ctx, &containers.ListContainersRequest{})
|
||||
r, err := c.ContainerService().List(ctx, &containers.ListContainersRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -109,7 +109,7 @@ func WithContainerLabels(labels map[string]string) NewContainerOpts {
|
||||
func WithExistingRootFS(id string) NewContainerOpts {
|
||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||
// check that the snapshot exists, if not, fail on creation
|
||||
if _, err := client.snapshotter().Mounts(ctx, id); err != nil {
|
||||
if _, err := client.SnapshotService().Mounts(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
c.RootFS = id
|
||||
@ -121,11 +121,11 @@ func WithExistingRootFS(id string) NewContainerOpts {
|
||||
// root filesystem in read-write mode
|
||||
func WithNewRootFS(id string, i Image) NewContainerOpts {
|
||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||
diffIDs, err := i.(*image).i.RootFS(ctx, client.content())
|
||||
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := client.snapshotter().Prepare(ctx, id, identity.ChainID(diffIDs).String()); err != nil {
|
||||
if _, err := client.SnapshotService().Prepare(ctx, id, identity.ChainID(diffIDs).String()); err != nil {
|
||||
return err
|
||||
}
|
||||
c.RootFS = id
|
||||
@ -137,11 +137,11 @@ func WithNewRootFS(id string, i Image) NewContainerOpts {
|
||||
// root filesystem in read-only mode
|
||||
func WithNewReadonlyRootFS(id string, i Image) NewContainerOpts {
|
||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||
diffIDs, err := i.(*image).i.RootFS(ctx, client.content())
|
||||
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := client.snapshotter().View(ctx, id, identity.ChainID(diffIDs).String()); err != nil {
|
||||
if _, err := client.SnapshotService().View(ctx, id, identity.ChainID(diffIDs).String()); err != nil {
|
||||
return err
|
||||
}
|
||||
c.RootFS = id
|
||||
@ -176,7 +176,7 @@ func (c *Client) NewContainer(ctx context.Context, id string, spec *specs.Spec,
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
r, err := c.containers().Create(ctx, &containers.CreateContainerRequest{
|
||||
r, err := c.ContainerService().Create(ctx, &containers.CreateContainerRequest{
|
||||
Container: container,
|
||||
})
|
||||
if err != nil {
|
||||
@ -202,9 +202,9 @@ func defaultPullContext() *PullContext {
|
||||
|
||||
func WithPullUnpack(client *Client, c *PullContext) error {
|
||||
c.Unpacker = &snapshotUnpacker{
|
||||
store: client.content(),
|
||||
diff: client.diff(),
|
||||
snapshotter: client.snapshotter(),
|
||||
store: client.ContentStore(),
|
||||
diff: client.DiffService(),
|
||||
snapshotter: client.SnapshotService(),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -265,7 +265,7 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...PullOpts) (Image,
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
store := c.content()
|
||||
store := c.ContentStore()
|
||||
|
||||
name, desc, err := pullCtx.Resolver.Resolve(ctx, ref)
|
||||
if err != nil {
|
||||
@ -283,7 +283,7 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...PullOpts) (Image,
|
||||
if err := images.Dispatch(ctx, images.Handlers(handlers...), desc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
is := c.images()
|
||||
is := c.ImageService()
|
||||
if err := is.Put(ctx, name, desc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -307,26 +307,26 @@ func (c *Client) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
func (c *Client) containers() containers.ContainersClient {
|
||||
func (c *Client) ContainerService() containers.ContainersClient {
|
||||
return containers.NewContainersClient(c.conn)
|
||||
}
|
||||
|
||||
func (c *Client) content() content.Store {
|
||||
func (c *Client) ContentStore() content.Store {
|
||||
return contentservice.NewStoreFromClient(contentapi.NewContentClient(c.conn))
|
||||
}
|
||||
|
||||
func (c *Client) snapshotter() snapshot.Snapshotter {
|
||||
func (c *Client) SnapshotService() snapshot.Snapshotter {
|
||||
return snapshotservice.NewSnapshotterFromClient(snapshotapi.NewSnapshotClient(c.conn))
|
||||
}
|
||||
|
||||
func (c *Client) tasks() execution.TasksClient {
|
||||
func (c *Client) TaskService() execution.TasksClient {
|
||||
return execution.NewTasksClient(c.conn)
|
||||
}
|
||||
|
||||
func (c *Client) images() images.Store {
|
||||
func (c *Client) ImageService() images.Store {
|
||||
return imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(c.conn))
|
||||
}
|
||||
|
||||
func (c *Client) diff() diff.DiffService {
|
||||
func (c *Client) DiffService() diff.DiffService {
|
||||
return diffservice.NewDiffServiceFromClient(diffapi.NewDiffClient(c.conn))
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ func (c *container) Spec() (*specs.Spec, error) {
|
||||
func (c *container) Delete(ctx context.Context) error {
|
||||
// TODO: should the client be the one removing resources attached
|
||||
// to the container at the moment before we have GC?
|
||||
err := c.client.snapshotter().Remove(ctx, c.c.RootFS)
|
||||
err := c.client.SnapshotService().Remove(ctx, c.c.RootFS)
|
||||
|
||||
if _, cerr := c.client.containers().Delete(ctx, &containers.DeleteContainerRequest{
|
||||
if _, cerr := c.client.ContainerService().Delete(ctx, &containers.DeleteContainerRequest{
|
||||
ID: c.c.ID,
|
||||
}); err == nil {
|
||||
err = cerr
|
||||
@ -80,7 +80,7 @@ func (c *container) NewTask(ctx context.Context, ioCreate IOCreation) (Task, err
|
||||
Stderr: i.Stderr,
|
||||
}
|
||||
// get the rootfs from the snapshotter and add it to the request
|
||||
mounts, err := c.client.snapshotter().Mounts(ctx, c.c.RootFS)
|
||||
mounts, err := c.client.SnapshotService().Mounts(ctx, c.c.RootFS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -91,7 +91,7 @@ func (c *container) NewTask(ctx context.Context, ioCreate IOCreation) (Task, err
|
||||
Options: m.Options,
|
||||
})
|
||||
}
|
||||
response, err := c.client.tasks().Create(ctx, request)
|
||||
response, err := c.client.TaskService().Create(ctx, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ func WithHostNamespace(ns specs.LinuxNamespaceType) SpecOpts {
|
||||
func WithImage(ctx context.Context, i Image) SpecOpts {
|
||||
return func(s *specs.Spec) error {
|
||||
image := i.(*image)
|
||||
store := image.client.content()
|
||||
store := image.client.ContentStore()
|
||||
ic, err := image.i.Config(ctx, store)
|
||||
if err != nil {
|
||||
return err
|
||||
|
14
task.go
14
task.go
@ -185,14 +185,14 @@ func (t *task) Pid() uint32 {
|
||||
}
|
||||
|
||||
func (t *task) Start(ctx context.Context) error {
|
||||
_, err := t.client.tasks().Start(ctx, &execution.StartRequest{
|
||||
_, err := t.client.TaskService().Start(ctx, &execution.StartRequest{
|
||||
ContainerID: t.containerID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *task) Kill(ctx context.Context, s syscall.Signal) error {
|
||||
_, err := t.client.tasks().Kill(ctx, &execution.KillRequest{
|
||||
_, err := t.client.TaskService().Kill(ctx, &execution.KillRequest{
|
||||
Signal: uint32(s),
|
||||
ContainerID: t.containerID,
|
||||
PidOrAll: &execution.KillRequest_All{
|
||||
@ -203,21 +203,21 @@ func (t *task) Kill(ctx context.Context, s syscall.Signal) error {
|
||||
}
|
||||
|
||||
func (t *task) Pause(ctx context.Context) error {
|
||||
_, err := t.client.tasks().Pause(ctx, &execution.PauseRequest{
|
||||
_, err := t.client.TaskService().Pause(ctx, &execution.PauseRequest{
|
||||
ContainerID: t.containerID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *task) Resume(ctx context.Context) error {
|
||||
_, err := t.client.tasks().Resume(ctx, &execution.ResumeRequest{
|
||||
_, err := t.client.TaskService().Resume(ctx, &execution.ResumeRequest{
|
||||
ContainerID: t.containerID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *task) Status(ctx context.Context) (string, error) {
|
||||
r, err := t.client.tasks().Info(ctx, &execution.InfoRequest{
|
||||
r, err := t.client.TaskService().Info(ctx, &execution.InfoRequest{
|
||||
ContainerID: t.containerID,
|
||||
})
|
||||
if err != nil {
|
||||
@ -228,7 +228,7 @@ func (t *task) Status(ctx context.Context) (string, error) {
|
||||
|
||||
// Wait is a blocking call that will wait for the task to exit and return the exit status
|
||||
func (t *task) Wait(ctx context.Context) (uint32, error) {
|
||||
events, err := t.client.tasks().Events(ctx, &execution.EventsRequest{})
|
||||
events, err := t.client.TaskService().Events(ctx, &execution.EventsRequest{})
|
||||
if err != nil {
|
||||
return 255, err
|
||||
}
|
||||
@ -251,7 +251,7 @@ func (t *task) Wait(ctx context.Context) (uint32, error) {
|
||||
// during cleanup
|
||||
func (t *task) Delete(ctx context.Context) (uint32, error) {
|
||||
cerr := t.io.Close()
|
||||
r, err := t.client.tasks().Delete(ctx, &execution.DeleteRequest{
|
||||
r, err := t.client.TaskService().Delete(ctx, &execution.DeleteRequest{
|
||||
ContainerID: t.containerID,
|
||||
})
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user