Skip to content

karpenter: NodePool: Parse CPU quantities as cores - #1244

Open
RajPrakash681 wants to merge 1 commit into
headlamp-k8s:mainfrom
RajPrakash681:fix/karpenter-cpu-quantity
Open

karpenter: NodePool: Parse CPU quantities as cores#1244
RajPrakash681 wants to merge 1 commit into
headlamp-k8s:mainfrom
RajPrakash681:fix/karpenter-cpu-quantity

Conversation

@RajPrakash681

@RajPrakash681 RajPrakash681 commented Aug 25, 2026

Copy link
Copy Markdown

Summary

status.resources.cpu and spec.limits.cpu on a Karpenter NodePool are Kubernetes resource quantities, so they can carry a suffix. Both NodePool views read them with parseInt, which stops at the first non-digit: parseInt('1750m') is 1750, so 1.75 cores is displayed and charted as 1750 cores. parseInt also truncates a plain decimal, turning 1.5 cores into 1.

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: 8 and status.resources.cpu: 1750m, the list column read 1750/8 and the percentage bar pinned at full.

Memory in the same two files was already correct — it goes through parseRam(). Only CPU used parseInt.

Related Issue

Fixes #1243

Changes

  • Added karpenter/src/helpers/parseCpu.tsx, converting n, u and m quantities to cores and returning 0 for anything unparseable. It mirrors the shape of the existing parseRam helper next to it, and the conversion matches parseCpuQuantity in the kubeflow plugin.

    On why this is a local helper rather than the SDK's parseCpu from @kinvolk/headlamp-plugin/lib/lib/units: in the pinned headlamp-plugin 0.14.0 that function parses with parseInt, so parseCpu('1.5') / TO_ONE_CPU is 1 rather than 1.5, and an unparseable value yields NaN instead of 0, which would feed NaN straight into PercentageBar. Using it here would trade this bug for a smaller one. Happy to switch to the SDK function instead once a release carries the parseFloat version, if maintainers would rather wait for that.

  • Added karpenter/src/helpers/parseCpu.test.ts covering milli-cores, micro-cores, nano-cores, unsuffixed and decimal quantities, and the unparseable case.

  • NodePool/List.tsx and NodePool/Details.tsx now read CPU through parseCpu instead of parseInt.

Steps to Test

  1. cd karpenter && npm install && npm run test — the four new parseCpu cases pass.
  2. npm run lint && npm run tsc — both clean.
  3. Against a cluster running Karpenter, open Karpenter → NodePools with a NodePool whose status.resources.cpu is reported in milli-cores, for example 1750m, and spec.limits.cpu set to 8.
  4. The CPU column reads 1.75/8 and the bar sits near 22%, instead of 1750/8 at full.
  5. Open that NodePool's details page: CPU reads 1.75 of 8 instead of 1750 of 8.

Signed-off-by: RajPrakash681 <rjnt452@gmail.com>
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.

karpenter: NodePool CPU is parsed with parseInt, so milli-core quantities read 1000x too high

1 participant