mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #57953 from andyzhangx/azuredisk-remount-fix
Automatic merge from submit-queue (batch tested with PRs 57733, 57613, 57953). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. fix device name change issue for azure disk: add remount logic **What this PR does / why we need it**: fix device name change issue for azure disk: add remount logic Accoding to [Troubleshoot Linux VM device name change](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/troubleshoot-device-names-problems), there is possibility of device name change, so when kubelet is restarted, we need to check whether the following two paths are still valid: 1. `/var/lib/kubelet/plugins/kubernetes.io/azure-disk/mounts/m358246426`: in MountDevice func 2. `/var/lib/kubelet/pods/950f2eb8-d4e7-11e7-bc95-000d3a041274/volumes/kubernetes.io~azure-disk/pvc-67e4e319-d4e7-11e7-bc95-000d3a041274`: in SetUpAt func **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #57952 **Special notes for your reviewer**: this is a corresponding fix of https://github.com/kubernetes/kubernetes/pull/57549, #57549 uses '/dev/disk/by-id', and this PR would check whether the mountPath is valid when kubelet restart(e.g. after VM reboot since device name may change), if not valid, remount, remember '/dev/disk/by-id' will be always valid. **Release note**: ``` fix device name change issue for azure disk: add remount logic ```
This commit is contained in:
commit
b9a62423c6
@ -232,6 +232,19 @@ func (attacher *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath str
|
||||
}
|
||||
}
|
||||
|
||||
if !notMnt {
|
||||
// testing original mount point, make sure the mount link is valid
|
||||
if _, err := (&osIOHandler{}).ReadDir(deviceMountPath); err != nil {
|
||||
// mount link is invalid, now unmount and remount later
|
||||
glog.Warningf("azureDisk - ReadDir %s failed with %v, unmount this directory", deviceMountPath, err)
|
||||
if err := mounter.Unmount(deviceMountPath); err != nil {
|
||||
glog.Errorf("azureDisk - Unmount deviceMountPath %s failed with %v", deviceMountPath, err)
|
||||
return err
|
||||
}
|
||||
notMnt = true
|
||||
}
|
||||
}
|
||||
|
||||
volumeSource, err := getVolumeSource(spec)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -86,8 +86,19 @@ func (m *azureDiskMounter) SetUpAt(dir string, fsGroup *int64) error {
|
||||
return err
|
||||
}
|
||||
if !mountPoint {
|
||||
glog.V(4).Infof("azureDisk - already mounted to target %s", dir)
|
||||
return nil
|
||||
// testing original mount point, make sure the mount link is valid
|
||||
_, err := (&osIOHandler{}).ReadDir(dir)
|
||||
if err == nil {
|
||||
glog.V(4).Infof("azureDisk - already mounted to target %s", dir)
|
||||
return nil
|
||||
}
|
||||
// mount link is invalid, now unmount and remount later
|
||||
glog.Warningf("azureDisk - ReadDir %s failed with %v, unmount this directory", dir, err)
|
||||
if err := mounter.Unmount(dir); err != nil {
|
||||
glog.Errorf("azureDisk - Unmount directory %s failed with %v", dir, err)
|
||||
return err
|
||||
}
|
||||
mountPoint = true
|
||||
}
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
|
Loading…
Reference in New Issue
Block a user