mirror of
https://github.com/containers/podman.git
synced 2025-06-25 20:26:51 +08:00
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>
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||||
"github.com/containers/podman/v3/pkg/rootless"
|
"github.com/containers/podman/v3/pkg/rootless"
|
||||||
"github.com/containers/podman/v3/pkg/specgen"
|
"github.com/containers/podman/v3/pkg/specgen"
|
||||||
|
"github.com/docker/docker/api/types/mount"
|
||||||
"github.com/pkg/errors"
|
"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()))
|
expose = append(expose, fmt.Sprintf("%s/%s", p.Port(), p.Proto()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// mounts type=tmpfs/bind,source=,dest=,opt=val
|
// mounts type=tmpfs/bind,source=...,target=...=,opt=val
|
||||||
// TODO options
|
|
||||||
mounts := make([]string, 0, len(cc.HostConfig.Mounts))
|
mounts := make([]string, 0, len(cc.HostConfig.Mounts))
|
||||||
|
var builder strings.Builder
|
||||||
for _, m := range cc.HostConfig.Mounts {
|
for _, m := range cc.HostConfig.Mounts {
|
||||||
mount := fmt.Sprintf("type=%s", m.Type)
|
addField(&builder, "type", string(m.Type))
|
||||||
if len(m.Source) > 0 {
|
addField(&builder, "source", m.Source)
|
||||||
mount += fmt.Sprintf(",source=%s", 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 {
|
mounts = append(mounts, builder.String())
|
||||||
mount += fmt.Sprintf(",dst=%s", m.Target)
|
builder.Reset()
|
||||||
}
|
|
||||||
mounts = append(mounts, mount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dns
|
// dns
|
||||||
@ -506,3 +519,17 @@ func logDriver() string {
|
|||||||
}
|
}
|
||||||
return ""
|
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)
|
||||||
|
}
|
||||||
|
@ -620,9 +620,9 @@ func getTmpfsMounts(tmpfsFlag []string) (map[string]spec.Mount, error) {
|
|||||||
|
|
||||||
mount := spec.Mount{
|
mount := spec.Mount{
|
||||||
Destination: filepath.Clean(destPath),
|
Destination: filepath.Clean(destPath),
|
||||||
Type: string(define.TypeTmpfs),
|
Type: define.TypeTmpfs,
|
||||||
Options: options,
|
Options: options,
|
||||||
Source: string(define.TypeTmpfs),
|
Source: define.TypeTmpfs,
|
||||||
}
|
}
|
||||||
m[destPath] = mount
|
m[destPath] = mount
|
||||||
}
|
}
|
||||||
|
@ -366,4 +366,12 @@ t GET containers/$cid/json 200 \
|
|||||||
.Config.Healthcheck.Timeout=30000000000 \
|
.Config.Healthcheck.Timeout=30000000000 \
|
||||||
.Config.Healthcheck.Retries=3
|
.Config.Healthcheck.Retries=3
|
||||||
|
|
||||||
|
# compat api: Test for mount options support
|
||||||
|
payload='{"Mounts":[{"Type":"tmpfs","Target":"/mnt/scratch","TmpfsOptions":{"SizeBytes":1024,"Mode":755}}]}'
|
||||||
|
t POST containers/create Image=$IMAGE HostConfig="$payload" 201 .Id~[0-9a-f]\\{64\\}
|
||||||
|
cid=$(jq -r '.Id' <<<"$output")
|
||||||
|
t GET containers/$cid/json 200 \
|
||||||
|
.HostConfig.Tmpfs['"/mnt/scratch"']~.*size=1024.* \
|
||||||
|
.HostConfig.Tmpfs['"/mnt/scratch"']~.*mode=755.*
|
||||||
|
|
||||||
t DELETE containers/$cid?v=true 204
|
t DELETE containers/$cid?v=true 204
|
||||||
|
@ -327,7 +327,8 @@ function start_service() {
|
|||||||
die "Cannot start service on non-localhost ($HOST)"
|
die "Cannot start service on non-localhost ($HOST)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$PODMAN_BIN --root $WORKDIR/server_root system service \
|
$PODMAN_BIN --root $WORKDIR/server_root --syslog=true \
|
||||||
|
system service \
|
||||||
--time 15 \
|
--time 15 \
|
||||||
tcp:127.0.0.1:$PORT \
|
tcp:127.0.0.1:$PORT \
|
||||||
&> $WORKDIR/server.log &
|
&> $WORKDIR/server.log &
|
||||||
|
Reference in New Issue
Block a user