From a0e8f887009bb336ef887df0ffbb9561a603bf35 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 30 Apr 2018 11:09:48 -0400 Subject: 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 Closes: #700 Approved by: rhatdan --- libpod/container.go | 4 +++ libpod/options.go | 85 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 53 insertions(+), 36 deletions(-) (limited to 'libpod') 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 + } +} -- cgit v1.2.3-54-g00ecf