quota

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package quota holds the pure limit arithmetic for team and project resource quotas. It never touches storage, so enforcement stays testable.

Index

Constants

View Source
const (
	ScopeTeam    = "team"
	ScopeProject = "project"
)

Scope names the kind of owner a quota applies to.

View Source
const (
	ResourceApps      = "apps"
	ResourceDatabases = "databases"
	ResourceMemory    = "memory"
	ResourceCPU       = "cpu"
	ResourcePreviews  = "previews"
)

Resource names one limited dimension.

Variables

Resources lists every dimension in display order.

Functions

func Percent

func Percent(used, limit int64) int

Percent returns used as a whole percentage of limit, or -1 when unlimited.

Types

type Amounts

type Amounts struct {
	Apps        int64
	Databases   int64
	MemoryBytes int64
	NanoCPUs    int64
	Previews    int64
}

Amounts holds one number per dimension. For limits, 0 means unlimited. Memory is in bytes and CPU in nano-CPUs, the units services already store.

func Merge

func Merge(explicit, defaults Amounts) Amounts

Merge returns explicit limits with any unset (zero) dimension filled from defaults, so env-driven defaults apply wherever nobody chose a value.

func (Amounts) Get

func (a Amounts) Get(resource string) int64

Get returns the amount for a named dimension.

func (Amounts) Unlimited

func (a Amounts) Unlimited() bool

Unlimited reports whether no dimension is capped.

type Violation

type Violation struct {
	Resource  string
	Limit     int64
	Used      int64
	Requested int64
}

Violation is one dimension that a request would push past its limit.

func Check

func Check(limits, used, requested Amounts) []Violation

Check returns every dimension where used+requested exceeds a nonzero limit. Landing exactly on the limit is allowed. A request of zero never violates, so shrinking a resource that is already over limit still works.

Jump to

Keyboard shortcuts

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