quota

package
v0.0.0-...-44f477e Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProjectReference reference type for project
	ProjectReference = "project"
)

Variables

View Source
var (
	// Ctl is a global quota controller instance
	Ctl = NewController()
)

Functions

func Driver

func Driver(ctx context.Context, reference string) (driver.Driver, error)

Driver returns quota driver for the reference

func IgnoreLimitation

func IgnoreLimitation(ignoreLimitation bool) func(*Options)

IgnoreLimitation set IgnoreLimitation for the Options

func ReferenceID

func ReferenceID(i interface{}) string

ReferenceID returns reference id for the interface

func RefreshForProjects

func RefreshForProjects(ctx context.Context) error

RefreshForProjects refresh quotas of all projects

func Validate

func Validate(ctx context.Context, reference string, hardLimits types.ResourceList) error

Validate validate hard limits

func WithReferenceObject

func WithReferenceObject() func(*Options)

WithReferenceObject set WithReferenceObject to true for the Options

Types

type Controller

type Controller interface {
	// Count returns the total count of quotas according to the query.
	Count(ctx context.Context, query *q.Query) (int64, error)

	// Create ensure quota for the reference object
	Create(ctx context.Context, reference, referenceID string, hardLimits types.ResourceList, used ...types.ResourceList) (int64, error)

	// Delete delete quota by id
	Delete(ctx context.Context, id int64) error

	// Get returns quota by id
	Get(ctx context.Context, id int64, options ...Option) (*quota.Quota, error)

	// GetByRef returns quota by reference object
	GetByRef(ctx context.Context, reference, referenceID string, options ...Option) (*quota.Quota, error)

	// IsEnabled returns true when quota enabled for reference object
	IsEnabled(ctx context.Context, reference, referenceID string) (bool, error)

	// List list quotas
	List(ctx context.Context, query *q.Query, options ...Option) ([]*quota.Quota, error)

	// Refresh refresh quota for the reference object
	Refresh(ctx context.Context, reference, referenceID string, options ...Option) error

	// Request request resources to run f
	// Before run the function, it reserves the resources,
	// then runs f and refresh quota when f success,
	// in the finally it releases the resources which reserved at the beginning.
	Request(ctx context.Context, reference, referenceID string, resources types.ResourceList, f func() error) error

	// Update update quota
	Update(ctx context.Context, q *quota.Quota) error
}

Controller defines the operations related with quotas

func NewController

func NewController() Controller

NewController creates an instance of the default quota controller

type Option

type Option func(*Options)

Option option for `Refresh` method of `Controller`

type Options

type Options struct {
	IgnoreLimitation    bool
	WithReferenceObject bool
}

Options options used by `Refresh`, `Get`, `List` methods of `Controller`

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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