mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
fix(tenant): default only the resources the tenant quota bounds
The tenant chart rendered tenant-range-limits whenever resourceQuotas
was non-empty. Its 128Mi default memory limit then applied under a
quota on load balancers, storage or GPUs alone, or on cpu or
ephemeral-storage without memory, and refused any pod that requests
more memory without a limit of its own, virt-launcher included, so
VMs could not start in such a tenant.
The LimitRange is there so pods without requests or limits pass a
quota that tracks cpu, memory or ephemeral-storage. Default each of
those three only when the flattened quota bounds that resource, and
render no LimitRange when it bounds none of them. A quota on all
three renders the LimitRange exactly as before, with the same values.
Closes: #4930
Assisted-by: LLM
Signed-off-by: Nimesh Kulkarni <167794819+GitNimay@users.noreply.github.com>
(cherry picked from commit 6014860c93)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
1 parent
47d1a7415f
commit
3bda3f4e95
2 files changed
+210
No files matched your search
@@ -7,6 +7,17 @@ metadata:
|
||||
spec:
|
||||
hard:
|
||||
{{- include "cozy-lib.resources.flatten" (list .Values.resourceQuotas $) | nindent 6 }}
|
||||
{{- /* The LimitRange only exists so pods without requests or limits still pass
|
||||
a quota that tracks them, so it defaults only the resources the quota
|
||||
bounds. A default limit on any other resource does nothing for the quota
|
||||
and refuses every container that requests more without a limit of its
|
||||
own: a 128Mi memory default under a quota on load balancers, cpu or
|
||||
ephemeral-storage alone kept virt-launcher from starting. */}}
|
||||
{{- $hard := include "cozy-lib.resources.flatten" (list .Values.resourceQuotas $) | fromYaml }}
|
||||
{{- $cpu := or (hasKey $hard "requests.cpu") (hasKey $hard "limits.cpu") }}
|
||||
{{- $memory := or (hasKey $hard "requests.memory") (hasKey $hard "limits.memory") }}
|
||||
{{- $ephemeral := or (hasKey $hard "requests.ephemeral-storage") (hasKey $hard "limits.ephemeral-storage") }}
|
||||
{{- if or $cpu $memory $ephemeral }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: LimitRange
|
||||
@@ -16,12 +27,25 @@ metadata:
|
||||
spec:
|
||||
limits:
|
||||
- default:
|
||||
{{- if $cpu }}
|
||||
cpu: "250m"
|
||||
{{- end }}
|
||||
{{- if $memory }}
|
||||
memory: "128Mi"
|
||||
{{- end }}
|
||||
{{- if $ephemeral }}
|
||||
ephemeral-storage: "2Gi"
|
||||
{{- end }}
|
||||
defaultRequest:
|
||||
{{- if $cpu }}
|
||||
cpu: "25m"
|
||||
{{- end }}
|
||||
{{- if $memory }}
|
||||
memory: "128Mi"
|
||||
{{- end }}
|
||||
{{- if $ephemeral }}
|
||||
ephemeral-storage: "50Mi"
|
||||
{{- end }}
|
||||
type: Container
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,186 @@
|
||||
suite: tenant LimitRange defaults only what the quota bounds
|
||||
|
||||
# The LimitRange defaults requests and limits so pods without them still pass a
|
||||
# quota that tracks cpu, memory or ephemeral-storage. A default on a resource
|
||||
# the quota does not bound only gets in the way: its 128Mi memory limit refuses
|
||||
# any container that requests more without a limit of its own, virt-launcher
|
||||
# included. Each test pins the document count, so a quota that stops rendering
|
||||
# at all reddens here too.
|
||||
templates:
|
||||
- templates/quota.yaml
|
||||
|
||||
release:
|
||||
name: tenant-test
|
||||
namespace: tenant-test
|
||||
|
||||
tests:
|
||||
- it: renders nothing without resourceQuotas
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: renders no LimitRange under a quota on load balancers alone
|
||||
set:
|
||||
resourceQuotas:
|
||||
services.loadbalancers: "1"
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- isKind:
|
||||
of: ResourceQuota
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: ResourceQuota
|
||||
- equal:
|
||||
path: spec.hard["services.loadbalancers"]
|
||||
value: "1"
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: ResourceQuota
|
||||
|
||||
- it: renders no LimitRange under a quota on storage alone
|
||||
set:
|
||||
resourceQuotas:
|
||||
storage: 100Gi
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- isKind:
|
||||
of: ResourceQuota
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: ResourceQuota
|
||||
|
||||
- it: renders no LimitRange under a quota on GPUs alone
|
||||
set:
|
||||
resourceQuotas:
|
||||
nvidia.com/gpu: "2"
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- isKind:
|
||||
of: ResourceQuota
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: ResourceQuota
|
||||
|
||||
- it: keeps every default under a quota on cpu, memory and ephemeral-storage
|
||||
set:
|
||||
resourceQuotas:
|
||||
cpu: "4"
|
||||
memory: 8Gi
|
||||
ephemeral-storage: 10Gi
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 2
|
||||
- isKind:
|
||||
of: LimitRange
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
- equal:
|
||||
path: metadata.name
|
||||
value: tenant-range-limits
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
- equal:
|
||||
path: spec.limits[0].default
|
||||
value:
|
||||
cpu: 250m
|
||||
memory: 128Mi
|
||||
ephemeral-storage: 2Gi
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
- equal:
|
||||
path: spec.limits[0].defaultRequest
|
||||
value:
|
||||
cpu: 25m
|
||||
memory: 128Mi
|
||||
ephemeral-storage: 50Mi
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
|
||||
- it: defaults only cpu under a quota on cpu alone
|
||||
set:
|
||||
resourceQuotas:
|
||||
cpu: "4"
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 2
|
||||
- equal:
|
||||
path: spec.limits[0].default
|
||||
value:
|
||||
cpu: 250m
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
- equal:
|
||||
path: spec.limits[0].defaultRequest
|
||||
value:
|
||||
cpu: 25m
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
|
||||
- it: defaults only memory under a quota on memory alone
|
||||
set:
|
||||
resourceQuotas:
|
||||
memory: 8Gi
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 2
|
||||
- equal:
|
||||
path: spec.limits[0].default
|
||||
value:
|
||||
memory: 128Mi
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
- equal:
|
||||
path: spec.limits[0].defaultRequest
|
||||
value:
|
||||
memory: 128Mi
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
|
||||
- it: defaults only ephemeral-storage under a quota on ephemeral-storage alone
|
||||
set:
|
||||
resourceQuotas:
|
||||
ephemeral-storage: 10Gi
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 2
|
||||
- equal:
|
||||
path: spec.limits[0].default
|
||||
value:
|
||||
ephemeral-storage: 2Gi
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
- equal:
|
||||
path: spec.limits[0].defaultRequest
|
||||
value:
|
||||
ephemeral-storage: 50Mi
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
|
||||
- it: defaults only memory when memory sits beside non-compute quota keys
|
||||
set:
|
||||
resourceQuotas:
|
||||
services.loadbalancers: "1"
|
||||
memory: 8Gi
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 2
|
||||
- equal:
|
||||
path: spec.limits[0].default
|
||||
value:
|
||||
memory: 128Mi
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: LimitRange
|
||||
Reference in new issue
Block a user