Merge pull request #2341 from dmcgowan/move-client-content-snapshot

Move client implementations for content store and snapshotter
This commit is contained in:
Phil Estes 2018-05-25 13:47:39 -04:00 committed by GitHub
commit e9434a10bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 64 deletions

View File

@ -38,6 +38,7 @@ import (
versionservice "github.com/containerd/containerd/api/services/version/v1" versionservice "github.com/containerd/containerd/api/services/version/v1"
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
contentproxy "github.com/containerd/containerd/content/proxy"
"github.com/containerd/containerd/defaults" "github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events" "github.com/containerd/containerd/events"
@ -49,6 +50,7 @@ import (
"github.com/containerd/containerd/remotes/docker" "github.com/containerd/containerd/remotes/docker"
"github.com/containerd/containerd/remotes/docker/schema1" "github.com/containerd/containerd/remotes/docker/schema1"
"github.com/containerd/containerd/snapshots" "github.com/containerd/containerd/snapshots"
snproxy "github.com/containerd/containerd/snapshots/proxy"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
ptypes "github.com/gogo/protobuf/types" ptypes "github.com/gogo/protobuf/types"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@ -464,7 +466,7 @@ func (c *Client) ContentStore() content.Store {
if c.contentStore != nil { if c.contentStore != nil {
return c.contentStore return c.contentStore
} }
return NewContentStoreFromClient(contentapi.NewContentClient(c.conn)) return contentproxy.NewContentStore(contentapi.NewContentClient(c.conn))
} }
// SnapshotService returns the underlying snapshotter for the provided snapshotter name // SnapshotService returns the underlying snapshotter for the provided snapshotter name
@ -472,7 +474,7 @@ func (c *Client) SnapshotService(snapshotterName string) snapshots.Snapshotter {
if c.snapshotters != nil { if c.snapshotters != nil {
return c.snapshotters[snapshotterName] return c.snapshotters[snapshotterName]
} }
return NewSnapshotterFromClient(snapshotsapi.NewSnapshotsClient(c.conn), snapshotterName) return snproxy.NewSnapshotter(snapshotsapi.NewSnapshotsClient(c.conn), snapshotterName)
} }
// TaskService returns the underlying TasksClient // TaskService returns the underlying TasksClient

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package containerd package proxy
import ( import (
"context" "context"

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package containerd package proxy
import ( import (
"context" "context"
@ -27,19 +27,20 @@ import (
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
) )
type remoteContent struct { type proxyContentStore struct {
client contentapi.ContentClient client contentapi.ContentClient
} }
// NewContentStoreFromClient returns a new content store // NewContentStore returns a new content store which communicates over a GRPC
func NewContentStoreFromClient(client contentapi.ContentClient) content.Store { // connection using the containerd content GRPC API.
return &remoteContent{ func NewContentStore(client contentapi.ContentClient) content.Store {
return &proxyContentStore{
client: client, client: client,
} }
} }
func (rs *remoteContent) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) { func (pcs *proxyContentStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
resp, err := rs.client.Info(ctx, &contentapi.InfoRequest{ resp, err := pcs.client.Info(ctx, &contentapi.InfoRequest{
Digest: dgst, Digest: dgst,
}) })
if err != nil { if err != nil {
@ -49,8 +50,8 @@ func (rs *remoteContent) Info(ctx context.Context, dgst digest.Digest) (content.
return infoFromGRPC(resp.Info), nil return infoFromGRPC(resp.Info), nil
} }
func (rs *remoteContent) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error { func (pcs *proxyContentStore) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
session, err := rs.client.List(ctx, &contentapi.ListContentRequest{ session, err := pcs.client.List(ctx, &contentapi.ListContentRequest{
Filters: filters, Filters: filters,
}) })
if err != nil { if err != nil {
@ -77,8 +78,8 @@ func (rs *remoteContent) Walk(ctx context.Context, fn content.WalkFunc, filters
return nil return nil
} }
func (rs *remoteContent) Delete(ctx context.Context, dgst digest.Digest) error { func (pcs *proxyContentStore) Delete(ctx context.Context, dgst digest.Digest) error {
if _, err := rs.client.Delete(ctx, &contentapi.DeleteContentRequest{ if _, err := pcs.client.Delete(ctx, &contentapi.DeleteContentRequest{
Digest: dgst, Digest: dgst,
}); err != nil { }); err != nil {
return errdefs.FromGRPC(err) return errdefs.FromGRPC(err)
@ -87,8 +88,8 @@ func (rs *remoteContent) Delete(ctx context.Context, dgst digest.Digest) error {
return nil return nil
} }
func (rs *remoteContent) ReaderAt(ctx context.Context, dgst digest.Digest) (content.ReaderAt, error) { func (pcs *proxyContentStore) ReaderAt(ctx context.Context, dgst digest.Digest) (content.ReaderAt, error) {
i, err := rs.Info(ctx, dgst) i, err := pcs.Info(ctx, dgst)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -97,12 +98,12 @@ func (rs *remoteContent) ReaderAt(ctx context.Context, dgst digest.Digest) (cont
ctx: ctx, ctx: ctx,
digest: dgst, digest: dgst,
size: i.Size, size: i.Size,
client: rs.client, client: pcs.client,
}, nil }, nil
} }
func (rs *remoteContent) Status(ctx context.Context, ref string) (content.Status, error) { func (pcs *proxyContentStore) Status(ctx context.Context, ref string) (content.Status, error) {
resp, err := rs.client.Status(ctx, &contentapi.StatusRequest{ resp, err := pcs.client.Status(ctx, &contentapi.StatusRequest{
Ref: ref, Ref: ref,
}) })
if err != nil { if err != nil {
@ -120,8 +121,8 @@ func (rs *remoteContent) Status(ctx context.Context, ref string) (content.Status
}, nil }, nil
} }
func (rs *remoteContent) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) { func (pcs *proxyContentStore) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
resp, err := rs.client.Update(ctx, &contentapi.UpdateRequest{ resp, err := pcs.client.Update(ctx, &contentapi.UpdateRequest{
Info: infoToGRPC(info), Info: infoToGRPC(info),
UpdateMask: &protobuftypes.FieldMask{ UpdateMask: &protobuftypes.FieldMask{
Paths: fieldpaths, Paths: fieldpaths,
@ -133,8 +134,8 @@ func (rs *remoteContent) Update(ctx context.Context, info content.Info, fieldpat
return infoFromGRPC(resp.Info), nil return infoFromGRPC(resp.Info), nil
} }
func (rs *remoteContent) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) { func (pcs *proxyContentStore) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
resp, err := rs.client.ListStatuses(ctx, &contentapi.ListStatusesRequest{ resp, err := pcs.client.ListStatuses(ctx, &contentapi.ListStatusesRequest{
Filters: filters, Filters: filters,
}) })
if err != nil { if err != nil {
@ -156,8 +157,8 @@ func (rs *remoteContent) ListStatuses(ctx context.Context, filters ...string) ([
return statuses, nil return statuses, nil
} }
func (rs *remoteContent) Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (content.Writer, error) { func (pcs *proxyContentStore) Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (content.Writer, error) {
wrclient, offset, err := rs.negotiate(ctx, ref, size, expected) wrclient, offset, err := pcs.negotiate(ctx, ref, size, expected)
if err != nil { if err != nil {
return nil, errdefs.FromGRPC(err) return nil, errdefs.FromGRPC(err)
} }
@ -170,8 +171,8 @@ func (rs *remoteContent) Writer(ctx context.Context, ref string, size int64, exp
} }
// Abort implements asynchronous abort. It starts a new write session on the ref l // Abort implements asynchronous abort. It starts a new write session on the ref l
func (rs *remoteContent) Abort(ctx context.Context, ref string) error { func (pcs *proxyContentStore) Abort(ctx context.Context, ref string) error {
if _, err := rs.client.Abort(ctx, &contentapi.AbortRequest{ if _, err := pcs.client.Abort(ctx, &contentapi.AbortRequest{
Ref: ref, Ref: ref,
}); err != nil { }); err != nil {
return errdefs.FromGRPC(err) return errdefs.FromGRPC(err)
@ -180,8 +181,8 @@ func (rs *remoteContent) Abort(ctx context.Context, ref string) error {
return nil return nil
} }
func (rs *remoteContent) negotiate(ctx context.Context, ref string, size int64, expected digest.Digest) (contentapi.Content_WriteClient, int64, error) { func (pcs *proxyContentStore) negotiate(ctx context.Context, ref string, size int64, expected digest.Digest) (contentapi.Content_WriteClient, int64, error) {
wrclient, err := rs.client.Write(ctx) wrclient, err := pcs.client.Write(ctx)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package containerd package proxy
import ( import (
"context" "context"

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package containerd package proxy
import ( import (
"context" "context"
@ -28,24 +28,24 @@ import (
protobuftypes "github.com/gogo/protobuf/types" protobuftypes "github.com/gogo/protobuf/types"
) )
// NewSnapshotterFromClient returns a new Snapshotter which communicates // NewSnapshotter returns a new Snapshotter which communicates over a GRPC
// over a GRPC connection. // connection using the containerd snapshot GRPC API.
func NewSnapshotterFromClient(client snapshotsapi.SnapshotsClient, snapshotterName string) snapshots.Snapshotter { func NewSnapshotter(client snapshotsapi.SnapshotsClient, snapshotterName string) snapshots.Snapshotter {
return &remoteSnapshotter{ return &proxySnapshotter{
client: client, client: client,
snapshotterName: snapshotterName, snapshotterName: snapshotterName,
} }
} }
type remoteSnapshotter struct { type proxySnapshotter struct {
client snapshotsapi.SnapshotsClient client snapshotsapi.SnapshotsClient
snapshotterName string snapshotterName string
} }
func (r *remoteSnapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) { func (p *proxySnapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
resp, err := r.client.Stat(ctx, resp, err := p.client.Stat(ctx,
&snapshotsapi.StatSnapshotRequest{ &snapshotsapi.StatSnapshotRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
Key: key, Key: key,
}) })
if err != nil { if err != nil {
@ -54,10 +54,10 @@ func (r *remoteSnapshotter) Stat(ctx context.Context, key string) (snapshots.Inf
return toInfo(resp.Info), nil return toInfo(resp.Info), nil
} }
func (r *remoteSnapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) { func (p *proxySnapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
resp, err := r.client.Update(ctx, resp, err := p.client.Update(ctx,
&snapshotsapi.UpdateSnapshotRequest{ &snapshotsapi.UpdateSnapshotRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
Info: fromInfo(info), Info: fromInfo(info),
UpdateMask: &protobuftypes.FieldMask{ UpdateMask: &protobuftypes.FieldMask{
Paths: fieldpaths, Paths: fieldpaths,
@ -69,9 +69,9 @@ func (r *remoteSnapshotter) Update(ctx context.Context, info snapshots.Info, fie
return toInfo(resp.Info), nil return toInfo(resp.Info), nil
} }
func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) { func (p *proxySnapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
resp, err := r.client.Usage(ctx, &snapshotsapi.UsageRequest{ resp, err := p.client.Usage(ctx, &snapshotsapi.UsageRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
Key: key, Key: key,
}) })
if err != nil { if err != nil {
@ -80,9 +80,9 @@ func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshots.Us
return toUsage(resp), nil return toUsage(resp), nil
} }
func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) { func (p *proxySnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
resp, err := r.client.Mounts(ctx, &snapshotsapi.MountsRequest{ resp, err := p.client.Mounts(ctx, &snapshotsapi.MountsRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
Key: key, Key: key,
}) })
if err != nil { if err != nil {
@ -91,15 +91,15 @@ func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mou
return toMounts(resp.Mounts), nil return toMounts(resp.Mounts), nil
} }
func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) { func (p *proxySnapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
var local snapshots.Info var local snapshots.Info
for _, opt := range opts { for _, opt := range opts {
if err := opt(&local); err != nil { if err := opt(&local); err != nil {
return nil, err return nil, err
} }
} }
resp, err := r.client.Prepare(ctx, &snapshotsapi.PrepareSnapshotRequest{ resp, err := p.client.Prepare(ctx, &snapshotsapi.PrepareSnapshotRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
Key: key, Key: key,
Parent: parent, Parent: parent,
Labels: local.Labels, Labels: local.Labels,
@ -110,15 +110,15 @@ func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string, opt
return toMounts(resp.Mounts), nil return toMounts(resp.Mounts), nil
} }
func (r *remoteSnapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) { func (p *proxySnapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
var local snapshots.Info var local snapshots.Info
for _, opt := range opts { for _, opt := range opts {
if err := opt(&local); err != nil { if err := opt(&local); err != nil {
return nil, err return nil, err
} }
} }
resp, err := r.client.View(ctx, &snapshotsapi.ViewSnapshotRequest{ resp, err := p.client.View(ctx, &snapshotsapi.ViewSnapshotRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
Key: key, Key: key,
Parent: parent, Parent: parent,
Labels: local.Labels, Labels: local.Labels,
@ -129,15 +129,15 @@ func (r *remoteSnapshotter) View(ctx context.Context, key, parent string, opts .
return toMounts(resp.Mounts), nil return toMounts(resp.Mounts), nil
} }
func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error { func (p *proxySnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
var local snapshots.Info var local snapshots.Info
for _, opt := range opts { for _, opt := range opts {
if err := opt(&local); err != nil { if err := opt(&local); err != nil {
return err return err
} }
} }
_, err := r.client.Commit(ctx, &snapshotsapi.CommitSnapshotRequest{ _, err := p.client.Commit(ctx, &snapshotsapi.CommitSnapshotRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
Name: name, Name: name,
Key: key, Key: key,
Labels: local.Labels, Labels: local.Labels,
@ -145,17 +145,17 @@ func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string, opts .
return errdefs.FromGRPC(err) return errdefs.FromGRPC(err)
} }
func (r *remoteSnapshotter) Remove(ctx context.Context, key string) error { func (p *proxySnapshotter) Remove(ctx context.Context, key string) error {
_, err := r.client.Remove(ctx, &snapshotsapi.RemoveSnapshotRequest{ _, err := p.client.Remove(ctx, &snapshotsapi.RemoveSnapshotRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
Key: key, Key: key,
}) })
return errdefs.FromGRPC(err) return errdefs.FromGRPC(err)
} }
func (r *remoteSnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error { func (p *proxySnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
sc, err := r.client.List(ctx, &snapshotsapi.ListSnapshotsRequest{ sc, err := p.client.List(ctx, &snapshotsapi.ListSnapshotsRequest{
Snapshotter: r.snapshotterName, Snapshotter: p.snapshotterName,
}) })
if err != nil { if err != nil {
return errdefs.FromGRPC(err) return errdefs.FromGRPC(err)
@ -179,7 +179,7 @@ func (r *remoteSnapshotter) Walk(ctx context.Context, fn func(context.Context, s
} }
} }
func (r *remoteSnapshotter) Close() error { func (p *proxySnapshotter) Close() error {
return nil return nil
} }