api: Fix couldn't delete umount disks from node
When the disk's file system has changed but user hasn't deleted it,
just keep the disk and don't allow user to update it.
@@ -56,11 +56,22 @@ func (m *VolumeManager) DiskUpdate(name string, updateDisks []types.DiskSpec) (*
originDisks := node.Spec.Disks
diskUpdateMap := map[string]types.DiskSpec{}
+
for _, uDisk := range updateDisks {
diskInfo, err := util.GetDiskInfo(uDisk.Path)
if err != nil {
return nil, err
}
+ isInvalid := false
+ for fsid, oDisk := range originDisks {
+ if oDisk.Path == uDisk.Path && fsid != diskInfo.Fsid {
+ isInvalid = true
+ logrus.Warnf("Update disk on node %v warning: The disk %v has changed file system, please mount it back or remove it", name, oDisk.Path)
+ diskUpdateMap[fsid] = oDisk
+ break
+ }
+ }
+ if !isInvalid {
// update disks
if oDisk, ok := originDisks[diskInfo.Fsid]; ok {
if oDisk.Path != uDisk.Path {
@@ -69,6 +80,7 @@ func (m *VolumeManager) DiskUpdate(name string, updateDisks []types.DiskSpec) (*
} else if oDisk.StorageMaximum != uDisk.StorageMaximum && uDisk.StorageMaximum != diskInfo.StorageMaximum {
logrus.Warnf("StorageMaximum has been changed for disk %v of node %v. Detected maximum storage %v, current setting %v", diskInfo.Path, name, diskInfo.StorageMaximum, uDisk.StorageMaximum)
}
+ diskUpdateMap[diskInfo.Fsid] = uDisk
} else {
// add disks
if uDisk.StorageMaximum != 0 && uDisk.StorageMaximum != diskInfo.StorageMaximum {
@@ -76,9 +88,10 @@ func (m *VolumeManager) DiskUpdate(name string, updateDisks []types.DiskSpec) (*
} else {
uDisk.StorageMaximum = diskInfo.StorageMaximum
}
- }
diskUpdateMap[diskInfo.Fsid] = uDisk
}
+ }
+ }
// delete disks
for fsid, oDisk := range originDisks {
