Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for shared volumes in getVolumeStats #2419

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion csi/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ func (s *OsdCsiServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetV

var attachPathMatch bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I don't understand the reason for this path match check. Regardless of the attachPath we can always return the volume usage for every volume. The attach path does not dictate the volume usage.

for _, attachPath := range vol.AttachPath {
if attachPath == path {
sharedPath := fmt.Sprintf("%s/%s", api.SharedVolExportPrefix, id)
dahuang-purestorage marked this conversation as resolved.
Show resolved Hide resolved
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
Loading