fix NixOS kernel modules path in podman driver

pull/12739/head
Alex Andrews 2021-10-19 20:44:47 +01:00
parent 09365b4b04
commit 8fb9165f82
1 changed files with 22 additions and 1 deletions
pkg/drivers/kic/oci

View File

@ -108,6 +108,21 @@ func PrepareContainerNode(p CreateParams) error {
return nil
}
// kernelModulesPath checks for the existence of a known kernel modules directory, returning the
// first valid path
func kernelModulesPath() (string, error) {
paths := []string{
"/lib/modules",
"/run/current-system/kernel-modules/lib/modules", // NixOS
}
for _, path := range paths {
if _, err := os.Stat(path); !os.IsNotExist(err) {
return path, nil
}
}
return "", errors.New("Unable to locate kernel modules")
}
// CreateContainerNode creates a new container node
func CreateContainerNode(p CreateParams) error {
// on windows os, if docker desktop is using Windows Containers. Exit early with error
@ -122,6 +137,12 @@ func CreateContainerNode(p CreateParams) error {
}
}
modulesPath, err := kernelModulesPath()
if err != nil {
klog.Errorf("error getting kernel modules path: %v", err)
return errors.Wrap(err, "kernel modules")
}
runArgs := []string{
"-d", // run the container detached
"-t", // allocate a tty for entrypoint logs
@ -136,7 +157,7 @@ func CreateContainerNode(p CreateParams) error {
"--tmpfs", "/run", // systemd wants a writable /run
// logs,pods be stroed on filesystem vs inside container,
// some k8s things want /lib/modules
"-v", "/lib/modules:/lib/modules:ro",
"-v", fmt.Sprintf("%s:/lib/modules:ro", modulesPath),
"--hostname", p.Name, // make hostname match container name
"--name", p.Name, // ... and set the container name
"--label", fmt.Sprintf("%s=%s", CreatedByLabelKey, "true"),