mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
fix(controller, platform): copy the LimitRange only under a compute-limit quota
The tenant chart renders tenant-range-limits under any non-empty resourceQuotas, including one that bounds no compute, such as services.loadbalancers alone. Copying it into an unbounded member whose allocated quota bounds neither limits.cpu nor limits.memory imposes a 128Mi default memory limit the quota never asked for: a container that requests more and sets no limit, virt-launcher among them, is refused where it was admitted before. Only a quota on limits.cpu or limits.memory makes admission reject a container that omits a limit, so the copy is now limited to that case, and removed otherwise. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
This commit is contained in:
2 files changed
+48
-3
No files matched your search
@@ -113,8 +113,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result
|
||||
pools := ComputePools(tenants)
|
||||
|
||||
desired := map[string]corev1.ResourceList{}
|
||||
// limitRangeSource maps each unbounded pool member to the pool root whose
|
||||
// chart LimitRange it must inherit.
|
||||
// limitRangeSource maps each unbounded pool member whose quota bounds a
|
||||
// compute limit to the pool root whose chart LimitRange it must inherit.
|
||||
limitRangeSource := map[string]string{}
|
||||
for _, p := range pools {
|
||||
if over := p.Overcommitted(); len(over) > 0 {
|
||||
@@ -134,7 +134,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result
|
||||
for _, ns := range p.Members {
|
||||
if existing[ns] {
|
||||
desired[ns] = buffered.EnforcedHard(ns, usedByNS)
|
||||
if ns != p.Root {
|
||||
if ns != p.Root && boundsComputeLimits(desired[ns]) {
|
||||
limitRangeSource[ns] = p.Root
|
||||
}
|
||||
}
|
||||
@@ -352,6 +352,18 @@ func ownedNamespace(hrNamespace, appName string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// boundsComputeLimits reports whether a quota bounds limits.cpu or
|
||||
// limits.memory, the only case in which admission rejects a container that
|
||||
// omits a limit. The chart renders its LimitRange under any non-empty
|
||||
// resourceQuotas, so the root may carry one under a quota that bounds no
|
||||
// compute at all; copying it then would impose default limits the quota
|
||||
// never asked for.
|
||||
func boundsComputeLimits(hard corev1.ResourceList) bool {
|
||||
_, cpu := hard[corev1.ResourceLimitsCPU]
|
||||
_, memory := hard[corev1.ResourceLimitsMemory]
|
||||
return cpu || memory
|
||||
}
|
||||
|
||||
// maxResourceList returns the per-resource maximum of a and b.
|
||||
func maxResourceList(a, b corev1.ResourceList) corev1.ResourceList {
|
||||
out := corev1.ResourceList{}
|
||||
|
||||
@@ -363,3 +363,36 @@ func TestReconcile_PoolRootWithoutLimitRange(t *testing.T) {
|
||||
t.Fatalf("no LimitRange can be copied from a root that has none")
|
||||
}
|
||||
}
|
||||
|
||||
// TestReconcile_NoLimitRangeWithoutComputeLimitQuota: the chart renders its
|
||||
// LimitRange for any non-empty resourceQuotas, compute or not. A member whose
|
||||
// allocated quota bounds neither limits.cpu nor limits.memory is admitted
|
||||
// without limits today; copying the root's defaults there would cap or refuse
|
||||
// pods (one requesting more than the default memory limit, for instance)
|
||||
// that the quota itself never constrains.
|
||||
func TestReconcile_NoLimitRangeWithoutComputeLimitQuota(t *testing.T) {
|
||||
stale := &corev1.LimitRange{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: allocatedLimitRangeName,
|
||||
Namespace: "tenant-foo-bar",
|
||||
Labels: map[string]string{managedByLabel: managedByValue},
|
||||
},
|
||||
}
|
||||
r, c := newReconciler(t,
|
||||
tenantHR("foo", "tenant-root"),
|
||||
tenantHR("bar", "tenant-foo"),
|
||||
ns("tenant-foo"), ns("tenant-foo-bar"),
|
||||
chartQuota("tenant-foo", map[string]string{"services.loadbalancers": "1"}, nil),
|
||||
chartLimitRange("tenant-foo", "250m"),
|
||||
stale,
|
||||
)
|
||||
if _, err := r.Reconcile(context.Background(), sweepKey); err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if _, ok := allocatedHard(t, c, "tenant-foo-bar", "services.loadbalancers"); !ok {
|
||||
t.Fatalf("tenant-foo-bar must still get its allocated quota")
|
||||
}
|
||||
if _, ok := getLimitRange(c, "tenant-foo-bar", allocatedLimitRangeName); ok {
|
||||
t.Fatalf("tenant-foo-bar's quota bounds no compute limit; it must carry no LimitRange copy")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user