iscsi: don't write json medata file when the volume is already mounted.

iSCSI volume plugin persists volume metadata into global mount directory,
before it is mounted. Content of the directory is shadowed by the volume
mount. Therefore kubelet should not write metadata to the directory when a
second pod uses the same volume on the same node.

1. The metadata were already persisted before mounting the volume for the
first pod.
2. The global mount directory has the volume mounted, so any write there
would write to the volume, which is undesirable.
This commit is contained in:
Jan Safranek 2020-06-17 20:09:54 +02:00
parent 62b7516b63
commit 9a9c216825

View File

@ -491,6 +491,22 @@ func (util *ISCSIUtil) persistISCSI(b iscsiDiskMounter) error {
klog.Errorf("iscsi: failed to mkdir %s, error", globalPDPath)
return err
}
if b.volumeMode == v1.PersistentVolumeFilesystem {
notMnt, err := b.mounter.IsLikelyNotMountPoint(globalPDPath)
if err != nil {
return err
}
if !notMnt {
// The volume is already mounted, therefore the previous WaitForAttach must have
// persisted the volume metadata. In addition, the metadata is actually *inside*
// globalPDPath and we can't write it here, because it was shadowed by the volume
// mount.
klog.V(4).Infof("Skipping persistISCSI, the volume is already mounted at %s", globalPDPath)
return nil
}
}
// Persist iscsi disk config to json file for DetachDisk path
return util.persistISCSIFile(*(b.iscsiDisk), globalPDPath)
}