quota

package
v1.41.6 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxTFlopsLimitResource   = "single.max.tflops.limit"
	MaxVRAMLimitResource     = "single.max.vram.limit"
	MaxTFlopsRequestResource = "single.max.tflops.request"
	MaxVRAMRequestResource   = "single.max.vram.request"
	MaxGPULimitResource      = "single.max.gpuCount.limit"

	TotalMaxTFlopsLimitResource   = "total.max.tflops.limit"
	TotalMaxVRAMLimitResource     = "total.max.vram.limit"
	TotalMaxTFlopsRequestResource = "total.max.tflops.request"
	TotalMaxVRAMRequestResource   = "total.max.vram.request"

	TotalMaxWorkersLimitResource = "total.max.workers.limit"
	DefaultAlertThresholdPercent = int32(95)
)
View Source
const QuotaReadyAndCapacitySufficient = "GPUResourceQuota is ready and capacity is sufficient"

Variables

This section is empty.

Functions

This section is empty.

Types

type Calculator

type Calculator struct{}

Calculator provides shared quota calculation logic

func NewCalculator

func NewCalculator() *Calculator

NewCalculator creates a new quota calculator

func (*Calculator) ApplyUsageOperation

func (c *Calculator) ApplyUsageOperation(currentUsage *tfv1.GPUResourceUsage, allocation *tfv1.AllocRequest, isIncrease bool)

ApplyUsageOperation atomically applies a usage operation (increase or decrease)

func (*Calculator) CalculateAvailablePercent

func (c *Calculator) CalculateAvailablePercent(quota *tfv1.GPUResourceQuota, usage *tfv1.GPUResourceUsage) *tfv1.GPUResourceAvailablePercent

CalculateAvailablePercent calculates available percentage for each resource

func (*Calculator) CalculateConditions added in v1.35.0

func (c *Calculator) CalculateConditions(availablePercent *tfv1.GPUResourceAvailablePercent, alertThreshold int32, previousMsg string) []metav1.Condition

CreateStandardConditions creates standard quota conditions

func (*Calculator) CreateZeroUsage

func (c *Calculator) CreateZeroUsage() *tfv1.GPUResourceUsage

CreateZeroUsage creates a zero-initialized usage object

func (*Calculator) DecreaseUsage

func (c *Calculator) DecreaseUsage(usage *tfv1.GPUResourceUsage, allocation *tfv1.AllocRequest)

DecreaseUsage safely decreases resource usage with bounds checking

func (*Calculator) IncreaseUsage

func (c *Calculator) IncreaseUsage(usage *tfv1.GPUResourceUsage, allocation *tfv1.AllocRequest)

IncreaseUsage safely increases resource usage

func (*Calculator) IsAlertThresholdReached

func (c *Calculator) IsAlertThresholdReached(availablePercent string, threshold int32) bool

IsAlertThresholdReached checks if alert threshold is reached for any resource

func (*Calculator) SafeAdd

func (c *Calculator) SafeAdd(a *resource.Quantity, b resource.Quantity, count int64)

SafeAdd safely adds quantities with nil checks

func (*Calculator) SafeSub

func (c *Calculator) SafeSub(a *resource.Quantity, b resource.Quantity, count int64)

SafeSub safely subtracts b from a, ensuring a doesn't go negative

type QuotaExceededError added in v1.35.0

type QuotaExceededError struct {
	Namespace string
	Resource  string
	Requested resource.Quantity
	Limit     resource.Quantity
}

QuotaExceededError represents a quota exceeded error with detailed information

func (*QuotaExceededError) Error added in v1.35.0

func (e *QuotaExceededError) Error() string

type QuotaStore added in v1.35.0

type QuotaStore struct {
	client.Client

	// In-memory quota store: namespace -> quota info
	QuotaStore map[string]*QuotaStoreEntry
	StoreMutex sync.RWMutex

	// Calculator for shared quota computation logic
	Calculator *Calculator
	// contains filtered or unexported fields
}

QuotaStore manages GPU resource quotas in memory for atomic operations

func NewQuotaStore added in v1.35.0

func NewQuotaStore(client client.Client, ctx context.Context) *QuotaStore

NewQuotaStore creates a new quota store

func (*QuotaStore) AdjustQuota added in v1.35.0

func (qs *QuotaStore) AdjustQuota(namespace string, reqDelta tfv1.Resource, limitDelta tfv1.Resource)

func (*QuotaStore) AllocateQuota added in v1.35.0

func (qs *QuotaStore) AllocateQuota(namespace string, req *tfv1.AllocRequest)

AllocateQuota atomically allocates quota resources This function is called under GPU allocator's storeMutex

func (*QuotaStore) CheckQuotaAvailable added in v1.35.0

func (qs *QuotaStore) CheckQuotaAvailable(namespace string, req *tfv1.AllocRequest) error

CheckQuotaAvailable is the quota checking logic Note: This method assumes proper locking is handled by the caller

func (*QuotaStore) DeallocateQuota added in v1.35.0

func (qs *QuotaStore) DeallocateQuota(namespace string, allocation *tfv1.AllocRequest)

DeallocateQuota atomically deallocate quota resources This function is called under GPU allocator's storeMutex

func (*QuotaStore) GetQuotaStatus added in v1.35.0

func (qs *QuotaStore) GetQuotaStatus(namespace string) (*tfv1.GPUResourceUsage, bool)

GetQuotaStatus returns current quota status for a namespace

func (*QuotaStore) InitQuotaStore added in v1.35.0

func (qs *QuotaStore) InitQuotaStore() error

initQuotaStore initializes the quota store from Kubernetes

func (*QuotaStore) ReconcileQuotaStore added in v1.35.0

func (qs *QuotaStore) ReconcileQuotaStore(ctx context.Context, namespacedAllocations map[string]*tfv1.AllocRequest)

ReconcileQuotaStore rebuilds quota usage from actual worker pods

func (*QuotaStore) StartInformerForGPUQuota added in v1.35.0

func (qs *QuotaStore) StartInformerForGPUQuota(ctx context.Context, mgr manager.Manager) error

func (*QuotaStore) SyncQuotasToK8s added in v1.35.0

func (qs *QuotaStore) SyncQuotasToK8s(ctx context.Context)

syncQuotasToK8s syncs dirty quotas to Kubernetes

type QuotaStoreEntry added in v1.35.0

type QuotaStoreEntry struct {
	// Original Quota definition from K8s
	Quota *tfv1.GPUResourceQuota

	// Current usage calculated in memory (authoritative)
	CurrentUsage *tfv1.GPUResourceUsage
}

QuotaStoreEntry represents quota information in memory

Jump to

Keyboard shortcuts

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