mirror of
https://github.com/containers/podman
synced 2024-10-19 16:54:07 +00:00
Re-create OCI runtimes by path when it is missing
When an OCI runtime is given by full path, we need to ensure we use the same runtime on subsequent use. Unfortunately, users are often not considerate enough to use the same `--runtime` flag every time they invoke runtime - and if the runtime was not in containers.conf, that means we don't have it stored inn the libpod Runtime. Fortunately, since we have the full path, we can initialize the OCI runtime for use at the point where we pull the container from the database. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
parent
f9655d92d6
commit
338d521782
|
@ -2,7 +2,7 @@ package libpod
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"path/filepath"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
|
@ -400,14 +400,30 @@ func (s *BoltState) getContainerFromDB(id []byte, ctr *Container, ctrsBkt *bolt.
|
|||
// Handle legacy containers which might use a literal path for
|
||||
// their OCI runtime name.
|
||||
runtimeName := ctr.config.OCIRuntime
|
||||
if strings.HasPrefix(runtimeName, "/") {
|
||||
runtimeName = filepath.Base(runtimeName)
|
||||
}
|
||||
|
||||
ociRuntime, ok := s.runtime.ociRuntimes[runtimeName]
|
||||
if !ok {
|
||||
// Use a MissingRuntime implementation
|
||||
ociRuntime = getMissingRuntime(runtimeName, s.runtime)
|
||||
runtimeSet := false
|
||||
|
||||
// If the path starts with a / and exists, make a new
|
||||
// OCI runtime for it using the full path.
|
||||
if strings.HasPrefix(runtimeName, "/") {
|
||||
if stat, err := os.Stat(runtimeName); err == nil && !stat.IsDir() {
|
||||
newOCIRuntime, err := newConmonOCIRuntime(runtimeName, []string{runtimeName}, s.runtime.conmonPath, s.runtime.runtimeFlags, s.runtime.config)
|
||||
if err == nil {
|
||||
// The runtime lock should
|
||||
// protect against concurrent
|
||||
// modification of the map.
|
||||
ociRuntime = newOCIRuntime
|
||||
s.runtime.ociRuntimes[runtimeName] = ociRuntime
|
||||
runtimeSet = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !runtimeSet {
|
||||
// Use a MissingRuntime implementation
|
||||
ociRuntime = getMissingRuntime(runtimeName, s.runtime)
|
||||
}
|
||||
}
|
||||
ctr.ociRuntime = ociRuntime
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue