quota

package
v0.0.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const NoopName = "noop"

Variables

This section is empty.

Functions

func Register

func Register(name string, f Factory)

Register adds a Factory under the given name. Panics on duplicate — see pkg/plugins.Register for the rationale.

Types

type Factory

type Factory func(h framework.Handle, args framework.Args) (Provider, error)

Factory constructs a quota Provider from shared runtime dependencies and provider-specific parameters. Passing nil args is legal for Providers that take no parameters (e.g. Noop).

func Get

func Get(name string) (Factory, error)

Get looks up a registered Factory.

type Info added in v0.0.5

type Info struct {
	// Quota is the wire-shape projection of this quota, returned to API
	// callers verbatim. Implementations are responsible for populating Id
	// and Name (Id MUST be stable across provider restarts; Name is the
	// human-readable form for the dashboard).
	Quota gen.Quota

	// Labels mirrors the source object's labels. Optional; nil when the
	// underlying backend has no notion of labels.
	Labels map[string]string

	// Annotations mirrors the source object's annotations. Optional.
	Annotations map[string]string
}

Info is the internal, provider-side view of a quota. It carries the public wire shape together with backend-only metadata (labels/annotations from the underlying CRD or external system) that must not leak to API callers.

The service layer serializes only Info.Quota over the wire; Labels and Annotations stay inside the binary so that internal consumers (the reservation plugin, controllers, etc.) can read provider-specific hints (queue name, parent pool id, scheduler URL, ...) without baking those hints into the public schema.

type Noop

type Noop struct{}

Noop is a Provider that reports the quota feature as disabled. It is the default for open-source builds where no quota backend is configured.

func (Noop) DeriveShortName added in v0.0.5

func (Noop) DeriveShortName(_ string) string

DeriveShortName has no usable default extractor in the open-source build — QuotaURL shapes are operator-defined and only the concrete Provider knows how to map them to a short identifier. Returning "" tells the caller to fall back to a deterministic hash-based suffix when naming member pools.

func (Noop) Enabled

func (Noop) Enabled() bool

func (Noop) ListForUser

func (Noop) ListForUser(_ context.Context, _, _ string) ([]Info, *domain.AppError)

type Provider

type Provider interface {
	// Enabled reports whether the provider can answer queries. False means
	// the quota feature is unavailable (no backend configured, CRD missing,
	// etc.) — callers should skip quota checks gracefully.
	Enabled() bool

	// ListForUser returns all quotas visible to the (user, team) pair.
	// Returns (nil, nil) when the provider is disabled or the user has no
	// visible quotas; returns an AppError only on transient/system failures.
	//
	// Each Info.Quota is the wire-shape value forwarded to API callers;
	// Info.Labels / Info.Annotations carry provider-internal metadata that
	// MUST NOT be serialized — they exist solely for in-process consumers
	// (reservation plugins, scheduler integration, etc.) that need to
	// derive backend-specific hints like queue names or scheduler IDs.
	ListForUser(ctx context.Context, user, team string) ([]Info, *domain.AppError)

	// DeriveShortName returns a stable human-readable short identifier for
	// a quota ID, used by the SandboxEnv Reconciler when naming member
	// SandboxPools that consume the quota (e.g. "{env-name}-{shortName}").
	//
	// Quota ID shapes are Provider-defined, so the parsing rule lives with
	// the concrete Provider — the open-source Noop returns "" and the
	// caller falls back to a deterministic hash-based suffix so naming
	// stays idempotent. Closed-source Providers can override this with a
	// catalog lookup or a tenant-specific path parser.
	DeriveShortName(quotaID string) string
}

Provider exposes read-only access to quota information.

A nil Provider is not valid; callers should always hold at least a Noop. Use Enabled() to decide whether to expose quota-related UI.

func Build

func Build(name string, h framework.Handle, args framework.Args) (Provider, error)

Build looks up a Factory by name and invokes it.

func NewNoop

func NewNoop() Provider

NewNoop returns a disabled quota Provider. Safe to share.

func NoopFactory

func NoopFactory(_ framework.Handle, _ framework.Args) (Provider, error)

NoopFactory is the Factory form of NewNoop — no Handle or Args are used. Registered at package init() so callers can Build("noop", h, nil) without any extra wiring.

Jump to

Keyboard shortcuts

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