🌐 AI搜索 & 代理 主页
Skip to content

resource.MustParse fails to parse quantities near math.MaxInt64 #135487

@snorwin

Description

@snorwin

What happened?

When parsing very large quantity values, i.e., values close to math.MaxInt64, k8s.io/apimachinery/pkg/api/resource.MustParse is unable to correctly interpret them. Similar parsing failures also occur when these high values are used within or passed to CEL validation rules.

What did you expect to happen?

Quantities within the valid range of [-math.MaxInt64, math.MaxInt64] should be parsed correctly. Values exceeding this range should be cleanly rounded to the nearest valid boundary or causing parsing errors.

How can we reproduce it (as minimally and precisely as possible)?

q := resource.MustParse(strconv.FormatInt(math.MaxInt64, 10))
fmt.Println(q.AsInt64())

fmt.Println(resource.NewQuantity(math.MaxInt64, resource.DecimalSI).AsInt64())

Actual Output

0 false
9223372036854775807 true

The first line shows that resource.MustParse failed to parse the maximum int64 value, yielding 0 and indicating failure. The second line shows that constructing the quantity directly succeeds and returns the correct value.

Anything else we need to know?

No response

Kubernetes version

k8s.io/apimachinery v0.34.2

Cloud provider

N/A

OS version

$ cat /etc/os-release
NAME="Fedora Linux"
VERSION="43 (Workstation Edition)"
RELEASE_TYPE=stable
ID=fedora
VERSION_ID=43
VERSION_CODENAME=""
PRETTY_NAME="Fedora Linux 43 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:43"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f43/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=43
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=43
SUPPORT_END=2026-12-02
VARIANT="Workstation Edition"
VARIANT_ID=workstation

$ uname -a
Linux client-8877 6.17.7-300.fc43.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Nov  2 15:30:09 UTC 2025 x86_64 GNU/Linux

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, ...) and versions (if applicable)

Metadata

Metadata

Assignees

Labels

good first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.sig/appsCategorizes an issue or PR as relevant to SIG Apps.

Type

No type

Projects

Status

Needs Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions