Skip to content

Commit 7caf731

Browse files
committed
Change publish path for CSI block volume per pod
This change is to allow CSI driver to publish the same volume for multipe pods on the same node.
1 parent 97d45fe commit 7caf731

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

pkg/volume/csi/csi_block.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,31 @@ var _ volume.BlockVolumeMapper = &csiBlockMapper{}
5151
var _ volume.CustomBlockVolumeMapper = &csiBlockMapper{}
5252

5353
// GetGlobalMapPath returns a global map path (on the node) to a device file which will be symlinked to
54-
// Example: plugins/kubernetes.io/csi/volumeDevices/{pvname}/dev
54+
// Example: plugins/kubernetes.io/csi/volumeDevices/{specName}/dev
5555
func (m *csiBlockMapper) GetGlobalMapPath(spec *volume.Spec) (string, error) {
56-
dir := getVolumeDevicePluginDir(spec.Name(), m.plugin.host)
56+
dir := getVolumeDevicePluginDir(m.specName, m.plugin.host)
5757
klog.V(4).Infof(log("blockMapper.GetGlobalMapPath = %s", dir))
5858
return dir, nil
5959
}
6060

6161
// getStagingPath returns a staging path for a directory (on the node) that should be used on NodeStageVolume/NodeUnstageVolume
62-
// Example: plugins/kubernetes.io/csi/volumeDevices/staging/{pvname}
62+
// Example: plugins/kubernetes.io/csi/volumeDevices/staging/{specName}
6363
func (m *csiBlockMapper) getStagingPath() string {
64-
sanitizedSpecVolID := utilstrings.EscapeQualifiedName(m.specName)
65-
return filepath.Join(m.plugin.host.GetVolumeDevicePluginDir(CSIPluginName), "staging", sanitizedSpecVolID)
64+
return filepath.Join(m.plugin.host.GetVolumeDevicePluginDir(CSIPluginName), "staging", m.specName)
6665
}
6766

6867
// getPublishPath returns a publish path for a file (on the node) that should be used on NodePublishVolume/NodeUnpublishVolume
69-
// Example: plugins/kubernetes.io/csi/volumeDevices/publish/{pvname}
68+
// Example: plugins/kubernetes.io/csi/volumeDevices/publish/{specName}/{podUID}
7069
func (m *csiBlockMapper) getPublishPath() string {
71-
sanitizedSpecVolID := utilstrings.EscapeQualifiedName(m.specName)
72-
return filepath.Join(m.plugin.host.GetVolumeDevicePluginDir(CSIPluginName), "publish", sanitizedSpecVolID)
70+
return filepath.Join(m.plugin.host.GetVolumeDevicePluginDir(CSIPluginName), "publish", m.specName, string(m.podUID))
7371
}
7472

7573
// GetPodDeviceMapPath returns pod's device file which will be mapped to a volume
76-
// returns: pods/{podUid}/volumeDevices/kubernetes.io~csi, {pvname}
74+
// returns: pods/{podUid}/volumeDevices/kubernetes.io~csi, {specName}
7775
func (m *csiBlockMapper) GetPodDeviceMapPath() (string, string) {
7876
path := m.plugin.host.GetPodVolumeDeviceDir(m.podUID, utilstrings.EscapeQualifiedName(CSIPluginName))
79-
specName := m.specName
80-
klog.V(4).Infof(log("blockMapper.GetPodDeviceMapPath [path=%s; name=%s]", path, specName))
81-
return path, specName
77+
klog.V(4).Infof(log("blockMapper.GetPodDeviceMapPath [path=%s; name=%s]", path, m.specName))
78+
return path, m.specName
8279
}
8380

8481
// stageVolumeForBlock stages a block volume to stagingPath

pkg/volume/csi/csi_block_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ func TestBlockMapperGetPublishPath(t *testing.T) {
141141
{
142142
name: "simple specName",
143143
specVolumeName: "spec-0",
144-
path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/publish/%s", "spec-0")),
144+
path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/publish/%s/%s", "spec-0", testPodUID)),
145145
},
146146
{
147147
name: "specName with dots",
148148
specVolumeName: "test.spec.1",
149-
path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/publish/%s", "test.spec.1")),
149+
path: filepath.Join(tmpDir, fmt.Sprintf("plugins/kubernetes.io/csi/volumeDevices/publish/%s/%s", "test.spec.1", testPodUID)),
150150
},
151151
}
152152
for _, tc := range testCases {

0 commit comments

Comments
 (0)