fix(cozy-lib): render tenant hugepages quota only as requests (#5189)

## What this PR does

A tenant with `hugepages-2Mi` or `hugepages-1Gi` in `resourceQuotas`
gets both `requests.hugepages-<size>` and `limits.hugepages-<size>` in
`tenant-quota`. Kubernetes accepts huge pages in a ResourceQuota only as
`hugepages-<size>` or `requests.hugepages-<size>`
([`IsStandardQuotaResourceName`](https://github.com/kubernetes/kubernetes/blob/v1.34.1/pkg/apis/core/helper/helpers.go#L245)),
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 today a VM whose memory is backed by huge pages runs outside
the tenant quota with no way to bound it.

`cozy-lib.resources.flattenResource` now drops the limits side for
`hugepages-*`, the same way it already does for `storage`, so the quota
carries only `requests.hugepages-<size>`. Both page sizes go through the
same rule. `sanitize` is unchanged: a pod spec still needs equal
requests and limits for huge pages.

`helm unittest .` passes 69 of 69 in `packages/tests/cozy-lib-tests` and
78 of 78 in `packages/apps/tenant`. The new case fails on `main` on both
`limits.hugepages-*` keys. Admission reads hugepages usage from
`requests.*` after #5184, which matches what this renders.

### Screenshots

Not a UI change.

### Downstream repositories

Template change in `cozy-lib`, one new test case and one line in the
hand-written part of `packages/apps/tenant/README.md`. No values key,
schema or default changes. The website tenant reference page is
regenerated from that README on release, so no trigger map entry needs a
manual follow-up.

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

### Release note

```release-note
fix(cozy-lib): a tenant quota with hugepages-2Mi or hugepages-1Gi now renders only requests.hugepages-<size>, so the tenant installs and its huge pages are bounded.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Huge-page quotas now apply only to requests, avoiding unsupported
limit entries in Kubernetes resource quotas. Quota entries for 2 MiB and
1 GiB huge pages are retained as requests, while corresponding limit
entries are omitted.
* **Documentation**
* Clarified that 2 MiB and 1 GiB huge-page resources are represented as
requests in resource quotas, not limits, because Kubernetes does not
support huge-page limits quotas.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-11-16 22:05:56 +03:00
commit 060686cbc0
3 files changed
+36

No files matched your search

+1
View File
@@ -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-<size>` only, as Kubernetes has no limits quota for huge pages
**Object count quotas** (passed as-is):
- `pods` - Maximum number of pods
@@ -286,6 +286,12 @@
{{- $out := "" }}
{{- if and (eq $section "limits") (eq $type "storage") }}
{{- $out = "" }}
{{- /*
A ResourceQuota accepts hugepages only as requests.hugepages-<size>,
limits.hugepages-<size> 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) }}
@@ -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"]