mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-10-16 10:57:49 +00:00
Add named volumes for each container to database
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
parent
1759eb09e1
commit
11799f4e0e
2 changed files with 46 additions and 0 deletions
|
|
@ -234,6 +234,8 @@ type ContainerConfig struct {
|
|||
// These include the SHM mount.
|
||||
// These must be unmounted before the container's rootfs is unmounted.
|
||||
Mounts []string `json:"mounts,omitempty"`
|
||||
// NamedVolumes lists the named volumes to mount into the container.
|
||||
NamedVolumes []*ContainerNamedVolume `json:"namedVolumes,omitempty"`
|
||||
|
||||
// Security Config
|
||||
|
||||
|
|
@ -368,6 +370,18 @@ type ContainerConfig struct {
|
|||
HealthCheckConfig *manifest.Schema2HealthConfig `json:"healthcheck"`
|
||||
}
|
||||
|
||||
// ContainerNamedVolume is a named volume that will be mounted into the
|
||||
// container.
|
||||
type ContainerNamedVolume struct {
|
||||
// Name is the name of the volume to mount in.
|
||||
// Must resolve to a valid volume present in this Podman.
|
||||
Name string `json:"volumeName"`
|
||||
// Dest is the mount's destination
|
||||
Dest string `json:"dest"`
|
||||
// Options are fstab style mount options
|
||||
Options []string `json:"options,omitempty"`
|
||||
}
|
||||
|
||||
// ContainerStatus returns a string representation for users
|
||||
// of a container state
|
||||
func (t ContainerStatus) String() string {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue