From 9a9c2168258bd19f6323edf4bd918482ad3454f5 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Wed, 17 Jun 2020 20:09:54 +0200 Subject: [PATCH] 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. --- pkg/volume/iscsi/iscsi_util.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/volume/iscsi/iscsi_util.go b/pkg/volume/iscsi/iscsi_util.go index 986c2381a2b..405ebf296eb 100644 --- a/pkg/volume/iscsi/iscsi_util.go +++ b/pkg/volume/iscsi/iscsi_util.go @@ -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) }