Skip to content

Commit 716dda2

Browse files
authored
fix(host.kernelModules): /lib/modules does not exist in a container (#1734)
1 parent 7f2a6d5 commit 716dda2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/collect/host_kernel_modules.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/pkg/errors"
1414
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
15+
"k8s.io/klog/v2"
1516
)
1617

1718
const (
@@ -120,7 +121,14 @@ func (l kernelModulesLoadable) collect() (map[string]KernelModuleInfo, error) {
120121
}
121122
kernel := strings.TrimSpace(string(out))
122123

123-
cmd := exec.Command("/usr/bin/find", "/lib/modules/"+kernel, "-type", "f", "-name", "*.ko*")
124+
kernelPath := "/lib/modules/" + kernel
125+
126+
if _, err := os.Stat(kernelPath); os.IsNotExist(err) {
127+
klog.V(2).Infof("modules are not loadable because kernel path %q does not exist, assuming we are in a container", kernelPath)
128+
return modules, nil
129+
}
130+
131+
cmd := exec.Command("/usr/bin/find", kernelPath, "-type", "f", "-name", "*.ko*")
124132
stdout, err := cmd.Output()
125133
if err != nil {
126134
return nil, err

0 commit comments

Comments
 (0)