mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
## What this PR does Since tenant quotas became hierarchical (#3086), an unbounded sub-tenant (no `resourceQuotas` of its own) shares its parent's pool and receives a controller-owned `tenant-quota-allocated` ResourceQuota. The tenant chart, however, renders the `tenant-range-limits` LimitRange only next to the `tenant-quota` of a tenant that declares `resourceQuotas`, so these namespaces end up with a quota on `limits.cpu`/`limits.memory` and no container defaults. Admission then rejects every container that omits one of those limits. Pods that predate the quota keep running and fail as soon as they are recreated. In production this took down CNPG postgres instances with backups enabled: the `plugin-barman-cloud` sidecar injected by the barman-cloud plugin sets CPU and memory requests and a memory limit but no CPU limit, so the instance pod is refused on its next restart. The same happened to the tenant `kubernetes` app: the `wait-for-kubeconfig` init container of `cluster-autoscaler`, `kcsi-controller` and the `bootstrap-token` jobs has no resources, so their ReplicaSets and Jobs were refused with `failed quota: tenant-quota-allocated: must specify limits.cpu` in every unbounded sub-tenant hosting a tenant cluster. On a production cluster, 131 tenant pods currently get their CPU or memory from the tenant LimitRange (VictoriaMetrics `config-init`/`config-reloader`, Harbor exporter, MariaDB agent, Strimzi entity operator, among others), so the defect is not specific to one chart: any of them breaks once it lands in such a namespace. Workloads that set every limit explicitly are unaffected. The controller already decides which namespaces it clamps, so it now copies the pool root's chart LimitRange into each unbounded member whose allocated quota bounds `limits.cpu` or `limits.memory` as `tenant-range-limits-allocated`, keeps it in step with the root, and deletes it once the namespace leaves the pool (for instance when the sub-tenant declares its own quota and the chart renders its own LimitRange). The chart renders its LimitRange under any non-empty `resourceQuotas`, including one that bounds no compute (#4930), so the copy is limited to members whose quota bounds a compute limit: elsewhere it would impose a 128Mi default memory limit the quota never asked for and refuse pods, virt-launcher among them, that are admitted today. This keeps the change independent of #4954. The copy has its own name so that Helm can still create the chart-owned object in that case without an ownership conflict. The root is the single source of truth for the defaults, so the values stay defined in `packages/apps/tenant/templates/quota.yaml` only. The controller gains `limitranges` RBAC and watches the two LimitRange names so a change propagates without waiting for the 60 s resync. Tests: five reconciler cases cover a member under a non-compute quota (no copy, and a stale one removed), the copy into an unbounded member (and not into the root), propagation of a change on the root, garbage collection once the member is bounded (the chart-owned object is left alone), and a root without a LimitRange. Disabling the copy makes the first two fail. ### Screenshots Not a UI change. ### Downstream repositories Walked the trigger map against the diff. The code touches only `internal/controller/tenantquota/` and the `cozystack-controller` RBAC template, but the website's `system-memory-limits.md` states that tenant namespaces get defaults only from the chart's `tenant-range-limits`, which this change makes untrue; the follow-up is an issue, since the page should change once this is merged. - [ ] No downstream repository is affected by this change - [x] [cozystack/website](https://github.com/cozystack/website) - follow-up: cozystack/website#806 - [ ] [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(controller, platform): sub-tenants without their own resourceQuotas now receive their parent pool's container defaults (LimitRange) alongside the allocated quota, when that quota bounds a CPU or memory limit, so pods that omit such a limit, such as the postgres barman-cloud backup sidecar, are no longer rejected at admission. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Unbounded pool members now receive their pool’s CPU and memory limit settings when their allocated quota sets those limits. Pool setting updates are reflected in members during reconciliation. * When a member has its own quota, inherited limit settings are removed while settings configured directly for that member remain unchanged. * No inherited settings are created when the pool has no limit settings or the allocated quota does not set CPU or memory limits. * Existing inherited settings are retained if an update temporarily fails. <!-- end of auto-generated comment: release notes by coderabbit.ai -->