aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2018-09-17 09:33:11 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-09-17 16:28:28 +0000
commit800eb8633850ddbcd01aa827fe4e505e6075e253 (patch)
tree92502a354452da67983a4114f31fc60acf8e965b /libpod
parent8b66eae7d8dcb298d05bfb0234104bfda6be3929 (diff)
downloadpodman-800eb8633850ddbcd01aa827fe4e505e6075e253.tar.gz
podman-800eb8633850ddbcd01aa827fe4e505e6075e253.tar.bz2
podman-800eb8633850ddbcd01aa827fe4e505e6075e253.zip
Hooks supports two directories, process default and override
ALso cleanup files section or podman man page Add description of policy.json Sort alphabetically. Add more info on oci hooks Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Closes: #1487 Approved by: umohnani8
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal.go25
-rw-r--r--libpod/options.go6
-rw-r--r--libpod/runtime.go4
3 files changed, 22 insertions, 13 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 79bc49c37..e5e871d6f 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -1246,7 +1246,7 @@ func (c *Container) saveSpec(spec *spec.Spec) error {
}
func (c *Container) setupOCIHooks(ctx context.Context, config *spec.Spec) (extensionStageHooks map[string][]spec.Hook, err error) {
- if c.runtime.config.HooksDir == "" {
+ if len(c.runtime.config.HooksDir) == 0 {
return nil, nil
}
@@ -1277,16 +1277,25 @@ func (c *Container) setupOCIHooks(ctx context.Context, config *spec.Spec) (exten
}
}
- manager, err := hooks.New(ctx, []string{c.runtime.config.HooksDir}, []string{"poststop"}, lang)
- if err != nil {
- if c.runtime.config.HooksDirNotExistFatal || !os.IsNotExist(err) {
+ var allHooks map[string][]spec.Hook
+ for _, hDir := range c.runtime.config.HooksDir {
+ manager, err := hooks.New(ctx, []string{hDir}, []string{"poststop"}, lang)
+ if err != nil {
+ if c.runtime.config.HooksDirNotExistFatal || !os.IsNotExist(err) {
+ return nil, err
+ }
+ logrus.Warnf("failed to load hooks: {}", err)
+ return nil, nil
+ }
+ hooks, err := manager.Hooks(config, c.Spec().Annotations, len(c.config.UserVolumes) > 0)
+ if err != nil {
return nil, err
}
- logrus.Warnf("failed to load hooks: {}", err)
- return nil, nil
+ for i, hook := range hooks {
+ allHooks[i] = hook
+ }
}
-
- return manager.Hooks(config, c.Spec().Annotations, len(c.config.UserVolumes) > 0)
+ return allHooks, nil
}
// mount mounts the container's root filesystem
diff --git a/libpod/options.go b/libpod/options.go
index e6751d68d..1a29c0705 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -181,7 +181,7 @@ func WithStaticDir(dir string) RuntimeOption {
// WithHooksDir sets the directory to look for OCI runtime hooks config.
// Note we are not saving this in database, since this is really just for used
// for testing.
-func WithHooksDir(hooksDir string, dirNotExistFatal bool) RuntimeOption {
+func WithHooksDir(hooksDir string) RuntimeOption {
return func(rt *Runtime) error {
if rt.valid {
return ErrRuntimeFinalized
@@ -191,8 +191,8 @@ func WithHooksDir(hooksDir string, dirNotExistFatal bool) RuntimeOption {
return errors.Wrap(ErrInvalidArg, "empty-string hook directories are not supported")
}
- rt.config.HooksDir = hooksDir
- rt.config.HooksDirNotExistFatal = dirNotExistFatal
+ rt.config.HooksDir = []string{hooksDir}
+ rt.config.HooksDirNotExistFatal = true
return nil
}
}
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 736169932..c69854a17 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -143,7 +143,7 @@ type RuntimeConfig struct {
// to attach pods to
CNIDefaultNetwork string `toml:"cni_default_network,omitempty"`
// HooksDir Path to the directory containing hooks configuration files
- HooksDir string `toml:"hooks_dir"`
+ HooksDir []string `toml:"hooks_dir"`
// HooksDirNotExistFatal switches between fatal errors and non-fatal
// warnings if the configured HooksDir does not exist.
HooksDirNotExistFatal bool `toml:"hooks_dir_not_exist_fatal"`
@@ -199,7 +199,7 @@ var (
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
},
CgroupManager: SystemdCgroupsManager,
- HooksDir: hooks.DefaultDir,
+ HooksDir: []string{hooks.DefaultDir, hooks.OverrideDir},
StaticDir: filepath.Join(storage.DefaultStoreOptions.GraphRoot, "libpod"),
TmpDir: "",
MaxLogSize: -1,