summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-02-27 22:31:18 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-03-06 01:21:09 +0000
commitabd2ae7a0ca8ee1c292e08cac4818fc8b7f4c384 (patch)
tree73d42dfdf4e200a14611c7e5d370e86abb3fca53 /libpod
parentff9da1fb3f4122276cf9f78cf0ae4a4d461f78da (diff)
downloadpodman-abd2ae7a0ca8ee1c292e08cac4818fc8b7f4c384.tar.gz
podman-abd2ae7a0ca8ee1c292e08cac4818fc8b7f4c384.tar.bz2
podman-abd2ae7a0ca8ee1c292e08cac4818fc8b7f4c384.zip
Change conmon and runtime paths to arrays
This allows more graceful handling of multiple paths in a config file. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #430 Approved by: rhatdan
Diffstat (limited to 'libpod')
-rw-r--r--libpod/options.go15
-rw-r--r--libpod/runtime.go86
2 files changed, 69 insertions, 32 deletions
diff --git a/libpod/options.go b/libpod/options.go
index 56e8fa203..7cbe9afb4 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -101,7 +101,11 @@ func WithOCIRuntime(runtimePath string) RuntimeOption {
return ErrRuntimeFinalized
}
- rt.config.RuntimePath = runtimePath
+ if runtimePath == "" {
+ return errors.Wrapf(ErrInvalidArg, "must provide a valid path")
+ }
+
+ rt.config.RuntimePath = []string{runtimePath}
return nil
}
@@ -114,10 +118,13 @@ func WithConmonPath(path string) RuntimeOption {
if rt.valid {
return ErrRuntimeFinalized
}
- // TODO Once libkpod is eliminated, "" should throw an error
- if path != "" {
- rt.config.ConmonPath = path
+
+ if path == "" {
+ return errors.Wrapf(ErrInvalidArg, "must provide a valid path")
}
+
+ rt.config.ConmonPath = []string{path}
+
return nil
}
}
diff --git a/libpod/runtime.go b/libpod/runtime.go
index c833f2300..61c757d1b 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -50,6 +50,8 @@ type Runtime struct {
ociRuntime *OCIRuntime
lockDir string
netPlugin ocicni.CNIPlugin
+ ociRuntimePath string
+ conmonPath string
valid bool
lock sync.RWMutex
}
@@ -60,8 +62,8 @@ type RuntimeConfig struct {
ImageDefaultTransport string
SignaturePolicyPath string
StateType RuntimeStateStore
- RuntimePath string
- ConmonPath string
+ RuntimePath []string // The first path pointing to a valid file will be used
+ ConmonPath []string // The first path pointing to a valid file will be used
ConmonEnvVars []string
CgroupManager string
StaticDir string
@@ -78,8 +80,20 @@ var (
StorageConfig: storage.StoreOptions{},
ImageDefaultTransport: DefaultTransport,
StateType: BoltDBStateStore,
- RuntimePath: findRuncPath(),
- ConmonPath: findConmonPath(),
+ RuntimePath: []string{
+ "/usr/bin/runc",
+ "/usr/sbin/runc",
+ "/sbin/runc",
+ "/bin/runc",
+ "/usr/lib/cri-o-runc/sbin/runc",
+ },
+ ConmonPath: []string{
+ "/usr/libexec/crio/conmon",
+ "/usr/local/libexec/crio/conmon",
+ "/usr/bin/conmon",
+ "/usr/sbin/conmon",
+ "/usr/lib/crio/bin/conmon",
+ },
ConmonEnvVars: []string{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
},
@@ -93,25 +107,6 @@ var (
}
)
-func findConmonPath() string {
- paths := []string{"/usr/libexec/crio/conmon", "/usr/local/libexec/crio/conmon", "/usr/bin/conmon", "/usr/sbin/conmon", "/usr/lib/crio/bin/conmon"}
- return pathHelper(paths)
-}
-
-func findRuncPath() string {
- paths := []string{"/usr/bin/runc", "/usr/sbin/runc", "/sbin/runc", "/bin/runc", "/usr/lib/cri-o-runc/sbin/runc"}
- return pathHelper(paths)
-}
-
-func pathHelper(paths []string) string {
- for _, path := range paths {
- if _, err := os.Stat(path); err == nil {
- return path
- }
- }
- return paths[0]
-}
-
// NewRuntime creates a new container runtime
// Options can be passed to override the default configuration for the runtime
func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
@@ -128,9 +123,44 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
}
}
- // Check for the existence of the runc binary
- if _, err := os.Stat(runtime.config.RuntimePath); err != nil {
- return nil, errors.Errorf("unable to find runc binary %s", runtime.config.RuntimePath)
+ // Find a working OCI runtime binary
+ foundRuntime := false
+ for _, path := range runtime.config.RuntimePath {
+ stat, err := os.Stat(path)
+ if err != nil {
+ continue
+ }
+ if stat.IsDir() {
+ continue
+ }
+ foundRuntime = true
+ runtime.ociRuntimePath = path
+ break
+ }
+ if !foundRuntime {
+ return nil, errors.Wrapf(ErrInvalidArg,
+ "could not find a working runc binary (configured options: %v)",
+ runtime.config.RuntimePath)
+ }
+
+ // Find a working conmon binary
+ foundConmon := false
+ for _, path := range runtime.config.ConmonPath {
+ stat, err := os.Stat(path)
+ if err != nil {
+ continue
+ }
+ if stat.IsDir() {
+ continue
+ }
+ foundConmon = true
+ runtime.conmonPath = path
+ break
+ }
+ if !foundConmon {
+ return nil, errors.Wrapf(ErrInvalidArg,
+ "could not find a working conmon binary (configured options: %v)",
+ runtime.config.RuntimePath)
}
// Set up containers/storage
@@ -165,8 +195,8 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
}
// Make an OCI runtime to perform container operations
- ociRuntime, err := newOCIRuntime("runc", runtime.config.RuntimePath,
- runtime.config.ConmonPath, runtime.config.ConmonEnvVars,
+ ociRuntime, err := newOCIRuntime("runc", runtime.ociRuntimePath,
+ runtime.conmonPath, runtime.config.ConmonEnvVars,
runtime.config.CgroupManager, runtime.config.TmpDir,
runtime.config.MaxLogSize, runtime.config.NoPivotRoot)
if err != nil {