Skip to content

Commit 38a3244

Browse files
committed
fix(cozy-lib): render tenant hugepages quota only as requests
A tenant with hugepages-2Mi or hugepages-1Gi in resourceQuotas got both requests.hugepages-<size> and limits.hugepages-<size> in tenant-quota. A ResourceQuota accepts huge pages only as hugepages-<size> or requests.hugepages-<size>, 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 <[email protected]> Assisted-by: LLM
1 parent 4087218 commit 38a3244

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎packages/apps/tenant/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ The `resourceQuotas` parameter allows you to limit resources available to the te
104104
- `memory` - Total memory (e.g., `"4Gi"` or `"512Mi"`)
105105
- `ephemeral-storage` - Ephemeral storage limit (e.g., `"10Gi"`)
106106
- `storage` - Total persistent storage (e.g., `"100Gi"`)
107+
- `hugepages-2Mi`, `hugepages-1Gi` - Total huge pages of that size (e.g., `"4Gi"`), converted to `requests.hugepages-<size>` only, as Kubernetes has no limits quota for huge pages
107108

108109
**Object count quotas** (passed as-is):
109110
- `pods` - Maximum number of pods

‎packages/library/cozy-lib/templates/_resources.tpl‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@
239239
{{- $out := "" }}
240240
{{- if and (eq $section "limits") (eq $type "storage") }}
241241
{{- $out = "" }}
242+
{{- /*
243+
A ResourceQuota accepts hugepages only as requests.hugepages-<size>,
244+
limits.hugepages-<size> is rejected and the whole quota with it.
245+
*/}}
246+
{{- else if and (eq $section "limits") (hasPrefix "hugepages-" $type) }}
247+
{{- $out = "" }}
242248
{{- else if and (eq $section "limits") (has $type $rawQuotaKeys) }}
243249
{{- $out = $type }}
244250
{{- else if not (has $type $rawQuotaKeys) }}

‎packages/tests/cozy-lib-tests/tests/quota_test.yaml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,32 @@ tests:
4848

4949
- notExists:
5050
path: spec.hard["requests.services.loadbalancers"]
51+
52+
- it: renders hugepages only as requests
53+
set:
54+
quota:
55+
hugepages-2Mi: "4Gi"
56+
hugepages-1Gi: "2Gi"
57+
_cluster: {}
58+
_namespace: {}
59+
60+
release:
61+
name: myrelease
62+
namespace: default
63+
revision: 1
64+
isUpgrade: false
65+
66+
asserts:
67+
- equal:
68+
path: spec.hard["requests.hugepages-2Mi"]
69+
value: "4Gi"
70+
71+
- equal:
72+
path: spec.hard["requests.hugepages-1Gi"]
73+
value: "2Gi"
74+
75+
- notExists:
76+
path: spec.hard["limits.hugepages-2Mi"]
77+
78+
- notExists:
79+
path: spec.hard["limits.hugepages-1Gi"]

0 commit comments

Comments
 (0)