mirror of
https://github.com/containers/podman.git
synced 2025-10-25 10:16:43 +08:00
Merge pull request #16243 from alexlarsson/volume-create-ignore
Add podman volume create --ignore
This commit is contained in:
@ -70,6 +70,11 @@ func CreateVolume(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
volumeOptions = append(volumeOptions, parsedOptions...)
|
||||
}
|
||||
|
||||
if input.IgnoreIfExists {
|
||||
volumeOptions = append(volumeOptions, libpod.WithVolumeIgnoreIfExist())
|
||||
}
|
||||
|
||||
vol, err := runtime.NewVolume(r.Context(), volumeOptions...)
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
|
||||
@ -19,6 +19,8 @@ type VolumeCreateOptions struct {
|
||||
Labels map[string]string `schema:"labels"`
|
||||
// Mapping of driver options and values.
|
||||
Options map[string]string `schema:"opts"`
|
||||
// Ignore existing volumes
|
||||
IgnoreIfExists bool `schema:"ignoreIfExist"`
|
||||
}
|
||||
|
||||
type VolumeConfigResponse struct {
|
||||
|
||||
@ -33,6 +33,11 @@ func (ic *ContainerEngine) VolumeCreate(ctx context.Context, opts entities.Volum
|
||||
}
|
||||
volumeOptions = append(volumeOptions, parsedOptions...)
|
||||
}
|
||||
|
||||
if opts.IgnoreIfExists {
|
||||
volumeOptions = append(volumeOptions, libpod.WithVolumeIgnoreIfExist())
|
||||
}
|
||||
|
||||
vol, err := ic.Libpod.NewVolume(ctx, volumeOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -669,11 +669,9 @@ func ConvertVolume(volume *parser.UnitFile, name string) (*parser.UnitFile, erro
|
||||
// Need the containers filesystem mounted to start podman
|
||||
service.Add(UnitGroup, "RequiresMountsFor", "%t/containers")
|
||||
|
||||
execCond := fmt.Sprintf("/usr/bin/bash -c \"! /usr/bin/podman volume exists %s\"", volumeName)
|
||||
|
||||
labels := volume.LookupAllKeyVal(VolumeGroup, "Label")
|
||||
|
||||
podman := NewPodmanCmdline("volume", "create")
|
||||
podman := NewPodmanCmdline("volume", "create", "--ignore")
|
||||
|
||||
var opts strings.Builder
|
||||
opts.WriteString("o=")
|
||||
@ -706,7 +704,6 @@ func ConvertVolume(volume *parser.UnitFile, name string) (*parser.UnitFile, erro
|
||||
service.Setv(ServiceGroup,
|
||||
"Type", "oneshot",
|
||||
"RemainAfterExit", "yes",
|
||||
"ExecCondition", execCond,
|
||||
|
||||
// The default syslog identifier is the exec basename (podman) which isn't very useful here
|
||||
"SyslogIdentifier", "%N")
|
||||
|
||||
Reference in New Issue
Block a user