From 1880daf59d1b1cab9d01a3ac57ed0390c305e64e Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 12 May 2020 21:17:25 +0200 Subject: [PATCH] Fix #1120: Do not let the size metric underflow uint. --- informer/disk/disk.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/informer/disk/disk.go b/informer/disk/disk.go index b9b9f31d..6c4f55e1 100644 --- a/informer/disk/disk.go +++ b/informer/disk/disk.go @@ -98,7 +98,13 @@ func (disk *Informer) GetMetric(ctx context.Context) *api.Metric { } else { switch disk.config.MetricType { case MetricFreeSpace: - metric = repoStat.StorageMax - repoStat.RepoSize + size := repoStat.RepoSize + total := repoStat.StorageMax + if size < total { + metric = total - size + } else { // Make sure we don't underflow + metric = 0 + } case MetricRepoSize: metric = repoStat.RepoSize }