Skip to content

fix: correct memory unit formatting in dashboard#821

Merged
sudermanjr merged 1 commit intoFairwindsOps:masterfrom
FatefulSet:fix/memory-unit-formatting
Jan 21, 2026
Merged

fix: correct memory unit formatting in dashboard#821
sudermanjr merged 1 commit intoFairwindsOps:masterfrom
FatefulSet:fix/memory-unit-formatting

Conversation

@FatefulSet
Copy link
Copy Markdown
Contributor

@FatefulSet FatefulSet commented Jan 20, 2026

This PR fixes #522 & #728

Checklist

  • I have signed the CLA
  • I have updated/added any relevant documentation

Description

What's the goal of this PR?

This PR improves the FormatResourceList function to handle memory unit conversion more accurately.

The previous implementation attempted to shorten strings by forcing conversions to Decimal scales (Kilo, Mega, Giga - Base 10), whereas Kubernetes memory is standardly represented in BinarySI (Ki, Mi, Gi - Base 2). This led to confusing displays (e.g., 1.05G instead of 1024Mi) and potential precision loss due to the RoundUp method.

Additionally, raw byte values from VPA recommendations (e.g., 104857600) were sometimes displayed as raw bytes instead of human-readable units.

What changes did you make?

The logic has been updated to:

  1. Force BinarySI formatting (Ki, Mi, Gi).
  2. Smartly round values:
    • Small values (< 1Mi) are rounded to the nearest Ki.
    • Standard values (>= 1Mi) are rounded to the nearest Mi.
  3. Ensure Set() is called to refresh the string representation even for existing round numbers.

Fixes #522
Fixes #728

@sudermanjr
Copy link
Copy Markdown
Member

Very cool, thanks! Looks like a few other tests might need to be updated

@FatefulSet FatefulSet force-pushed the fix/memory-unit-formatting branch from 066a2e2 to 7345690 Compare January 20, 2026 21:21
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 20, 2026

CLA assistant check
All committers have signed the CLA.

@FatefulSet
Copy link
Copy Markdown
Contributor Author

Hi @sudermanjr, thanks, I fixed the tests

@sudermanjr sudermanjr merged commit 4108c88 into FairwindsOps:master Jan 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory requests/limits units convertion Use mebibytes (Mi) instead of megabites (M) in memory recommendation

3 participants