Skip to content

daemon, client: diskUsage: explicitly exclude "-1" for containers#52309

Merged
vvoland merged 2 commits intomoby:masterfrom
thaJeztah:fix_disk_usage_followups
Apr 13, 2026
Merged

daemon, client: diskUsage: explicitly exclude "-1" for containers#52309
vvoland merged 2 commits intomoby:masterfrom
thaJeztah:fix_disk_usage_followups

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

The Containers field is set to "-1" if no information was collected; in
practice this should not happen when we collect diskusage information,
but let's be explicit.

Also rename the "i" variable to prevent it from being mistaken for the
slice's index value.

Follow-up to 46dba49

- How to verify it

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah marked this pull request as ready for review April 4, 2026 20:45
@thaJeztah thaJeztah force-pushed the fix_disk_usage_followups branch 2 times, most recently from c2880c4 to d092510 Compare April 7, 2026 13:43
@thaJeztah thaJeztah requested a review from vvoland April 10, 2026 12:07
@thaJeztah thaJeztah added this to the 29.4.1 milestone Apr 10, 2026
Comment thread client/system_disk_usage.go Outdated
Comment on lines +248 to +255
if img.Containers > 0 {
idu.ActiveCount++
} else if i.Size != -1 && i.SharedSize != -1 {
} else if img.Containers == 0 && img.Size != -1 && img.SharedSize != -1 {
// Only count reclaimable size if we have size information
idu.Reclaimable += (i.Size - i.SharedSize)
// and container-count is known to be zero (-1 means no
// information was available).
reclaimable := img.Size - img.SharedSize
idu.Reclaimable += reclaimable
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitty opinionated nit: switch would be a little bit more readable IMO 😅

Suggested change
if img.Containers > 0 {
idu.ActiveCount++
} else if i.Size != -1 && i.SharedSize != -1 {
} else if img.Containers == 0 && img.Size != -1 && img.SharedSize != -1 {
// Only count reclaimable size if we have size information
idu.Reclaimable += (i.Size - i.SharedSize)
// and container-count is known to be zero (-1 means no
// information was available).
reclaimable := img.Size - img.SharedSize
idu.Reclaimable += reclaimable
switch {
case img.Containers <= 0:
// No container-count information available; skip.
case img.Containers > 0:
du.ActiveCount++
case img.Size != -1 && img.SharedSize != -1:
reclaimable := img.Size - img.SharedSize
du.Reclaimable += reclaimable
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, yes, I agree. Not sure why I didn't do that; usually i'm the one suggesting that 😂

I'll update

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated, but I made a small change 😂 😉

-case img.Containers <= 0:
+case img.Containers < 0:

The Containers field is set to "-1" if no information was collected; in
practice this should not happen when we collect diskusage information,
but let's be explicit.

Also rename the "i" variable to prevent it from being mistaken for the
slice's index value.

Follow-up to 46dba49

Signed-off-by: Sebastiaan van Stijn <[email protected]>
…ainers

The Containers field is set to "-1" if no information was collected; in
practice this should not happen when we collect diskusage information,
but let's be explicit.

Also rename the "i" variable to prevent it from being mistaken for the
slice's index value.

Follow-up to 46dba49

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the fix_disk_usage_followups branch from d092510 to 1a45789 Compare April 10, 2026 20:02
@vvoland vvoland merged commit 828f87c into moby:master Apr 13, 2026
217 of 219 checks passed
@thaJeztah thaJeztah deleted the fix_disk_usage_followups branch April 13, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants