Skip to content

Commit

Permalink
fix: right volume_condition message when healthy
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhem committed Nov 27, 2024
1 parent c086328 commit bfbe615
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions internal/driver/nodeserver_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,30 @@ func nodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest)
return nil, status.Error(codes.InvalidArgument, "volume ID or path empty")
}

var volumeCondition *csi.VolumeCondition

var statfs unix.Statfs_t
// See http://man7.org/linux/man-pages/man2/statfs.2.html for details.
err := unix.Statfs(req.GetVolumePath(), &statfs)
if err != nil && !errors.Is(err, unix.EIO) {
if errors.Is(err, unix.ENOENT) {
return nil, status.Errorf(codes.NotFound, "volume path not found: %v", err.Error())
switch {
case errors.Is(err, unix.EIO):
// EIO is returned when the filesystem is not mounted.
volumeCondition = &csi.VolumeCondition{
Abnormal: true,
Message: fmt.Sprintf("failed to get stats: %v", err.Error()),
}
case errors.Is(err, unix.ENOENT):
// ENOENT is returned when the volume path does not exist.
return nil, status.Errorf(codes.NotFound, "volume path not found: %v", err.Error())
case err != nil:
// Any other error is considered an internal error.
return nil, status.Errorf(codes.Internal, "failed to get stats: %v", err.Error())
}

// If we got a filesystem error that suggests things are not well with this volume
var abnormal bool
if errors.Is(err, unix.EIO) {
abnormal = true
default:
// If no error occurred, the volume is considered healthy.
volumeCondition = &csi.VolumeCondition{
Abnormal: false,
Message: "healthy",
}
}

response := &csi.NodeGetVolumeStatsResponse{
Expand All @@ -53,10 +63,7 @@ func nodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest)
Unit: csi.VolumeUsage_INODES,
},
},
VolumeCondition: &csi.VolumeCondition{
Abnormal: abnormal,
Message: fmt.Sprintf("failed to call statfs on volume, got err: %s", err),
},
VolumeCondition: volumeCondition,
}

log.V(2).Info("Successfully retrieved volume stats", "volumeID", req.GetVolumeId(), "volumePath", req.GetVolumePath(), "response", response)
Expand Down

0 comments on commit bfbe615

Please sign in to comment.