client: move content store client to containerd package
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
This commit is contained in:
parent
aefaeeacb0
commit
8c5dede74e
@ -33,7 +33,6 @@ import (
|
|||||||
"github.com/containerd/containerd/remotes"
|
"github.com/containerd/containerd/remotes"
|
||||||
"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"
|
||||||
contentservice "github.com/containerd/containerd/services/content"
|
|
||||||
"github.com/containerd/containerd/snapshot"
|
"github.com/containerd/containerd/snapshot"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
ptypes "github.com/gogo/protobuf/types"
|
ptypes "github.com/gogo/protobuf/types"
|
||||||
@ -432,7 +431,7 @@ func (c *Client) ContainerService() containers.Store {
|
|||||||
|
|
||||||
// ContentStore returns the underlying content Store
|
// ContentStore returns the underlying content Store
|
||||||
func (c *Client) ContentStore() content.Store {
|
func (c *Client) ContentStore() content.Store {
|
||||||
return contentservice.NewStoreFromClient(contentapi.NewContentClient(c.conn))
|
return NewContentStoreFromClient(contentapi.NewContentClient(c.conn))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SnapshotService returns the underlying snapshotter for the provided snapshotter name
|
// SnapshotService returns the underlying snapshotter for the provided snapshotter name
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package content
|
package containerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package content
|
package containerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -11,18 +11,18 @@ import (
|
|||||||
digest "github.com/opencontainers/go-digest"
|
digest "github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type remoteStore struct {
|
type remoteContent struct {
|
||||||
client contentapi.ContentClient
|
client contentapi.ContentClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStoreFromClient returns a new content store
|
// NewContentStoreFromClient returns a new content store
|
||||||
func NewStoreFromClient(client contentapi.ContentClient) content.Store {
|
func NewContentStoreFromClient(client contentapi.ContentClient) content.Store {
|
||||||
return &remoteStore{
|
return &remoteContent{
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
|
func (rs *remoteContent) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
|
||||||
resp, err := rs.client.Info(ctx, &contentapi.InfoRequest{
|
resp, err := rs.client.Info(ctx, &contentapi.InfoRequest{
|
||||||
Digest: dgst,
|
Digest: dgst,
|
||||||
})
|
})
|
||||||
@ -33,7 +33,7 @@ func (rs *remoteStore) Info(ctx context.Context, dgst digest.Digest) (content.In
|
|||||||
return infoFromGRPC(resp.Info), nil
|
return infoFromGRPC(resp.Info), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
|
func (rs *remoteContent) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
|
||||||
session, err := rs.client.List(ctx, &contentapi.ListContentRequest{
|
session, err := rs.client.List(ctx, &contentapi.ListContentRequest{
|
||||||
Filters: filters,
|
Filters: filters,
|
||||||
})
|
})
|
||||||
@ -61,7 +61,7 @@ func (rs *remoteStore) Walk(ctx context.Context, fn content.WalkFunc, filters ..
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) Delete(ctx context.Context, dgst digest.Digest) error {
|
func (rs *remoteContent) Delete(ctx context.Context, dgst digest.Digest) error {
|
||||||
if _, err := rs.client.Delete(ctx, &contentapi.DeleteContentRequest{
|
if _, err := rs.client.Delete(ctx, &contentapi.DeleteContentRequest{
|
||||||
Digest: dgst,
|
Digest: dgst,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -71,7 +71,7 @@ func (rs *remoteStore) Delete(ctx context.Context, dgst digest.Digest) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) ReaderAt(ctx context.Context, dgst digest.Digest) (content.ReaderAt, error) {
|
func (rs *remoteContent) ReaderAt(ctx context.Context, dgst digest.Digest) (content.ReaderAt, error) {
|
||||||
i, err := rs.Info(ctx, dgst)
|
i, err := rs.Info(ctx, dgst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -85,7 +85,7 @@ func (rs *remoteStore) ReaderAt(ctx context.Context, dgst digest.Digest) (conten
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) Status(ctx context.Context, ref string) (content.Status, error) {
|
func (rs *remoteContent) Status(ctx context.Context, ref string) (content.Status, error) {
|
||||||
resp, err := rs.client.Status(ctx, &contentapi.StatusRequest{
|
resp, err := rs.client.Status(ctx, &contentapi.StatusRequest{
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
})
|
})
|
||||||
@ -104,7 +104,7 @@ func (rs *remoteStore) Status(ctx context.Context, ref string) (content.Status,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
|
func (rs *remoteContent) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
|
||||||
resp, err := rs.client.Update(ctx, &contentapi.UpdateRequest{
|
resp, err := rs.client.Update(ctx, &contentapi.UpdateRequest{
|
||||||
Info: infoToGRPC(info),
|
Info: infoToGRPC(info),
|
||||||
UpdateMask: &protobuftypes.FieldMask{
|
UpdateMask: &protobuftypes.FieldMask{
|
||||||
@ -117,7 +117,7 @@ func (rs *remoteStore) Update(ctx context.Context, info content.Info, fieldpaths
|
|||||||
return infoFromGRPC(resp.Info), nil
|
return infoFromGRPC(resp.Info), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
|
func (rs *remoteContent) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
|
||||||
resp, err := rs.client.ListStatuses(ctx, &contentapi.ListStatusesRequest{
|
resp, err := rs.client.ListStatuses(ctx, &contentapi.ListStatusesRequest{
|
||||||
Filters: filters,
|
Filters: filters,
|
||||||
})
|
})
|
||||||
@ -140,7 +140,7 @@ func (rs *remoteStore) ListStatuses(ctx context.Context, filters ...string) ([]c
|
|||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (content.Writer, error) {
|
func (rs *remoteContent) 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 := rs.negotiate(ctx, ref, size, expected)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.FromGRPC(err)
|
return nil, errdefs.FromGRPC(err)
|
||||||
@ -154,7 +154,7 @@ func (rs *remoteStore) Writer(ctx context.Context, ref string, size int64, expec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 *remoteStore) Abort(ctx context.Context, ref string) error {
|
func (rs *remoteContent) Abort(ctx context.Context, ref string) error {
|
||||||
if _, err := rs.client.Abort(ctx, &contentapi.AbortRequest{
|
if _, err := rs.client.Abort(ctx, &contentapi.AbortRequest{
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -164,7 +164,7 @@ func (rs *remoteStore) Abort(ctx context.Context, ref string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *remoteStore) negotiate(ctx context.Context, ref string, size int64, expected digest.Digest) (contentapi.Content_WriteClient, int64, error) {
|
func (rs *remoteContent) negotiate(ctx context.Context, ref string, size int64, expected digest.Digest) (contentapi.Content_WriteClient, int64, error) {
|
||||||
wrclient, err := rs.client.Write(ctx)
|
wrclient, err := rs.client.Write(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
@ -1,4 +1,4 @@
|
|||||||
package content
|
package containerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -452,3 +452,23 @@ func (s *service) Abort(ctx context.Context, req *api.AbortRequest) (*ptypes.Emp
|
|||||||
|
|
||||||
return &ptypes.Empty{}, nil
|
return &ptypes.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func infoToGRPC(info content.Info) api.Info {
|
||||||
|
return api.Info{
|
||||||
|
Digest: info.Digest,
|
||||||
|
Size_: info.Size,
|
||||||
|
CreatedAt: info.CreatedAt,
|
||||||
|
UpdatedAt: info.UpdatedAt,
|
||||||
|
Labels: info.Labels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func infoFromGRPC(info api.Info) content.Info {
|
||||||
|
return content.Info{
|
||||||
|
Digest: info.Digest,
|
||||||
|
Size: info.Size_,
|
||||||
|
CreatedAt: info.CreatedAt,
|
||||||
|
UpdatedAt: info.UpdatedAt,
|
||||||
|
Labels: info.Labels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user