aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-04-30 11:09:48 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-03 12:23:12 +0000
commita0e8f887009bb336ef887df0ffbb9561a603bf35 (patch)
treee439723f44c74366ae9c8994cf81e648356f92a4
parentf6d41abfb04550f473b80d89cf8c02e5744a5b0b (diff)
downloadpodman-a0e8f887009bb336ef887df0ffbb9561a603bf35.tar.gz
podman-a0e8f887009bb336ef887df0ffbb9561a603bf35.tar.bz2
podman-a0e8f887009bb336ef887df0ffbb9561a603bf35.zip
Add config bool to indicate there are user volumes
This allows us to accurately trigger OCI hooks that trigger on the presence of volume mounts. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #700 Approved by: rhatdan
-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
+ }
+}