aboutsummaryrefslogtreecommitdiff
path: root/libpod/options.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-03-12 15:53:08 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-04-04 12:26:29 -0400
commit11799f4e0ec6256c65691828fb73501bda5d7eec (patch)
tree6f214ab0ddb882b83277d77209544692b0bbfa7c /libpod/options.go
parent1759eb09e1c13bc8392d515d69ca93226d067c73 (diff)
downloadpodman-11799f4e0ec6256c65691828fb73501bda5d7eec.tar.gz
podman-11799f4e0ec6256c65691828fb73501bda5d7eec.tar.bz2
podman-11799f4e0ec6256c65691828fb73501bda5d7eec.zip
Add named volumes for each container to database
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/options.go')
-rw-r--r--libpod/options.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/libpod/options.go b/libpod/options.go
index 24f126e66..86f1747ce 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -1255,6 +1255,38 @@ func withIsInfra() CtrCreateOption {
}
}
+// WithNamedVolumes adds the given named volumes to the container.
+func WithNamedVolumes(volumes []*ContainerNamedVolume) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+
+ 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)
+ }
+
+ if _, ok := destinations[vol.Dest]; ok {
+ return errors.Wrapf(err, "two volumes found with destination %s", vol.Dest)
+ }
+ destinations[vol.Dest] = true
+
+ ctr.config.NamedVolumes = append(ctr.config.NamedVolumes, &ContainerNamedVolume{
+ Name: vol.Name,
+ Dest: vol.Dest,
+ Options: vol.Options,
+ })
+ }
+
+ return nil
+ }
+}
+
// Volume Creation Options
// WithVolumeName sets the name of the volume.