aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/libpodruntime/runtime.go2
-rw-r--r--libpod/container_internal.go6
-rw-r--r--libpod/options.go7
-rw-r--r--libpod/runtime.go2
4 files changed, 14 insertions, 3 deletions
diff --git a/cmd/podman/libpodruntime/runtime.go b/cmd/podman/libpodruntime/runtime.go
index ea626ed8e..acb531737 100644
--- a/cmd/podman/libpodruntime/runtime.go
+++ b/cmd/podman/libpodruntime/runtime.go
@@ -55,7 +55,7 @@ func GetRuntimeWithStorageOpts(c *cli.Context, storageOpts *storage.StoreOptions
if c.GlobalIsSet("default-mounts-file") {
options = append(options, libpod.WithDefaultMountsFile(c.GlobalString("default-mounts-file")))
}
- options = append(options, libpod.WithHooksDir(c.GlobalString("hooks-dir-path")))
+ options = append(options, libpod.WithHooksDir(c.GlobalString("hooks-dir-path"), c.GlobalIsSet("hooks-dir-path")))
// TODO flag to set CNI plugins dir?
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 0015bed66..992c1d07b 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -1289,7 +1289,11 @@ func (c *Container) setupOCIHooks(ctx context.Context, g *generate.Generator) er
manager, err := hooks.New(ctx, []string{c.runtime.config.HooksDir})
if err != nil {
- return err
+ if c.runtime.config.HooksDirNotExistFatal || !os.IsNotExist(err) {
+ return err
+ }
+ logrus.Warnf("failed to load hooks: {}", err)
+ return nil
}
return manager.Hooks(g.Spec(), c.Spec().Annotations, len(c.config.UserVolumes) > 0)
diff --git a/libpod/options.go b/libpod/options.go
index 90b376668..1af788e46 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -180,13 +180,18 @@ 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) RuntimeOption {
+func WithHooksDir(hooksDir string, dirNotExistFatal bool) RuntimeOption {
return func(rt *Runtime) error {
if rt.valid {
return ErrRuntimeFinalized
}
+ if hooksDir == "" {
+ return errors.Wrap(ErrInvalidArg, "empty-string hook directories are not supported")
+ }
+
rt.config.HooksDir = hooksDir
+ rt.config.HooksDirNotExistFatal = dirNotExistFatal
return nil
}
}
diff --git a/libpod/runtime.go b/libpod/runtime.go
index e9d41a991..29011be10 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -131,6 +131,8 @@ type RuntimeConfig struct {
CNIPluginDir []string `toml:"cni_plugin_dir"`
// HooksDir Path to the directory containing hooks configuration files
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"`
// DefaultMountsFile is the path to the default mounts file for testing purposes only
DefaultMountsFile string `toml:"-"`
}