From 38a32445f7ac2cf93064724fd15d868adacbf83c Mon Sep 17 00:00:00 2001 From: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:21:09 +0100 Subject: [PATCH] fix(cozy-lib): render tenant hugepages quota only as requests A tenant with hugepages-2Mi or hugepages-1Gi in resourceQuotas got both requests.hugepages- and limits.hugepages- in tenant-quota. A ResourceQuota accepts huge pages only as hugepages- or requests.hugepages-, so the apiserver rejects tenant-quota and the tenant release fails to install or upgrade. Huge pages are not counted in limits.memory either, so without this key a VM whose memory is backed by huge pages runs outside the tenant quota. The limits side is dropped for hugepages-* the same way it already is for storage. sanitize still emits equal requests and limits, which is what a pod spec needs for huge pages, so only the quota rendering changes. Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> Assisted-by: LLM --- packages/apps/tenant/README.md | 1 + .../library/cozy-lib/templates/_resources.tpl | 6 ++++ .../cozy-lib-tests/tests/quota_test.yaml | 29 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/packages/apps/tenant/README.md b/packages/apps/tenant/README.md index 5cd48995c..5b9c712f5 100644 --- a/packages/apps/tenant/README.md +++ b/packages/apps/tenant/README.md @@ -104,6 +104,7 @@ The `resourceQuotas` parameter allows you to limit resources available to the te - `memory` - Total memory (e.g., `"4Gi"` or `"512Mi"`) - `ephemeral-storage` - Ephemeral storage limit (e.g., `"10Gi"`) - `storage` - Total persistent storage (e.g., `"100Gi"`) +- `hugepages-2Mi`, `hugepages-1Gi` - Total huge pages of that size (e.g., `"4Gi"`), converted to `requests.hugepages-` only, as Kubernetes has no limits quota for huge pages **Object count quotas** (passed as-is): - `pods` - Maximum number of pods diff --git a/packages/library/cozy-lib/templates/_resources.tpl b/packages/library/cozy-lib/templates/_resources.tpl index 48b0718fd..8ec76f185 100644 --- a/packages/library/cozy-lib/templates/_resources.tpl +++ b/packages/library/cozy-lib/templates/_resources.tpl @@ -239,6 +239,12 @@ {{- $out := "" }} {{- if and (eq $section "limits") (eq $type "storage") }} {{- $out = "" }} +{{- /* + A ResourceQuota accepts hugepages only as requests.hugepages-, + limits.hugepages- is rejected and the whole quota with it. +*/}} +{{- else if and (eq $section "limits") (hasPrefix "hugepages-" $type) }} +{{- $out = "" }} {{- else if and (eq $section "limits") (has $type $rawQuotaKeys) }} {{- $out = $type }} {{- else if not (has $type $rawQuotaKeys) }} diff --git a/packages/tests/cozy-lib-tests/tests/quota_test.yaml b/packages/tests/cozy-lib-tests/tests/quota_test.yaml index 0ba2260c4..0604ca5ee 100644 --- a/packages/tests/cozy-lib-tests/tests/quota_test.yaml +++ b/packages/tests/cozy-lib-tests/tests/quota_test.yaml @@ -48,3 +48,32 @@ tests: - notExists: path: spec.hard["requests.services.loadbalancers"] + + - it: renders hugepages only as requests + set: + quota: + hugepages-2Mi: "4Gi" + hugepages-1Gi: "2Gi" + _cluster: {} + _namespace: {} + + release: + name: myrelease + namespace: default + revision: 1 + isUpgrade: false + + asserts: + - equal: + path: spec.hard["requests.hugepages-2Mi"] + value: "4Gi" + + - equal: + path: spec.hard["requests.hugepages-1Gi"] + value: "2Gi" + + - notExists: + path: spec.hard["limits.hugepages-2Mi"] + + - notExists: + path: spec.hard["limits.hugepages-1Gi"]