Skip to content

Commit

Permalink
add check for shared volumes in getVolumeStats (#2419) (#2420)
Browse files Browse the repository at this point in the history
* add check for shared volumes in getVolumeStats (#2419)

Adds check for shared v4 volumes that have a different attach path than the assumed CSI volume path.

JIRA: PWX-35351

Signed-off-by: dahuang <[email protected]>
  • Loading branch information
dahuang-purestorage authored Feb 21, 2024
1 parent 1bc848a commit 79e0a6f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,3 +1491,8 @@ func (s *ProxySpec) GetPureFullVolumeName() string {

return ""
}

const (
// SharedVolExportPrefix is the export path where shared volumes are mounted
SharedVolExportPrefix = "/var/lib/osd/pxns"
)
3 changes: 2 additions & 1 deletion csi/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ func (s *OsdCsiServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetV
}

var attachPathMatch bool
sharedPath := fmt.Sprintf("%s/%s", api.SharedVolExportPrefix, id)
for _, attachPath := range vol.AttachPath {
if attachPath == path {
if attachPath == path || attachPath == sharedPath {
attachPathMatch = true
}
}
Expand Down
15 changes: 14 additions & 1 deletion csi/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,9 @@ func TestNodeGetVolumeStats(t *testing.T) {
used := int64(1 * 1024 * 1024)
available := size - used
id := "myvol123"
sharedPath := fmt.Sprintf("%s/%s", api.SharedVolExportPrefix, id) // "/var/lib/osd/pxns/myvol123"
vol := &api.Volume{
AttachPath: []string{"/test"},
AttachPath: []string{"/test", sharedPath},
Id: id,
Locator: &api.VolumeLocator{
Name: id,
Expand Down Expand Up @@ -1104,6 +1105,18 @@ func TestNodeGetVolumeStats(t *testing.T) {
assert.Equal(t, false, resp.VolumeCondition.Abnormal)
assert.Equal(t, "Volume status is up", resp.VolumeCondition.Message)

// Get VolumeStats - shared volume
resp, err = c.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{VolumeId: id, VolumePath: sharedPath})
assert.NoError(t, err)
assert.Equal(t, 1, len(resp.Usage))
assert.Equal(t, size, resp.Usage[0].Total)
assert.Equal(t, used, resp.Usage[0].Used)
assert.Equal(t, available, resp.Usage[0].Available)
assert.Equal(t, false, resp.VolumeCondition.Abnormal)
assert.Equal(t, "Volume status is up", resp.VolumeCondition.Message)

// Get VolumeStats - down
vol.Status = api.VolumeStatus_VOLUME_STATUS_DOWN
resp, err = c.NodeGetVolumeStats(
Expand Down

0 comments on commit 79e0a6f

Please sign in to comment.