quota

package
v0.2.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package quota implements the quota checks pinned by decisions O-5 (Org quota = soft cap, admin-overridable per User; default 10) and O-6 (Workspace quota = soft cap, admin-overridable per Org; default 50) in docs/organizations.md. The package is library-only: it exposes constants, helpers, and a Counter interface so REST handlers (roadmap step 10) and any future controller-side admission can run the same check.

Quota counting deliberately ignores Organizations created by the hub's personal-Org bootstrap (spec.personal=true). Those are auto-provisioned per User and shouldn't burn the user's admin-overridable cap.

Index

Constants

View Source
const (
	// DefaultOrgsPerUser is the platform-wide soft cap on the number
	// of Organizations a single User may create. Per O-5; overridable
	// per User via User.spec.orgQuota (0 means use this default).
	DefaultOrgsPerUser int32 = 10

	// DefaultWorkspacesPerOrg is the platform-wide soft cap on the
	// number of child Workspaces an Organization may hold. Per O-6;
	// overridable per Org via Organization.spec.workspaceQuota (0
	// means use this default).
	DefaultWorkspacesPerOrg int32 = 50

	// LabelCreatedBy records which User CR created a given Organization.
	// Set at create time by the hub's Org-create endpoint (roadmap step 10)
	// and by the personal-Org bootstrap controller (roadmap step 1+). Used
	// here to count Orgs against the user's quota.
	LabelCreatedBy = tenancyv1alpha1.OrganizationCreatorLabel
)

Variables

This section is empty.

Functions

func CheckOrgQuota

func CheckOrgQuota(ctx context.Context, user *tenancyv1alpha1.User, counter Counter) error

CheckOrgQuota verifies the User has not reached their Org-creation cap. It calls counter.Count(ctx) to read current usage, then compares against EffectiveOrgsPerUser(user).

  • Returns nil when usage < cap.
  • Returns a *QuotaExceededError when usage >= cap.
  • Returns the Counter's error verbatim on count failure.

Personal Organizations created by the bootstrap controller are expected to be excluded by the Counter implementation (the Counter caller filters by spec.personal=false). The package does not enforce that filter on its own to keep the abstraction tight; the "Organizations counted exclude spec.personal=true" rule is part of the Counter contract.

func CheckWorkspaceQuota

func CheckWorkspaceQuota(ctx context.Context, org *tenancyv1alpha1.Organization, counter Counter) error

CheckWorkspaceQuota verifies the Organization has not reached its Workspace-creation cap. Same contract as CheckOrgQuota.

func EffectiveOrgsPerUser

func EffectiveOrgsPerUser(user *tenancyv1alpha1.User) int32

EffectiveOrgsPerUser returns the effective Org quota for the given User. spec.orgQuota of 0 (the zero value) defers to the platform default; a non-zero value overrides it.

func EffectiveWorkspacesPerOrg

func EffectiveWorkspacesPerOrg(org *tenancyv1alpha1.Organization) int32

EffectiveWorkspacesPerOrg returns the effective Workspace quota for the given Organization. spec.workspaceQuota of 0 defers to the platform default; a non-zero value overrides it.

Types

type Counter

type Counter interface {
	Count(ctx context.Context) (int32, error)
}

Counter is the minimal interface the quota checks consume. The caller supplies a Counter whose Count method returns the current usage; the quota check compares against the cap and returns QuotaExceededError when usage >= cap.

Pulling the count behind an interface keeps the package dependency-free of the railgrid / kcp clientsets so the helpers can be unit-tested with a literal fakeCounter (see quota_test.go) and the production wiring picks the appropriate listing strategy at the call site.

type CounterFunc

type CounterFunc func(ctx context.Context) (int32, error)

CounterFunc adapts a function to the Counter interface.

func (CounterFunc) Count

func (f CounterFunc) Count(ctx context.Context) (int32, error)

Count implements Counter.

type QuotaExceededError

type QuotaExceededError struct {
	Kind  string
	Owner string
	Count int32
	Cap   int32
}

QuotaExceededError is returned by the Check* helpers when the supplied Counter reports usage at or above the effective cap. Carries structured fields so REST handlers (roadmap step 10) can map it to a 409 Conflict (or 4xx of choice) with a machine-readable hint.

The kind field describes what is being capped ("Organization" or "Workspace"). Owner identifies the parent (User name for Org quota; Organization UUID for Workspace quota).

func (*QuotaExceededError) Error

func (e *QuotaExceededError) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL