Skip to content

Commit e01b449

Browse files
kvapsclaude
andcommitted
feat(tenants): add dedicatedCPU quota sugar for pinned-CPU workloads
Introduce an optional `dedicatedCPU` key in the cozy-lib resource sanitizer (and therefore in tenant `resourceQuotas`). Its value is added 1:1 to both `limits.cpu` and `requests.cpu`, bypassing the `cpuAllocationRatio` divisor. This fixes the quota mismatch between regular VMs (where KubeVirt divides pod `requests.cpu` by `cpuAllocationRatio`) and instance types with `dedicatedCPUPlacement` (where pod `requests == limits`): previously, a single dedicated-CPU VM could exhaust the tenant's `requests.cpu` quota while the `limits.cpu` quota stayed largely unused, effectively shrinking the usable tenant capacity for CX-series workloads to `cpu / cpuAllocationRatio`. With the new key, operators can declare dedicated capacity explicitly: resourceQuotas: cpu: 10 # oversubscribable (burstable) CPU budget dedicatedCPU: 2 # plus 2 cores of dedicated physical CPU This yields `limits.cpu=12, requests.cpu=3` at the default ratio of 10, so both sides of the ResourceQuota stay in lockstep regardless of which instance-type series a workload uses. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
1 parent fb67f2d commit e01b449

5 files changed

Lines changed: 99 additions & 1 deletion

File tree

‎packages/apps/tenant/README.md‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ tenant-u1
9292
The `resourceQuotas` parameter allows you to limit resources available to the tenant. Supported keys include:
9393

