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:
@@ -98,7 +98,7 @@ func (l *local) Apply(ctx context.Context, er *diffapi.ApplyRequest, _ ...grpc.C
|
||||
ocidesc ocispec.Descriptor
|
||||
err error
|
||||
desc = toDescriptor(er.Diff)
|
||||
mounts = toMounts(er.Mounts)
|
||||
mounts = mount.FromProto(er.Mounts)
|
||||
)
|
||||
|
||||
var opts []diff.ApplyOpt
|
||||
@@ -131,8 +131,8 @@ func (l *local) Diff(ctx context.Context, dr *diffapi.DiffRequest, _ ...grpc.Cal
|
||||
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
|
||||
@@ -165,19 +165,6 @@ func (l *local) Diff(ctx context.Context, dr *diffapi.DiffRequest, _ ...grpc.Cal
|
||||
}, 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,
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"errors"
|
||||
|
||||
snapshotsapi "github.com/containerd/containerd/api/services/snapshots/v1"
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/mount"
|
||||
@@ -102,7 +101,7 @@ func (s *service) Prepare(ctx context.Context, pr *snapshotsapi.PrepareSnapshotR
|
||||
}
|
||||
|
||||
return &snapshotsapi.PrepareSnapshotResponse{
|
||||
Mounts: fromMounts(mounts),
|
||||
Mounts: mount.ToProto(mounts),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -121,7 +120,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
|
||||
}
|
||||
|
||||
@@ -137,7 +136,7 @@ func (s *service) Mounts(ctx context.Context, mr *snapshotsapi.MountsRequest) (*
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
return &snapshotsapi.MountsResponse{
|
||||
Mounts: fromMounts(mounts),
|
||||
Mounts: mount.ToProto(mounts),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -304,19 +303,6 @@ func fromUsage(usage snapshots.Usage) *snapshotsapi.UsageResponse {
|
||||
}
|
||||
}
|
||||
|
||||
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