aboutsummaryrefslogtreecommitdiff
path: root/libpod/options.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-03-22 14:23:18 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-04-04 12:26:29 -0400
commitee770ad5b54845e345384be3e01c700e93926b44 (patch)
tree64a1b9cd92926d06a07ba6588e034fb9faeec094 /libpod/options.go
parentd245c6df29e0c124da25e25cd9fbc5f1095bb6f7 (diff)
downloadpodman-ee770ad5b54845e345384be3e01c700e93926b44.tar.gz
podman-ee770ad5b54845e345384be3e01c700e93926b44.tar.bz2
podman-ee770ad5b54845e345384be3e01c700e93926b44.zip
Create non-existing named volumes at container create
Replaces old functionality we used for handling image volumes. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/options.go')
-rw-r--r--libpod/options.go53
1 files changed, 27 insertions, 26 deletions
diff --git a/libpod/options.go b/libpod/options.go
index 86f1747ce..4f35a5c8c 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -1265,14 +1265,11 @@ func WithNamedVolumes(volumes []*ContainerNamedVolume) CtrCreateOption {
destinations := make(map[string]bool)
for _, vol := range volumes {
- // First check if libpod has the volumes
- _, err := ctr.runtime.GetVolume(vol.Name)
- if err != nil {
- return errors.Wrapf(err, "error retrieving volume %s to add to container", vol.Name)
- }
+ // Don't check if they already exist.
+ // If they don't we will automatically create them.
if _, ok := destinations[vol.Dest]; ok {
- return errors.Wrapf(err, "two volumes found with destination %s", vol.Dest)
+ return errors.Wrapf(ErrInvalidArg, "two volumes found with destination %s", vol.Dest)
}
destinations[vol.Dest] = true
@@ -1306,68 +1303,72 @@ func WithVolumeName(name string) VolumeCreateOption {
}
}
-// WithVolumeUID sets the uid of the owner.
-func WithVolumeUID(uid int) VolumeCreateOption {
+// WithVolumeLabels sets the labels of the volume.
+func WithVolumeLabels(labels map[string]string) VolumeCreateOption {
return func(volume *Volume) error {
if volume.valid {
return ErrVolumeFinalized
}
- volume.config.UID = uid
+
+ volume.config.Labels = make(map[string]string)
+ for key, value := range labels {
+ volume.config.Labels[key] = value
+ }
+
return nil
}
}
-// WithVolumeGID sets the gid of the owner.
-func WithVolumeGID(gid int) VolumeCreateOption {
+// WithVolumeDriver sets the driver of the volume.
+func WithVolumeDriver(driver string) VolumeCreateOption {
return func(volume *Volume) error {
if volume.valid {
return ErrVolumeFinalized
}
- volume.config.GID = gid
+
+ volume.config.Driver = driver
+
return nil
}
}
-// WithVolumeLabels sets the labels of the volume.
-func WithVolumeLabels(labels map[string]string) VolumeCreateOption {
+// WithVolumeOptions sets the options of the volume.
+func WithVolumeOptions(options map[string]string) VolumeCreateOption {
return func(volume *Volume) error {
if volume.valid {
return ErrVolumeFinalized
}
- volume.config.Labels = make(map[string]string)
- for key, value := range labels {
- volume.config.Labels[key] = value
+ volume.config.Options = make(map[string]string)
+ for key, value := range options {
+ volume.config.Options[key] = value
}
return nil
}
}
-// WithVolumeDriver sets the driver of the volume.
-func WithVolumeDriver(driver string) VolumeCreateOption {
+// WithVolumeUID sets the UID that the volume will be created as.
+func WithVolumeUID(uid int) VolumeCreateOption {
return func(volume *Volume) error {
if volume.valid {
return ErrVolumeFinalized
}
- volume.config.Driver = driver
+ volume.config.UID = uid
return nil
}
}
-// WithVolumeOptions sets the options of the volume.
-func WithVolumeOptions(options map[string]string) VolumeCreateOption {
+// WithVolumeGID sets the GID that the volume will be created as.
+func WithVolumeGID(gid int) VolumeCreateOption {
return func(volume *Volume) error {
if volume.valid {
return ErrVolumeFinalized
}
- volume.config.Options = make(map[string]string)
- for key, value := range options {
- volume.config.Options[key] = value
- }
+ volume.config.GID = gid
return nil
}