#7405·kubevela

[Feature] Per-namespace quota on definition usage

Author: briankaneCreated Sep 28, 2026Updated Sep 28, 2026
Labelstype/featurearea/webhookarea/chartarea/admission

Describe the feature

A definition installed in vela-system can be used by every Application in the cluster. #7388 added spec.restrictions, which says who may use one. This proposes the other half: how much they may use it.

spec.restrictions.quota would cap how many components or traits of a definition's type one namespace may contain, varying by namespace class:

yaml
spec:
  restrictions:
    quota:
      - namespaceSelector:
          matchLabels: {tier: gold}
        warn: 16
        limit: 20
      - namespaces: ["tenant-dev-*"]
        limit: 3
      - warn: 5          # no matcher: the default, and advisory only

At or above warn the Application is admitted with an admission warning. Above limit it is refused. warn on its own would never refuse, which is how a quota gets introduced before it is enforced: publish it, watch who trips it, set limit once you know. Introducing a hard limit blind is how you break a tenant you had not counted.

Why is this needed

In a multi-tenant cluster the tenant is the namespace, and there is currently no way for a platform team to bound how much of a shared definition a namespace consumes.

ResourceQuota cannot express it: count/<resource>.<group> counts objects, so it can cap how many Applications a namespace holds but not how many occurrences of components[].type sit inside them. One Application with fifty webservice components is one object.

Proposed behaviour

  • Counted: components[].type for a ComponentDefinition and components[].traits[].type for a TraitDefinition. Two components of one type count twice, and one trait on two components counts twice. A pinned webservice@v1 should count against webservice, and a component type and a trait type sharing a name should keep separate budgets.
  • Not counted: policies, workflow steps and sources. A namespace accumulates components and the traits on them, while those three are part of how a single Application is assembled, so a per-namespace cap on them would say nothing. A quota on those kinds should be refused when the definition is written rather than accepted and ignored.
  • First match wins, so ordering is the precedence rule and overlapping entries need no tie-break. An entry with no matcher takes every namespace, so it has to be last, and one placed earlier should be refused on write rather than silently shadowing the rest.
  • The system namespaces should be exempt, unconditionally. Addons install their own Applications there using these same definitions, so a quota matching one is an outage rather than a policy.
  • An opt-out for incidents. Something like annotating a Namespace definition.oam.dev/quota-exempt=true to lift every quota there until it is removed. Worth logging each use, since an annotation has no expiry and one left in place should be findable.
  • Lowering a quota under a namespace already above it has to leave it drainable. If every edit is refused while the namespace is over, the only remedy is deleting whole Applications. An edit that does not add to an Application's own use should be admitted.

Enforcement

Admission only, on create and update, which is what #7388 settled on for restrictions and for the same reason: an Application admitted before a quota existed should keep reconciling rather than break for a policy change its author did not make. It would be frozen against growth instead.

It should be honest about what it is. A count read at admission has no transaction, so two concurrent creates can each see room and both be admitted. Gatekeeper and Kyverno have the same property for count constraints. This blocks a request; it does not guarantee the ceiling, and the docs should say so.

The count runs on every Application admission, so it wants an index on Applications by the definitions they use, otherwise it walks the whole namespace each time. A definition with no quota should cost nothing: no list, and no namespace read.

Out of scope

  • A cross-type budget. "Bronze gets 10 components total, whatever the mix" cannot live on one definition, since no definition can see another's counts. Per-type limits compose into a ceiling, never a total. That needs a separate cluster-scoped object and is a different feature.
  • VelaUX. Its component dropdown would still offer a type whose quota is spent, with the refusal arriving at apply time. Separate repo.