summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2021-07-29 08:34:49 -0700
committerJhon Honce <jhonce@redhat.com>2021-08-27 11:11:01 -0700
commita5adc3d80f7387c75c83f1e0c7ad3333fdc48806 (patch)
treeab45e953b5e89452a5b32a4c8c78c37c05f64923 /cmd
parent266a3892f25d8cee508f421e718ba6f135ff7123 (diff)
downloadpodman-a5adc3d80f7387c75c83f1e0c7ad3333fdc48806.tar.gz
podman-a5adc3d80f7387c75c83f1e0c7ad3333fdc48806.tar.bz2
podman-a5adc3d80f7387c75c83f1e0c7ad3333fdc48806.zip
Add support for mount options to API
When creating containers the specialized mount options where not populated via the API. Fixes: #10831 Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/create_opts.go45
1 files changed, 36 insertions, 9 deletions
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go
index 2f592cba7..09ac61f2e 100644
--- a/cmd/podman/common/create_opts.go
+++ b/cmd/podman/common/create_opts.go
@@ -16,6 +16,7 @@ import (
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/rootless"
"github.com/containers/podman/v3/pkg/specgen"
+ "github.com/docker/docker/api/types/mount"
"github.com/pkg/errors"
)
@@ -94,18 +95,30 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
expose = append(expose, fmt.Sprintf("%s/%s", p.Port(), p.Proto()))
}
- // mounts type=tmpfs/bind,source=,dest=,opt=val
- // TODO options
+ // mounts type=tmpfs/bind,source=...,target=...=,opt=val
mounts := make([]string, 0, len(cc.HostConfig.Mounts))
+ var builder strings.Builder
for _, m := range cc.HostConfig.Mounts {
- mount := fmt.Sprintf("type=%s", m.Type)
- if len(m.Source) > 0 {
- mount += fmt.Sprintf(",source=%s", m.Source)
+ addField(&builder, "type", string(m.Type))
+ addField(&builder, "source", m.Source)
+ addField(&builder, "target", m.Target)
+ addField(&builder, "ro", strconv.FormatBool(m.ReadOnly))
+ addField(&builder, "consistency", string(m.Consistency))
+
+ // Map any specialized mount options that intersect between *Options and cli options
+ switch m.Type {
+ case mount.TypeBind:
+ addField(&builder, "bind-propagation", string(m.BindOptions.Propagation))
+ addField(&builder, "bind-nonrecursive", strconv.FormatBool(m.BindOptions.NonRecursive))
+ case mount.TypeTmpfs:
+ addField(&builder, "tmpfs-size", strconv.FormatInt(m.TmpfsOptions.SizeBytes, 10))
+ addField(&builder, "tmpfs-mode", strconv.FormatUint(uint64(m.TmpfsOptions.Mode), 10))
+ case mount.TypeVolume:
+ // All current VolumeOpts are handled above
+ // See vendor/github.com/containers/common/pkg/parse/parse.go:ValidateVolumeOpts()
}
- if len(m.Target) > 0 {
- mount += fmt.Sprintf(",dst=%s", m.Target)
- }
- mounts = append(mounts, mount)
+ mounts = append(mounts, builder.String())
+ builder.Reset()
}
// dns
@@ -506,3 +519,17 @@ func logDriver() string {
}
return ""
}
+
+// addField is a helper function to populate mount options
+func addField(b *strings.Builder, name string, value string) {
+ if value == "" {
+ return
+ }
+
+ if b.Len() > 0 {
+ b.WriteRune(',')
+ }
+ b.WriteString(name)
+ b.WriteRune('=')
+ b.WriteString(value)
+}