diff --git a/pkg/daemon/ceph/osd/nsenter.go b/pkg/daemon/ceph/osd/nsenter.go index 7d10e51e0..e44eb867f 100644 --- a/pkg/daemon/ceph/osd/nsenter.go +++ b/pkg/daemon/ceph/osd/nsenter.go @@ -18,6 +18,7 @@ package osd import ( "fmt" + "os" "path/filepath" "github.com/pkg/errors" @@ -77,11 +78,12 @@ func (ne *NSEnter) checkIfBinaryExistsOnHost() error { err := ne.callNsEnter(binPath) if err != nil { logger.Debugf("failed to call nsenter. %v", err) - // If nsenter failed, let's try with the rootfs directly + // If nsenter failed, let's try with the rootfs directly but only lookup the binary and do not execute it + // This avoids mismatch libraries between the container and the host while executing rootFSBinPath := filepath.Join(rootFSPath, binPath) - output, err := ne.context.Executor.ExecuteCommandWithCombinedOutput(rootFSBinPath, ne.binaryArgs...) + _, err := os.Stat(rootFSBinPath) if err != nil { - logger.Debugf("failed to execute command on the host rootfs. %s. %v", output, err) + logger.Debugf("failed to lookup binary path %q on the host rootfs. %v", rootFSBinPath, err) continue } binPath = rootFSBinPath diff --git a/pkg/daemon/ceph/osd/nsenter_test.go b/pkg/daemon/ceph/osd/nsenter_test.go index 6bffaea8e..f6c70cf55 100644 --- a/pkg/daemon/ceph/osd/nsenter_test.go +++ b/pkg/daemon/ceph/osd/nsenter_test.go @@ -51,23 +51,4 @@ func TestCheckIfBinaryExistsOnHost(t *testing.T) { ne := NewNsenter(context, lvmCommandToCheck, []string{"help"}) err := ne.checkIfBinaryExistsOnHost() assert.NoError(t, err) - - executor.MockExecuteCommandWithCombinedOutput = func(command string, args ...string) (string, error) { - logger.Infof("%s %v", command, args) - switch command { - - case "/rootfs/usr/sbin/lvm": - return "success", nil - - case "/rootfs/sbin/lvm": - return "success", nil - - } - return "", errors.Errorf("unknown command %s %s", command, args) - } - - context = &clusterd.Context{Executor: executor} - ne = NewNsenter(context, lvmCommandToCheck, []string{"help"}) - err = ne.checkIfBinaryExistsOnHost() - assert.NoError(t, err) }