mount: Add From/ToProto helpers
Helpers to convert from containerd's [Mount] to its protobuf structure for [Mount] and vice-versa appear three times. It seems sane to just expose this facility in /mount. Signed-off-by: Danny Canter <danny@dcantah.dev>
This commit is contained in:
@@ -50,7 +50,7 @@ func (s *service) Apply(ctx context.Context, er *diffapi.ApplyRequest) (*diffapi
|
||||
ocidesc ocispec.Descriptor
|
||||
err error
|
||||
desc = toDescriptor(er.Diff)
|
||||
mounts = toMounts(er.Mounts)
|
||||
mounts = mount.FromProto(er.Mounts)
|
||||
)
|
||||
|
||||
var opts []diff.ApplyOpt
|
||||
@@ -79,8 +79,8 @@ func (s *service) Diff(ctx context.Context, dr *diffapi.DiffRequest) (*diffapi.D
|
||||
var (
|
||||
ocidesc ocispec.Descriptor
|
||||
err error
|
||||
aMounts = toMounts(dr.Left)
|
||||
bMounts = toMounts(dr.Right)
|
||||
aMounts = mount.FromProto(dr.Left)
|
||||
bMounts = mount.FromProto(dr.Right)
|
||||
)
|
||||
|
||||
var opts []diff.Opt
|
||||
@@ -108,19 +108,6 @@ func (s *service) Diff(ctx context.Context, dr *diffapi.DiffRequest) (*diffapi.D
|
||||
}, nil
|
||||
}
|
||||
|
||||
func toMounts(apim []*types.Mount) []mount.Mount {
|
||||
mounts := make([]mount.Mount, len(apim))
|
||||
for i, m := range apim {
|
||||
mounts[i] = mount.Mount{
|
||||
Type: m.Type,
|
||||
Source: m.Source,
|
||||
Target: m.Target,
|
||||
Options: m.Options,
|
||||
}
|
||||
}
|
||||
return mounts
|
||||
}
|
||||
|
||||
func toDescriptor(d *types.Descriptor) ocispec.Descriptor {
|
||||
return ocispec.Descriptor{
|
||||
MediaType: d.MediaType,
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
|
||||
snapshotsapi "github.com/containerd/containerd/api/services/snapshots/v1"
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/protobuf"
|
||||
@@ -51,7 +50,7 @@ func (s service) Prepare(ctx context.Context, pr *snapshotsapi.PrepareSnapshotRe
|
||||
}
|
||||
|
||||
return &snapshotsapi.PrepareSnapshotResponse{
|
||||
Mounts: fromMounts(mounts),
|
||||
Mounts: mount.ToProto(mounts),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -65,7 +64,7 @@ func (s service) View(ctx context.Context, pr *snapshotsapi.ViewSnapshotRequest)
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
return &snapshotsapi.ViewSnapshotResponse{
|
||||
Mounts: fromMounts(mounts),
|
||||
Mounts: mount.ToProto(mounts),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ func (s service) Mounts(ctx context.Context, mr *snapshotsapi.MountsRequest) (*s
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
return &snapshotsapi.MountsResponse{
|
||||
Mounts: fromMounts(mounts),
|
||||
Mounts: mount.ToProto(mounts),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -199,19 +198,6 @@ func fromInfo(info snapshots.Info) *snapshotsapi.Info {
|
||||
}
|
||||
}
|
||||
|
||||
func fromMounts(mounts []mount.Mount) []*types.Mount {
|
||||
out := make([]*types.Mount, len(mounts))
|
||||
for i, m := range mounts {
|
||||
out[i] = &types.Mount{
|
||||
Type: m.Type,
|
||||
Source: m.Source,
|
||||
Target: m.Target,
|
||||
Options: m.Options,
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func toInfo(info *snapshotsapi.Info) snapshots.Info {
|
||||
return snapshots.Info{
|
||||
Name: info.Name,
|
||||
|
||||
Reference in New Issue
Block a user