Skip to content

Commit 9a9c216

Browse files
committed
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.
1 parent 62b7516 commit 9a9c216

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/volume/iscsi/iscsi_util.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,22 @@ func (util *ISCSIUtil) persistISCSI(b iscsiDiskMounter) error {
491491
klog.Errorf("iscsi: failed to mkdir %s, error", globalPDPath)
492492
return err
493493
}
494+
495+
if b.volumeMode == v1.PersistentVolumeFilesystem {
496+
notMnt, err := b.mounter.IsLikelyNotMountPoint(globalPDPath)
497+
if err != nil {
498+
return err
499+
}
500+
if !notMnt {
501+
// The volume is already mounted, therefore the previous WaitForAttach must have
502+
// persisted the volume metadata. In addition, the metadata is actually *inside*
503+
// globalPDPath and we can't write it here, because it was shadowed by the volume
504+
// mount.
505+
klog.V(4).Infof("Skipping persistISCSI, the volume is already mounted at %s", globalPDPath)
506+
return nil
507+
}
508+
}
509+
494510
// Persist iscsi disk config to json file for DetachDisk path
495511
return util.persistISCSIFile(*(b.iscsiDisk), globalPDPath)
496512
}

0 commit comments

Comments
 (0)