Merge pull request #1777 from jessvalarezo/migrate-client-code
client: migrate client code to containerd
This commit is contained in:
commit
a4968710fd
15
client.go
15
client.go
@ -33,11 +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"
|
|
||||||
diffservice "github.com/containerd/containerd/services/diff"
|
|
||||||
imagesservice "github.com/containerd/containerd/services/images"
|
|
||||||
namespacesservice "github.com/containerd/containerd/services/namespaces"
|
|
||||||
snapshotservice "github.com/containerd/containerd/services/snapshot"
|
|
||||||
"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"
|
||||||
@ -426,7 +421,7 @@ func (c *Client) Close() error {
|
|||||||
|
|
||||||
// NamespaceService returns the underlying Namespaces Store
|
// NamespaceService returns the underlying Namespaces Store
|
||||||
func (c *Client) NamespaceService() namespaces.Store {
|
func (c *Client) NamespaceService() namespaces.Store {
|
||||||
return namespacesservice.NewStoreFromClient(namespacesapi.NewNamespacesClient(c.conn))
|
return NewNamespaceStoreFromClient(namespacesapi.NewNamespacesClient(c.conn))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerService returns the underlying container Store
|
// ContainerService returns the underlying container Store
|
||||||
@ -436,12 +431,12 @@ 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
|
||||||
func (c *Client) SnapshotService(snapshotterName string) snapshot.Snapshotter {
|
func (c *Client) SnapshotService(snapshotterName string) snapshot.Snapshotter {
|
||||||
return snapshotservice.NewSnapshotterFromClient(snapshotapi.NewSnapshotsClient(c.conn), snapshotterName)
|
return NewSnapshotterFromClient(snapshotapi.NewSnapshotsClient(c.conn), snapshotterName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaskService returns the underlying TasksClient
|
// TaskService returns the underlying TasksClient
|
||||||
@ -451,12 +446,12 @@ func (c *Client) TaskService() tasks.TasksClient {
|
|||||||
|
|
||||||
// ImageService returns the underlying image Store
|
// ImageService returns the underlying image Store
|
||||||
func (c *Client) ImageService() images.Store {
|
func (c *Client) ImageService() images.Store {
|
||||||
return imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(c.conn))
|
return NewImageStoreFromClient(imagesapi.NewImagesClient(c.conn))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiffService returns the underlying Differ
|
// DiffService returns the underlying Differ
|
||||||
func (c *Client) DiffService() diff.Differ {
|
func (c *Client) DiffService() diff.Differ {
|
||||||
return diffservice.NewDiffServiceFromClient(diffapi.NewDiffClient(c.conn))
|
return NewDiffServiceFromClient(diffapi.NewDiffClient(c.conn))
|
||||||
}
|
}
|
||||||
|
|
||||||
// IntrospectionService returns the underlying Introspection Client
|
// IntrospectionService returns the underlying Introspection Client
|
||||||
|
@ -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"
|
@ -1,4 +1,4 @@
|
|||||||
package diff
|
package containerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
diffapi "github.com/containerd/containerd/api/services/diff/v1"
|
diffapi "github.com/containerd/containerd/api/services/diff/v1"
|
||||||
@ -12,16 +12,16 @@ import (
|
|||||||
// NewDiffServiceFromClient returns a new diff service which communicates
|
// NewDiffServiceFromClient returns a new diff service which communicates
|
||||||
// over a GRPC connection.
|
// over a GRPC connection.
|
||||||
func NewDiffServiceFromClient(client diffapi.DiffClient) diff.Differ {
|
func NewDiffServiceFromClient(client diffapi.DiffClient) diff.Differ {
|
||||||
return &remote{
|
return &diffRemote{
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type remote struct {
|
type diffRemote struct {
|
||||||
client diffapi.DiffClient
|
client diffapi.DiffClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []mount.Mount) (ocispec.Descriptor, error) {
|
func (r *diffRemote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []mount.Mount) (ocispec.Descriptor, error) {
|
||||||
req := &diffapi.ApplyRequest{
|
req := &diffapi.ApplyRequest{
|
||||||
Diff: fromDescriptor(diff),
|
Diff: fromDescriptor(diff),
|
||||||
Mounts: fromMounts(mounts),
|
Mounts: fromMounts(mounts),
|
||||||
@ -33,7 +33,7 @@ func (r *remote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []mo
|
|||||||
return toDescriptor(resp.Applied), nil
|
return toDescriptor(resp.Applied), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remote) DiffMounts(ctx context.Context, a, b []mount.Mount, opts ...diff.Opt) (ocispec.Descriptor, error) {
|
func (r *diffRemote) DiffMounts(ctx context.Context, a, b []mount.Mount, opts ...diff.Opt) (ocispec.Descriptor, error) {
|
||||||
var config diff.Config
|
var config diff.Config
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
if err := opt(&config); err != nil {
|
if err := opt(&config); err != nil {
|
129
image_store.go
Normal file
129
image_store.go
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
package containerd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
imagesapi "github.com/containerd/containerd/api/services/images/v1"
|
||||||
|
"github.com/containerd/containerd/api/types"
|
||||||
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/images"
|
||||||
|
ptypes "github.com/gogo/protobuf/types"
|
||||||
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type remoteImages struct {
|
||||||
|
client imagesapi.ImagesClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewImageStoreFromClient returns a new image store client
|
||||||
|
func NewImageStoreFromClient(client imagesapi.ImagesClient) images.Store {
|
||||||
|
return &remoteImages{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *remoteImages) Get(ctx context.Context, name string) (images.Image, error) {
|
||||||
|
resp, err := s.client.Get(ctx, &imagesapi.GetImageRequest{
|
||||||
|
Name: name,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return images.Image{}, errdefs.FromGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageFromProto(resp.Image), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *remoteImages) List(ctx context.Context, filters ...string) ([]images.Image, error) {
|
||||||
|
resp, err := s.client.List(ctx, &imagesapi.ListImagesRequest{
|
||||||
|
Filters: filters,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errdefs.FromGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return imagesFromProto(resp.Images), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *remoteImages) Create(ctx context.Context, image images.Image) (images.Image, error) {
|
||||||
|
created, err := s.client.Create(ctx, &imagesapi.CreateImageRequest{
|
||||||
|
Image: imageToProto(&image),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return images.Image{}, errdefs.FromGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageFromProto(&created.Image), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *remoteImages) Update(ctx context.Context, image images.Image, fieldpaths ...string) (images.Image, error) {
|
||||||
|
var updateMask *ptypes.FieldMask
|
||||||
|
if len(fieldpaths) > 0 {
|
||||||
|
updateMask = &ptypes.FieldMask{
|
||||||
|
Paths: fieldpaths,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updated, err := s.client.Update(ctx, &imagesapi.UpdateImageRequest{
|
||||||
|
Image: imageToProto(&image),
|
||||||
|
UpdateMask: updateMask,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return images.Image{}, errdefs.FromGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageFromProto(&updated.Image), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *remoteImages) Delete(ctx context.Context, name string) error {
|
||||||
|
_, err := s.client.Delete(ctx, &imagesapi.DeleteImageRequest{
|
||||||
|
Name: name,
|
||||||
|
})
|
||||||
|
|
||||||
|
return errdefs.FromGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func imageToProto(image *images.Image) imagesapi.Image {
|
||||||
|
return imagesapi.Image{
|
||||||
|
Name: image.Name,
|
||||||
|
Labels: image.Labels,
|
||||||
|
Target: descToProto(&image.Target),
|
||||||
|
CreatedAt: image.CreatedAt,
|
||||||
|
UpdatedAt: image.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func imageFromProto(imagepb *imagesapi.Image) images.Image {
|
||||||
|
return images.Image{
|
||||||
|
Name: imagepb.Name,
|
||||||
|
Labels: imagepb.Labels,
|
||||||
|
Target: descFromProto(&imagepb.Target),
|
||||||
|
CreatedAt: imagepb.CreatedAt,
|
||||||
|
UpdatedAt: imagepb.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func imagesFromProto(imagespb []imagesapi.Image) []images.Image {
|
||||||
|
var images []images.Image
|
||||||
|
|
||||||
|
for _, image := range imagespb {
|
||||||
|
images = append(images, imageFromProto(&image))
|
||||||
|
}
|
||||||
|
|
||||||
|
return images
|
||||||
|
}
|
||||||
|
|
||||||
|
func descFromProto(desc *types.Descriptor) ocispec.Descriptor {
|
||||||
|
return ocispec.Descriptor{
|
||||||
|
MediaType: desc.MediaType,
|
||||||
|
Size: desc.Size_,
|
||||||
|
Digest: desc.Digest,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func descToProto(desc *ocispec.Descriptor) types.Descriptor {
|
||||||
|
return types.Descriptor{
|
||||||
|
MediaType: desc.MediaType,
|
||||||
|
Size_: desc.Size,
|
||||||
|
Digest: desc.Digest,
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package namespaces
|
package containerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -10,16 +10,16 @@ import (
|
|||||||
"github.com/gogo/protobuf/types"
|
"github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewStoreFromClient returns a new namespace store
|
// NewNamespaceStoreFromClient returns a new namespace store
|
||||||
func NewStoreFromClient(client api.NamespacesClient) namespaces.Store {
|
func NewNamespaceStoreFromClient(client api.NamespacesClient) namespaces.Store {
|
||||||
return &remote{client: client}
|
return &remoteNamespaces{client: client}
|
||||||
}
|
}
|
||||||
|
|
||||||
type remote struct {
|
type remoteNamespaces struct {
|
||||||
client api.NamespacesClient
|
client api.NamespacesClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remote) Create(ctx context.Context, namespace string, labels map[string]string) error {
|
func (r *remoteNamespaces) Create(ctx context.Context, namespace string, labels map[string]string) error {
|
||||||
var req api.CreateNamespaceRequest
|
var req api.CreateNamespaceRequest
|
||||||
|
|
||||||
req.Namespace = api.Namespace{
|
req.Namespace = api.Namespace{
|
||||||
@ -35,7 +35,7 @@ func (r *remote) Create(ctx context.Context, namespace string, labels map[string
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remote) Labels(ctx context.Context, namespace string) (map[string]string, error) {
|
func (r *remoteNamespaces) Labels(ctx context.Context, namespace string) (map[string]string, error) {
|
||||||
var req api.GetNamespaceRequest
|
var req api.GetNamespaceRequest
|
||||||
req.Name = namespace
|
req.Name = namespace
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ func (r *remote) Labels(ctx context.Context, namespace string) (map[string]strin
|
|||||||
return resp.Namespace.Labels, nil
|
return resp.Namespace.Labels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remote) SetLabel(ctx context.Context, namespace, key, value string) error {
|
func (r *remoteNamespaces) SetLabel(ctx context.Context, namespace, key, value string) error {
|
||||||
var req api.UpdateNamespaceRequest
|
var req api.UpdateNamespaceRequest
|
||||||
|
|
||||||
req.Namespace = api.Namespace{
|
req.Namespace = api.Namespace{
|
||||||
@ -67,7 +67,7 @@ func (r *remote) SetLabel(ctx context.Context, namespace, key, value string) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remote) List(ctx context.Context) ([]string, error) {
|
func (r *remoteNamespaces) List(ctx context.Context) ([]string, error) {
|
||||||
var req api.ListNamespacesRequest
|
var req api.ListNamespacesRequest
|
||||||
|
|
||||||
resp, err := r.client.List(ctx, &req)
|
resp, err := r.client.List(ctx, &req)
|
||||||
@ -84,7 +84,7 @@ func (r *remote) List(ctx context.Context) ([]string, error) {
|
|||||||
return namespaces, nil
|
return namespaces, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remote) Delete(ctx context.Context, namespace string) error {
|
func (r *remoteNamespaces) Delete(ctx context.Context, namespace string) error {
|
||||||
var req api.DeleteNamespaceRequest
|
var req api.DeleteNamespaceRequest
|
||||||
|
|
||||||
req.Name = namespace
|
req.Name = namespace
|
@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -140,3 +140,19 @@ func toMounts(apim []*types.Mount) []mount.Mount {
|
|||||||
}
|
}
|
||||||
return mounts
|
return mounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toDescriptor(d *types.Descriptor) ocispec.Descriptor {
|
||||||
|
return ocispec.Descriptor{
|
||||||
|
MediaType: d.MediaType,
|
||||||
|
Digest: d.Digest,
|
||||||
|
Size: d.Size_,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromDescriptor(d ocispec.Descriptor) *types.Descriptor {
|
||||||
|
return &types.Descriptor{
|
||||||
|
MediaType: d.MediaType,
|
||||||
|
Digest: d.Digest,
|
||||||
|
Size_: d.Size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
package images
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
imagesapi "github.com/containerd/containerd/api/services/images/v1"
|
|
||||||
"github.com/containerd/containerd/errdefs"
|
|
||||||
"github.com/containerd/containerd/images"
|
|
||||||
ptypes "github.com/gogo/protobuf/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type remoteStore struct {
|
|
||||||
client imagesapi.ImagesClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewStoreFromClient returns a new image store client
|
|
||||||
func NewStoreFromClient(client imagesapi.ImagesClient) images.Store {
|
|
||||||
return &remoteStore{
|
|
||||||
client: client,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *remoteStore) Get(ctx context.Context, name string) (images.Image, error) {
|
|
||||||
resp, err := s.client.Get(ctx, &imagesapi.GetImageRequest{
|
|
||||||
Name: name,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return images.Image{}, errdefs.FromGRPC(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return imageFromProto(resp.Image), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *remoteStore) List(ctx context.Context, filters ...string) ([]images.Image, error) {
|
|
||||||
resp, err := s.client.List(ctx, &imagesapi.ListImagesRequest{
|
|
||||||
Filters: filters,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, errdefs.FromGRPC(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return imagesFromProto(resp.Images), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *remoteStore) Create(ctx context.Context, image images.Image) (images.Image, error) {
|
|
||||||
created, err := s.client.Create(ctx, &imagesapi.CreateImageRequest{
|
|
||||||
Image: imageToProto(&image),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return images.Image{}, errdefs.FromGRPC(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return imageFromProto(&created.Image), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *remoteStore) Update(ctx context.Context, image images.Image, fieldpaths ...string) (images.Image, error) {
|
|
||||||
var updateMask *ptypes.FieldMask
|
|
||||||
if len(fieldpaths) > 0 {
|
|
||||||
updateMask = &ptypes.FieldMask{
|
|
||||||
Paths: fieldpaths,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updated, err := s.client.Update(ctx, &imagesapi.UpdateImageRequest{
|
|
||||||
Image: imageToProto(&image),
|
|
||||||
UpdateMask: updateMask,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return images.Image{}, errdefs.FromGRPC(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return imageFromProto(&updated.Image), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *remoteStore) Delete(ctx context.Context, name string) error {
|
|
||||||
_, err := s.client.Delete(ctx, &imagesapi.DeleteImageRequest{
|
|
||||||
Name: name,
|
|
||||||
})
|
|
||||||
|
|
||||||
return errdefs.FromGRPC(err)
|
|
||||||
}
|
|
@ -293,3 +293,24 @@ func fromMounts(mounts []mount.Mount) []*types.Mount {
|
|||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toInfo(info snapshotapi.Info) snapshot.Info {
|
||||||
|
return snapshot.Info{
|
||||||
|
Name: info.Name,
|
||||||
|
Parent: info.Parent,
|
||||||
|
Kind: toKind(info.Kind),
|
||||||
|
Created: info.CreatedAt,
|
||||||
|
Updated: info.UpdatedAt,
|
||||||
|
Labels: info.Labels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func toKind(kind snapshotapi.Kind) snapshot.Kind {
|
||||||
|
if kind == snapshotapi.KindActive {
|
||||||
|
return snapshot.KindActive
|
||||||
|
}
|
||||||
|
if kind == snapshotapi.KindView {
|
||||||
|
return snapshot.KindView
|
||||||
|
}
|
||||||
|
return snapshot.KindCommitted
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package snapshot
|
package containerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -206,3 +206,24 @@ func toMounts(mm []*types.Mount) []mount.Mount {
|
|||||||
}
|
}
|
||||||
return mounts
|
return mounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fromKind(kind snapshot.Kind) snapshotapi.Kind {
|
||||||
|
if kind == snapshot.KindActive {
|
||||||
|
return snapshotapi.KindActive
|
||||||
|
}
|
||||||
|
if kind == snapshot.KindView {
|
||||||
|
return snapshotapi.KindView
|
||||||
|
}
|
||||||
|
return snapshotapi.KindCommitted
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromInfo(info snapshot.Info) snapshotapi.Info {
|
||||||
|
return snapshotapi.Info{
|
||||||
|
Name: info.Name,
|
||||||
|
Parent: info.Parent,
|
||||||
|
Kind: fromKind(info.Kind),
|
||||||
|
CreatedAt: info.Created,
|
||||||
|
UpdatedAt: info.Updated,
|
||||||
|
Labels: info.Labels,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user