Merge pull request #16243 from alexlarsson/volume-create-ignore

Add podman volume create --ignore
This commit is contained in:
OpenShift Merge Robot
2022-10-26 15:00:51 -04:00
committed by GitHub
11 changed files with 80 additions and 18 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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

View File

@ -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")