Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resource quota quantity parser #2112

Open
petersutter opened this issue Sep 27, 2024 · 0 comments
Open

Fix resource quota quantity parser #2112

petersutter opened this issue Sep 27, 2024 · 0 comments
Labels
component/dashboard Gardener Dashboard kind/bug Bug

Comments

@petersutter
Copy link
Member

What happened:

export function parseNumberWithMagnitudeSuffix (abbreviatedNumber) {
let number = abbreviatedNumber
let suffix = ''
if (/[kmbt]$/i.test(abbreviatedNumber)) {
suffix = abbreviatedNumber.slice(-1)
number = abbreviatedNumber.slice(0, -1)
}
number = Number(number)
if (isNaN(number)) {
logger.error(`Failed to parse ${abbreviatedNumber} because it doesn't follow the required format: a number optionally with a decimal, followed by an optional magnitude suffix ('k', 'm', 'b', 't').`)
return null
}
const suffixFactors = { k: 1e3, m: 1e6, b: 1e9, t: 1e12 }
const factor = suffixFactors[suffix?.toLowerCase()] ?? 1
return number * factor
}

The parseNumberWithMagnitudeSuffix parses quantity values like 1b but such values are not allowed by the kube-apiserver. https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know:

Environment:

@petersutter petersutter added kind/bug Bug component/dashboard Gardener Dashboard labels Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/dashboard Gardener Dashboard kind/bug Bug
Projects
None yet
Development

No branches or pull requests

1 participant