mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
util: NodeGetVolumeStatsResponse.Usage may not contain negative values
Following the CSI specification, values that are included in the
VolumeUsage MUST NOT be negative. However, CephFS seems to return -1 for
the number of inodes that are available. Instead of returning a
negative value, set it to 0 so that it will not get included in the
encoded JSON response.
Updates: #2579
See-also: 5b0d454015/spec.md (L2477-L2487)
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
6ffb91c047
commit
6d3e25f069
@ -263,17 +263,30 @@ func FilesystemNodeGetVolumeStats(ctx context.Context, targetPath string) (*csi.
|
||||
return &csi.NodeGetVolumeStatsResponse{
|
||||
Usage: []*csi.VolumeUsage{
|
||||
{
|
||||
Available: available,
|
||||
Total: capacity,
|
||||
Used: used,
|
||||
Available: requirePositive(available),
|
||||
Total: requirePositive(capacity),
|
||||
Used: requirePositive(used),
|
||||
Unit: csi.VolumeUsage_BYTES,
|
||||
},
|
||||
{
|
||||
Available: inodesFree,
|
||||
Total: inodes,
|
||||
Used: inodesUsed,
|
||||
Available: requirePositive(inodesFree),
|
||||
Total: requirePositive(inodes),
|
||||
Used: requirePositive(inodesUsed),
|
||||
Unit: csi.VolumeUsage_INODES,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// requirePositive returns the value for `x` when it is greater or equal to 0,
|
||||
// or returns 0 in the acse `x` is negative.
|
||||
//
|
||||
// This is used for VolumeUsage entries in the NodeGetVolumeStatsResponse. The
|
||||
// CSI spec does not allow negative values in the VolumeUsage objects.
|
||||
func requirePositive(x int64) int64 {
|
||||
if x >= 0 {
|
||||
return x
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user