9494
**Compute resources** (converted to `requests.X` and `limits.X`):
95-
- `cpu` - Total CPU cores (e.g., `"4"` or `"500m"`)
95+
- `cpu` - Total CPU cores (e.g., `"4"` or `"500m"`). `requests.cpu` is derived
96+
as `cpu / cpuAllocationRatio` (default ratio is 10), matching KubeVirt's
97+
behavior for regular VMs and burstable containers.
98+
- `dedicatedCPU` - Additional CPU cores reserved for workloads that pin
99+
physical cores and cannot be oversubscribed (KubeVirt instance types with
100+
`dedicatedCPUPlacement`, pods with `Guaranteed` QoS). The value is added to
101+
both `limits.cpu` and `requests.cpu` at a 1:1 ratio, so that one dedicated
102+
core consumes one full unit of `requests.cpu` quota. Can be combined with
103+
`cpu`.
96104
- `memory` - Total memory (e.g., `"4Gi"` or `"512Mi"`)
97105
- `ephemeral-storage` - Ephemeral storage limit (e.g., `"10Gi"`)
98106
- `storage` - Total persistent storage (e.g., `"100Gi"`)
@@ -115,3 +123,17 @@ resourceQuotas:
115123
services.loadbalancers: "3"
116124
pods: "50"
117125
```
126+
127+
**Example with dedicated CPU** (for tenants that run VMs from the `cx*`
128+
instance-type series or other `dedicatedCPUPlacement` workloads):
129+
130+
```yaml
131+
resourceQuotas:
132+
cpu: 10 # 10 cores of oversubscribable (burstable) CPU budget
133+
dedicatedCPU: 2 # plus 2 cores of dedicated physical CPU
134+
memory: 16Gi
135+
```
136+
137+
With the default `cpuAllocationRatio=10` this produces a `ResourceQuota` of
138+
`limits.cpu=12`, `requests.cpu=3` — enough for either 12 cores of regular VMs
139+
(plus burst headroom) or 3 cores of dedicated VMs, or any mix in between.

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
6868
{{ include "cozy-lib.resources.sanitize" list (.Values.resources $) }}
6969
70+
The optional **dedicatedCPU** key is sugar for workloads with
71+
`dedicatedCPUPlacement` (KubeVirt CX-series, Guaranteed-QoS pods). Its value
72+
is added to **both** `limits.cpu` and `requests.cpu` at a 1:1 ratio (the
73+
CPU-allocation ratio does not apply), reflecting that such workloads pin
74+
physical cores and cannot be oversubscribed.
75+
7076
Example input:
7177
==============
7278
cpu: "2"
@@ -83,6 +89,18 @@
8389
cpu: 200m # 2 / 10
8490
memory: 256Mi # = limit
8591
devices.com/nvidia: "1" # = limit
92+
93+
Example input with dedicatedCPU:
94+
================================
95+
cpu: "10"
96+
dedicatedCPU: "2"
97+
98+
Example output (cpuAllocationRatio = 10):
99+
=========================================
100+
limits:
101+
cpu: "12" # 10 + 2
102+
requests:
103+
cpu: "3" # 10/10 + 2
86104
*/}}
87105
{{- define "cozy-lib.resources.sanitize" }}
88106
{{- $cpuAllocationRatio := include "cozy-lib.resources.cpuAllocationRatio" . | float64 }}
@@ -99,6 +117,8 @@
99117
{{- $cpuRequestF64 := divf $vcpuRequestF64 $cpuAllocationRatio }}
100118
{{- $_ := set $output.requests $k ($cpuRequestF64 | toString) }}
101119
{{- $_ := set $output.limits $k ($v | toString) }}
120+
{{- else if eq $k "dedicatedCPU" }}
121+
{{- /* merged into cpu after the loop */}}
102122
{{- else if eq $k "memory" }}
103123
{{- $vMemoryRequestF64 := (include "cozy-lib.resources.toFloat" $v) | float64 }}
104124
{{- $memoryRequestF64 := divf $vMemoryRequestF64 $memoryAllocationRatio }}
@@ -114,6 +134,13 @@
114134
{{- $_ := set $output.limits $k $v }}
115135
{{- end }}
116136
{{- end }}
137+
{{- if hasKey $args "dedicatedCPU" }}
138+
{{- $dedicatedF := (include "cozy-lib.resources.toFloat" (index $args "dedicatedCPU")) | float64 }}
139+
{{- $curLimitF := (include "cozy-lib.resources.toFloat" (dig "cpu" "0" $output.limits)) | float64 }}
140+
{{- $curRequestF := (include "cozy-lib.resources.toFloat" (dig "cpu" "0" $output.requests)) | float64 }}
141+
{{- $_ := set $output.limits "cpu" (addf $curLimitF $dedicatedF | toString) }}
142+
{{- $_ := set $output.requests "cpu" (addf $curRequestF $dedicatedF | toString) }}
143+
{{- end }}
117144
{{- $output | toYaml }}
118145
{{- end }}
119146

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

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

4949
- notExists:
5050
path: spec.hard["requests.services.loadbalancers"]
51+
52+
- it: dedicatedCPU alone produces 1:1 cpu quota
53+
values:
54+
- quota_values_dedicated.yaml
55+
56+
release:
57+
name: myrelease
58+
namespace: default
59+
revision: 1
60+
isUpgrade: false
61+
62+
asserts:
63+
- equal:
64+
path: spec.hard["limits.cpu"]
65+
value: "2"
66+
67+
- equal:
68+
path: spec.hard["requests.cpu"]
69+
value: "2"
70+
71+
- it: cpu and dedicatedCPU are summed with correct ratios
72+
values:
73+
- quota_values_combined.yaml
74+
75+
release:
76+
name: myrelease
77+
namespace: default
78+
revision: 1
79+
isUpgrade: false
80+
81+
asserts:
82+
- equal:
83+
path: spec.hard["limits.cpu"]
84+
value: "12"
85+
86+
- equal:
87+
path: spec.hard["requests.cpu"]
88+
value: "3"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
quota:
2+
cpu: "10"
3+
dedicatedCPU: "2"
4+
5+
_cluster: {}
6+
_namespace: {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
quota:
2+
dedicatedCPU: "2"
3+
4+
_cluster: {}
5+
_namespace: {}

0 commit comments

Comments
 (0)