summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/spec.go4
-rw-r--r--libpod/container.go4
-rw-r--r--libpod/options.go85
3 files changed, 57 insertions, 36 deletions
diff --git a/cmd/podman/spec.go b/cmd/podman/spec.go
index 14fe3a38a..fbe611cc3 100644
--- a/cmd/podman/spec.go
+++ b/cmd/podman/spec.go
@@ -652,6 +652,10 @@ func (c *createConfig) GetContainerCreateOptions() ([]libpod.CtrCreateOption, er
}
}
+ if len(c.Volumes) != 0 {
+ options = append(options, libpod.WithUserVolumes())
+ }
+
if c.NetMode.IsContainer() {
connectedCtr, err := c.Runtime.LookupContainer(c.NetMode.ConnectedContainer())
if err != nil {
diff --git a/libpod/container.go b/libpod/container.go
index e532ecba2..67aa086fc 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -190,6 +190,10 @@ type ContainerConfig struct {
// These include the SHM mount
// These must be unmounted before the container's rootfs is unmounted
Mounts []string `json:"mounts,omitempty"`
+ // UserVolumes indicates that the container has user-added volume mounts
+ // It is used to trigger OCI hooks that rely on the presence of user
+ // volumes
+ UserVolumes bool `json:"userVolumes, omitempty"`
// Security Config
// Whether the container is privileged
diff --git a/libpod/options.go b/libpod/options.go
index 981ca9a9d..eabb9d425 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -741,42 +741,6 @@ func WithCgroupParent(parent string) CtrCreateOption {
}
}
-// Pod Creation Options
-
-// WithPodName sets the name of the pod
-func WithPodName(name string) PodCreateOption {
- return func(pod *Pod) error {
- if pod.valid {
- return ErrPodFinalized
- }
-
- // Check the name against a regex
- if !nameRegex.MatchString(name) {
- return errors.Wrapf(ErrInvalidArg, "name must match regex [a-zA-Z0-9_-]+")
- }
-
- pod.config.Name = name
-
- return nil
- }
-}
-
-// WithPodLabels sets the labels of a pod
-func WithPodLabels(labels map[string]string) PodCreateOption {
- return func(pod *Pod) error {
- if pod.valid {
- return ErrPodFinalized
- }
-
- pod.config.Labels = make(map[string]string)
- for key, value := range labels {
- pod.config.Labels[key] = value
- }
-
- return nil
- }
-}
-
// WithDNSSearch sets the additional search domains of a container
func WithDNSSearch(searchDomains []string) CtrCreateOption {
return func(ctr *Container) error {
@@ -850,3 +814,52 @@ func WithGroups(groups []string) CtrCreateOption {
return nil
}
}
+
+// WithUserVolumes informs libpod that the container has user-added volumes
+// It is used to for triggering hooks that check for the presence of volume
+// mounts
+func WithUserVolumes() CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+ ctr.config.UserVolumes = true
+ return nil
+ }
+}
+
+// Pod Creation Options
+
+// WithPodName sets the name of the pod
+func WithPodName(name string) PodCreateOption {
+ return func(pod *Pod) error {
+ if pod.valid {
+ return ErrPodFinalized
+ }
+
+ // Check the name against a regex
+ if !nameRegex.MatchString(name) {
+ return errors.Wrapf(ErrInvalidArg, "name must match regex [a-zA-Z0-9_-]+")
+ }
+
+ pod.config.Name = name
+
+ return nil
+ }
+}
+
+// WithPodLabels sets the labels of a pod
+func WithPodLabels(labels map[string]string) PodCreateOption {
+ return func(pod *Pod) error {
+ if pod.valid {
+ return ErrPodFinalized
+ }
+
+ pod.config.Labels = make(map[string]string)
+ for key, value := range labels {
+ pod.config.Labels[key] = value
+ }
+
+ return nil
+ }
+}