From f6fc73573c7308004bfa62f5c6dbda0fef941a89 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Mon, 2 Mar 2020 12:54:02 +0100 Subject: [PATCH] Call NodeUnpublish after NodePublish timeout When NodePublish times out and user deletes corresponding pod, the driver may continue publishing the volume. In order to "cancel" this operation, Kubernetes must issue NodeUnpublish and wait until it finishes. Therefore, NodeUnpublish should be called even if the target directory (created by the driver) does not exist yet. --- pkg/volume/csi/csi_block.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/pkg/volume/csi/csi_block.go b/pkg/volume/csi/csi_block.go index ceacdc4a140..2d8d31fd897 100644 --- a/pkg/volume/csi/csi_block.go +++ b/pkg/volume/csi/csi_block.go @@ -503,19 +503,8 @@ func (m *csiBlockMapper) UnmapPodDevice() error { ctx, cancel := context.WithTimeout(context.Background(), csiTimeout) defer cancel() - // Call NodeUnpublishVolume - if _, err := os.Stat(publishPath); err != nil { - if os.IsNotExist(err) { - klog.V(4).Infof(log("blockMapper.UnmapPodDevice publishPath(%s) has already been deleted, skip calling NodeUnpublishVolume", publishPath)) - } else { - return err - } - } else { - err := m.unpublishVolumeForBlock(ctx, csiClient, publishPath) - if err != nil { - return err - } - } - - return nil + // Call NodeUnpublishVolume. + // Even if publishPath does not exist - previous NodePublish may have timed out + // and Kubernetes makes sure that the operation is finished. + return m.unpublishVolumeForBlock(ctx, csiClient, publishPath) }