karpenter: NodePool: Parse CPU quantities as cores - #1244
Open
RajPrakash681 wants to merge 1 commit into
Open
Conversation
Signed-off-by: RajPrakash681 <rjnt452@gmail.com>
RajPrakash681
requested review from
ashu8912,
illume,
joaquimrocha,
skoeva,
sniok,
vyncent-t and
yolossn
as code owners
August 25, 2026 09:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
status.resources.cpuandspec.limits.cpuon a Karpenter NodePool are Kubernetes resource quantities, so they can carry a suffix. Both NodePool views read them withparseInt, which stops at the first non-digit:parseInt('1750m')is1750, so 1.75 cores is displayed and charted as 1750 cores.parseIntalso truncates a plain decimal, turning1.5cores into1.Karpenter reports these values in milli-cores whenever the amount is not a whole number of cores, which is the normal case for a NodePool that has scaled up partially. With
spec.limits.cpu: 8andstatus.resources.cpu: 1750m, the list column read1750/8and the percentage bar pinned at full.Memory in the same two files was already correct — it goes through
parseRam(). Only CPU usedparseInt.Related Issue
Fixes #1243
Changes
Added
karpenter/src/helpers/parseCpu.tsx, convertingn,uandmquantities to cores and returning 0 for anything unparseable. It mirrors the shape of the existingparseRamhelper next to it, and the conversion matchesparseCpuQuantityin the kubeflow plugin.On why this is a local helper rather than the SDK's
parseCpufrom@kinvolk/headlamp-plugin/lib/lib/units: in the pinnedheadlamp-plugin0.14.0 that function parses withparseInt, soparseCpu('1.5') / TO_ONE_CPUis1rather than1.5, and an unparseable value yieldsNaNinstead of0, which would feedNaNstraight intoPercentageBar. Using it here would trade this bug for a smaller one. Happy to switch to the SDK function instead once a release carries theparseFloatversion, if maintainers would rather wait for that.Added
karpenter/src/helpers/parseCpu.test.tscovering milli-cores, micro-cores, nano-cores, unsuffixed and decimal quantities, and the unparseable case.NodePool/List.tsxandNodePool/Details.tsxnow read CPU throughparseCpuinstead ofparseInt.Steps to Test
cd karpenter && npm install && npm run test— the four newparseCpucases pass.npm run lint && npm run tsc— both clean.status.resources.cpuis reported in milli-cores, for example1750m, andspec.limits.cpuset to8.1.75/8and the bar sits near 22%, instead of1750/8at full.1.75 of 8instead of1750 of 8.