protokube: check for device symlinks

This commit is contained in:
andrewsykim 2018-04-04 13:37:24 -04:00
parent 1eee3c35a1
commit b0ef6a2f99
2 changed files with 14 additions and 2 deletions

View File

@ -19,6 +19,7 @@ package protokube
import (
"fmt"
"net"
"path/filepath"
"time"
"github.com/golang/glog"
@ -195,6 +196,17 @@ func pathFor(hostPath string) string {
return RootFS + hostPath[1:]
}
func pathForSymlinks(hostPath string) string {
path := pathFor(hostPath)
symlink, err := filepath.EvalSymlinks(path)
if err != nil {
return path
}
return symlink
}
func (k *KubeBoot) String() string {
return DebugString(k)
}

View File

@ -187,8 +187,8 @@ func (k *VolumeMountController) safeFormatAndMount(volume *Volume, mountpoint st
}
if mountedDevice != "" {
// We check that it is the correct device. We also tolerate /dev/X as well as /root/dev/X
if mountedDevice != source && mountedDevice != device {
// We check that it is the correct device. We also tolerate /dev/X as well as /root/dev/X and any of symlinks to them
if mountedDevice != source && mountedDevice != device && pathFor(mountedDevice) != pathForSymlinks(device) {
return fmt.Errorf("device already mounted at %s, but is %s and we want %s or %s", target, mountedDevice, source, device)
}
} else {