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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user