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:
Danny Canter
2023-06-28 04:03:18 -07:00
parent 9b4ed8acc2
commit 55a8102ec1
7 changed files with 49 additions and 99 deletions

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"strings"
"github.com/containerd/containerd/api/types"
"github.com/containerd/continuity/fs"
)
@@ -130,3 +131,33 @@ func readonlyOverlay(opt []string) []string {
}
return out
}
// ToProto converts from [Mount] to the containerd
// APIs protobuf definition of a Mount.
func ToProto(mounts []Mount) []*types.Mount {
apiMounts := make([]*types.Mount, len(mounts))
for i, m := range mounts {
apiMounts[i] = &types.Mount{
Type: m.Type,
Source: m.Source,
Target: m.Target,
Options: m.Options,
}
}
return apiMounts
}
// FromProto converts from the protobuf definition [types.Mount] to
// [Mount].
func FromProto(mm []*types.Mount) []Mount {
mounts := make([]Mount, len(mm))
for i, m := range mm {
mounts[i] = Mount{
Type: m.Type,
Source: m.Source,
Target: m.Target,
Options: m.Options,
}
}
return mounts
}