cache

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCohortNotFound = errors.New("cohort not found")
	ErrCohortHasCycle = errors.New("cohort has a cycle")
	ErrCqNotFound     = errors.New("cluster queue not found")
)

Functions

This section is empty.

Types

type AdmissionCheck added in v0.5.0

type AdmissionCheck struct {
	Active                       bool
	Controller                   string
	SingleInstanceInClusterQueue bool
	FlavorIndependent            bool
}

type Cache

type Cache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Cache keeps track of the Workloads that got admitted through ClusterQueues.

func New

func New(client client.Client, opts ...Option) *Cache

func (*Cache) ActiveClusterQueues added in v0.9.0

func (c *Cache) ActiveClusterQueues() sets.Set[kueue.ClusterQueueReference]

func (*Cache) AddClusterQueue

func (c *Cache) AddClusterQueue(ctx context.Context, cq *kueue.ClusterQueue) error

func (*Cache) AddLocalQueue added in v0.2.0

func (c *Cache) AddLocalQueue(q *kueue.LocalQueue) error

func (*Cache) AddOrUpdateAdmissionCheck added in v0.5.0

func (c *Cache) AddOrUpdateAdmissionCheck(ac *kueue.AdmissionCheck) sets.Set[kueue.ClusterQueueReference]

func (*Cache) AddOrUpdateCohort added in v0.9.0

func (c *Cache) AddOrUpdateCohort(apiCohort *kueuealpha.Cohort) error

func (*Cache) AddOrUpdateResourceFlavor

func (c *Cache) AddOrUpdateResourceFlavor(rf *kueue.ResourceFlavor) sets.Set[kueue.ClusterQueueReference]

func (*Cache) AddOrUpdateTopologyForFlavor added in v0.9.2

func (c *Cache) AddOrUpdateTopologyForFlavor(topology *kueuealpha.Topology, flv *kueue.ResourceFlavor) sets.Set[kueue.ClusterQueueReference]

func (*Cache) AddOrUpdateWorkload

func (c *Cache) AddOrUpdateWorkload(w *kueue.Workload) bool

func (*Cache) AdmissionChecksForClusterQueue added in v0.7.0

func (c *Cache) AdmissionChecksForClusterQueue(cqName kueue.ClusterQueueReference) []AdmissionCheck

func (*Cache) AssumeWorkload

func (c *Cache) AssumeWorkload(w *kueue.Workload) error

func (*Cache) CleanUpOnContext added in v0.3.0

func (c *Cache) CleanUpOnContext(ctx context.Context)

CleanUpOnContext tracks the context. When closed, it wakes routines waiting on the podsReady condition. It should be called before doing any calls to cache.WaitForPodsReady.

func (*Cache) ClusterQueueActive added in v0.2.0

func (c *Cache) ClusterQueueActive(name kueue.ClusterQueueReference) bool

func (*Cache) ClusterQueueAncestors added in v0.11.0

func (c *Cache) ClusterQueueAncestors(cqObj *kueue.ClusterQueue) ([]kueue.CohortReference, error)

ClusterQueueAncestors returns all ancestors (Cohorts), excluding the root, for a given ClusterQueue. If the ClusterQueue contains a Cohort cycle, it returns ErrCohortHasCycle.

func (*Cache) ClusterQueueEmpty added in v0.2.0

func (c *Cache) ClusterQueueEmpty(name kueue.ClusterQueueReference) bool

ClusterQueueEmpty indicates whether there's any active workload admitted by the provided clusterQueue. Return true if the clusterQueue doesn't exist.

func (*Cache) ClusterQueueReadiness added in v0.5.0

func (c *Cache) ClusterQueueReadiness(name kueue.ClusterQueueReference) (metav1.ConditionStatus, string, string)

func (*Cache) ClusterQueueTerminating added in v0.2.0

func (c *Cache) ClusterQueueTerminating(name kueue.ClusterQueueReference) bool

func (*Cache) ClusterQueuesUsingAdmissionCheck added in v0.5.0

func (c *Cache) ClusterQueuesUsingAdmissionCheck(ac string) []kueue.ClusterQueueReference

func (*Cache) ClusterQueuesUsingFlavor added in v0.3.0

func (c *Cache) ClusterQueuesUsingFlavor(flavor kueue.ResourceFlavorReference) []kueue.ClusterQueueReference

func (*Cache) ClusterQueuesUsingTopology added in v0.9.2

func (c *Cache) ClusterQueuesUsingTopology(tName kueue.TopologyReference) []kueue.ClusterQueueReference

func (*Cache) CohortStats added in v0.11.0

func (c *Cache) CohortStats(cohortObj *kueuealpha.Cohort) (*CohortUsageStats, error)

func (*Cache) DeleteAdmissionCheck added in v0.5.0

func (c *Cache) DeleteAdmissionCheck(ac *kueue.AdmissionCheck) sets.Set[kueue.ClusterQueueReference]

func (*Cache) DeleteClusterQueue

func (c *Cache) DeleteClusterQueue(cq *kueue.ClusterQueue)

func (*Cache) DeleteCohort added in v0.9.0

func (c *Cache) DeleteCohort(cohortName kueue.CohortReference)

func (*Cache) DeleteLocalQueue added in v0.2.0

func (c *Cache) DeleteLocalQueue(q *kueue.LocalQueue)

func (*Cache) DeleteResourceFlavor

func (c *Cache) DeleteResourceFlavor(rf *kueue.ResourceFlavor) sets.Set[kueue.ClusterQueueReference]

func (*Cache) DeleteTopologyForFlavor added in v0.9.2

func (c *Cache) DeleteTopologyForFlavor(flv kueue.ResourceFlavorReference) sets.Set[kueue.ClusterQueueReference]

func (*Cache) DeleteWorkload

func (c *Cache) DeleteWorkload(w *kueue.Workload) error

func (*Cache) ForgetWorkload

func (c *Cache) ForgetWorkload(w *kueue.Workload) error

func (*Cache) IsAssumedOrAdmittedWorkload added in v0.3.0

func (c *Cache) IsAssumedOrAdmittedWorkload(w workload.Info) bool

func (*Cache) LocalQueueUsage added in v0.4.0

func (c *Cache) LocalQueueUsage(qObj *kueue.LocalQueue) (*LocalQueueUsageStats, error)

func (*Cache) MatchingClusterQueues added in v0.2.0

func (c *Cache) MatchingClusterQueues(nsLabels map[string]string) sets.Set[kueue.ClusterQueueReference]

func (*Cache) PodsReadyForAllAdmittedWorkloads added in v0.3.0

func (c *Cache) PodsReadyForAllAdmittedWorkloads(log logr.Logger) bool

func (*Cache) Snapshot

func (c *Cache) Snapshot(ctx context.Context) (*Snapshot, error)

func (*Cache) TASCache added in v0.9.0

func (c *Cache) TASCache() *TASCache

func (*Cache) TerminateClusterQueue added in v0.2.0

func (c *Cache) TerminateClusterQueue(name kueue.ClusterQueueReference)

func (*Cache) UpdateClusterQueue

func (c *Cache) UpdateClusterQueue(cq *kueue.ClusterQueue) error

func (*Cache) UpdateLocalQueue added in v0.2.0

func (c *Cache) UpdateLocalQueue(oldQ, newQ *kueue.LocalQueue) error

func (*Cache) UpdateWorkload

func (c *Cache) UpdateWorkload(oldWl, newWl *kueue.Workload) error

func (*Cache) Usage

func (c *Cache) Usage(cqObj *kueue.ClusterQueue) (*ClusterQueueUsageStats, error)

Usage reports the reserved and admitted resources and number of workloads holding them in the ClusterQueue.

func (*Cache) WaitForPodsReady added in v0.3.0

func (c *Cache) WaitForPodsReady(ctx context.Context)

WaitForPodsReady waits for all admitted workloads to be in the PodsReady condition if podsReadyTracking is enabled, otherwise returns immediately.

type ClusterQueueSnapshot added in v0.8.0

type ClusterQueueSnapshot struct {
	Name              kueue.ClusterQueueReference
	ResourceGroups    []ResourceGroup
	Workloads         map[string]*workload.Info
	WorkloadsNotReady sets.Set[string]
	NamespaceSelector labels.Selector
	Preemption        kueue.ClusterQueuePreemption
	FairWeight        resource.Quantity
	FlavorFungibility kueue.FlavorFungibility
	// Aggregates AdmissionChecks from both .spec.AdmissionChecks and .spec.AdmissionCheckStrategy
	// Sets hold ResourceFlavors to which an AdmissionCheck should apply.
	// In case its empty, it means an AdmissionCheck should apply to all ResourceFlavor
	AdmissionChecks map[string]sets.Set[kueue.ResourceFlavorReference]
	Status          metrics.ClusterQueueStatus
	// AllocatableResourceGeneration will be increased when some admitted workloads are
	// deleted, or the resource groups are changed.
	AllocatableResourceGeneration int64

	ResourceNode ResourceNode
	hierarchy.ClusterQueue[*CohortSnapshot]

	TASFlavors map[kueue.ResourceFlavorReference]*TASFlavorSnapshot
	// contains filtered or unexported fields
}

func (*ClusterQueueSnapshot) AddUsage added in v0.8.0

func (c *ClusterQueueSnapshot) AddUsage(usage workload.Usage)

func (*ClusterQueueSnapshot) Available added in v0.8.0

Available returns the current capacity available, before preempting any workloads. Includes local capacity and capacity borrowed from Cohort. When the ClusterQueue/Cohort is in debt, Available will return 0.

func (*ClusterQueueSnapshot) Borrowing added in v0.8.0

func (*ClusterQueueSnapshot) BorrowingWith added in v0.8.0

func (c *ClusterQueueSnapshot) BorrowingWith(fr resources.FlavorResource, val int64) bool

func (*ClusterQueueSnapshot) DominantResourceShare added in v0.8.0

func (c *ClusterQueueSnapshot) DominantResourceShare() int

func (*ClusterQueueSnapshot) FindTopologyAssignmentsForWorkload added in v0.10.2

func (c *ClusterQueueSnapshot) FindTopologyAssignmentsForWorkload(
	tasRequestsByFlavor WorkloadTASRequests,
	simulateEmpty bool) TASAssignmentsResult

func (*ClusterQueueSnapshot) Fits added in v0.8.0

func (c *ClusterQueueSnapshot) Fits(usage workload.Usage) bool

func (*ClusterQueueSnapshot) GetName added in v0.9.0

func (*ClusterQueueSnapshot) IsTASOnly added in v0.11.0

func (c *ClusterQueueSnapshot) IsTASOnly() bool

func (*ClusterQueueSnapshot) PotentialAvailable added in v0.8.4

func (c *ClusterQueueSnapshot) PotentialAvailable(fr resources.FlavorResource) int64

PotentialAvailable returns the largest workload this ClusterQueue could possibly admit, accounting for its capacity and capacity borrowed its from Cohort.

func (*ClusterQueueSnapshot) QuotaFor added in v0.8.0

func (*ClusterQueueSnapshot) RGByResource added in v0.8.0

func (c *ClusterQueueSnapshot) RGByResource(resource corev1.ResourceName) *ResourceGroup

RGByResource returns the ResourceGroup which contains capacity for the resource, or nil if the CQ doesn't provide this resource.

func (*ClusterQueueSnapshot) RemoveUsage added in v0.11.0

func (c *ClusterQueueSnapshot) RemoveUsage(usage workload.Usage)

func (*ClusterQueueSnapshot) SimulateUsageAddition added in v0.11.0

func (c *ClusterQueueSnapshot) SimulateUsageAddition(usage workload.Usage) func()

SimulateUsageAddition modifies the snapshot by adding usage, and returns a function used to restore the usage.

func (*ClusterQueueSnapshot) SimulateUsageRemoval added in v0.11.0

func (c *ClusterQueueSnapshot) SimulateUsageRemoval(usage workload.Usage) func()

SimulateUsageRemoval modifies the snapshot by removing usage, and returns a function used to restore the usage.

func (*ClusterQueueSnapshot) SimulateWorkloadRemoval added in v0.11.0

func (c *ClusterQueueSnapshot) SimulateWorkloadRemoval(workloads []*workload.Info) func()

SimulateWorkloadRemoval modifies the snapshot by removing the usage corresponding to the list of workloads. It returns a function which can be used to restore the usage.

type ClusterQueueUsageStats added in v0.5.0

type ClusterQueueUsageStats struct {
	ReservedResources  []kueue.FlavorUsage
	ReservingWorkloads int
	AdmittedResources  []kueue.FlavorUsage
	AdmittedWorkloads  int
	WeightedShare      int64
}

type CohortSnapshot added in v0.8.0

type CohortSnapshot struct {
	Name kueue.CohortReference

	ResourceNode ResourceNode
	hierarchy.Cohort[*ClusterQueueSnapshot, *CohortSnapshot]

	FairWeight resource.Quantity
}

func (*CohortSnapshot) DominantResourceShare added in v0.11.0

func (c *CohortSnapshot) DominantResourceShare() int

func (*CohortSnapshot) GetName added in v0.9.0

func (c *CohortSnapshot) GetName() kueue.CohortReference

func (*CohortSnapshot) Root added in v0.9.2

func (c *CohortSnapshot) Root() *CohortSnapshot

Root returns the root of the Cohort Tree. It expects that no cycles exist in the Cohort graph.

func (*CohortSnapshot) SubtreeClusterQueues added in v0.9.2

func (c *CohortSnapshot) SubtreeClusterQueues() []*ClusterQueueSnapshot

SubtreeClusterQueues returns all of the ClusterQueues in the subtree starting at the given Cohort. It expects that no cycles exist in the Cohort graph.

type CohortUsageStats added in v0.11.0

type CohortUsageStats struct {
	WeightedShare int64
}

type FailureInfo added in v0.10.2

type FailureInfo struct {
	// PodSetName indicates the name of the PodSet for which computing the
	// TAS assignment failed.
	PodSetName kueue.PodSetReference

	// Reason indicates the reason why computing the TAS assignment failed.
	Reason string
}

type FlavorTASRequests added in v0.10.2

type FlavorTASRequests []TASPodSetRequests

type LocalQueueUsageStats added in v0.5.0

type LocalQueueUsageStats struct {
	ReservedResources  []kueue.LocalQueueFlavorUsage
	ReservingWorkloads int
	AdmittedResources  []kueue.LocalQueueFlavorUsage
	AdmittedWorkloads  int
	Flavors            []kueue.LocalQueueFlavorStatus
}

type Option added in v0.3.0

type Option func(*options)

Option configures the reconciler.

func WithExcludedResourcePrefixes added in v0.7.0

func WithExcludedResourcePrefixes(excludedPrefixes []string) Option

func WithFairSharing added in v0.7.0

func WithFairSharing(enabled bool) Option

func WithPodsReadyTracking added in v0.3.0

func WithPodsReadyTracking(f bool) Option

WithPodsReadyTracking indicates the cache controller tracks the PodsReady condition for admitted workloads, and allows to block admission of new workloads until all admitted workloads are in the PodsReady condition.

func WithResourceTransformations added in v0.9.0

func WithResourceTransformations(transforms []config.ResourceTransformation) Option

WithResourceTransformations sets the resource transformations.

type ResourceGroup added in v0.3.0

type ResourceGroup struct {
	CoveredResources sets.Set[corev1.ResourceName]
	Flavors          []kueue.ResourceFlavorReference
	// The set of key labels from all flavors.
	// Those keys define the affinity terms of a workload
	// that can be matched against the flavors.
	LabelKeys sets.Set[string]
}

func (*ResourceGroup) Clone added in v0.8.1

func (rg *ResourceGroup) Clone() ResourceGroup

type ResourceNode added in v0.9.0

type ResourceNode struct {
	// Quotas are the ResourceQuotas specified for the current
	// node.
	Quotas map[resources.FlavorResource]ResourceQuota
	// SubtreeQuota is the sum of the node's quota, as well as
	// resources available from its children, constrained by
	// LendingLimits.
	SubtreeQuota resources.FlavorResourceQuantities
	// Usage is the quantity which counts against this node's
	// SubtreeQuota. For ClusterQueues, this is simply its
	// usage. For Cohorts, this is the sum of childrens'
	// usages past childrens' guaranteedQuotas.
	Usage resources.FlavorResourceQuantities
}

ResourceNode is the shared representation of Quotas and Usage, used by ClusterQueues and Cohorts.

func NewResourceNode added in v0.9.0

func NewResourceNode() ResourceNode

func (ResourceNode) Clone added in v0.9.0

func (r ResourceNode) Clone() ResourceNode

Clone clones the mutable field Usage, while returning copies to Quota and SubtreeQuota (these are replaced with new maps upon update).

type ResourceQuota added in v0.3.0

type ResourceQuota struct {
	Nominal        int64
	BorrowingLimit *int64
	LendingLimit   *int64
}

type Snapshot

type Snapshot struct {
	hierarchy.Manager[*ClusterQueueSnapshot, *CohortSnapshot]
	ResourceFlavors          map[kueue.ResourceFlavorReference]*kueue.ResourceFlavor
	InactiveClusterQueueSets sets.Set[kueue.ClusterQueueReference]
}

func (*Snapshot) AddWorkload added in v0.3.0

func (s *Snapshot) AddWorkload(wl *workload.Info)

AddWorkload adds a workload from its corresponding ClusterQueue and updates resource usage.

func (*Snapshot) Log added in v0.6.0

func (s *Snapshot) Log(log logr.Logger)

func (*Snapshot) RemoveWorkload added in v0.3.0

func (s *Snapshot) RemoveWorkload(wl *workload.Info)

RemoveWorkload removes a workload from its corresponding ClusterQueue and updates resource usage.

type TASAssignmentsResult added in v0.10.2

type TASAssignmentsResult map[kueue.PodSetReference]tasPodSetAssignmentResult

func (TASAssignmentsResult) Failure added in v0.10.2

func (r TASAssignmentsResult) Failure() *FailureInfo

type TASCache added in v0.9.0

type TASCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTASCache added in v0.9.0

func NewTASCache(client client.Client) TASCache

func (*TASCache) Clone added in v0.9.0

Clone returns a shallow copy of the map

func (*TASCache) Delete added in v0.9.0

func (t *TASCache) Delete(name kueue.ResourceFlavorReference)

func (*TASCache) Get added in v0.9.0

func (*TASCache) NewTASFlavorCache added in v0.9.0

func (t *TASCache) NewTASFlavorCache(topologyName kueue.TopologyReference, levels []string, nodeLabels map[string]string,
	tolerations []corev1.Toleration) *TASFlavorCache

func (*TASCache) Set added in v0.9.0

type TASFlavorCache added in v0.9.0

type TASFlavorCache struct {
	sync.RWMutex

	// TopologyName indicates the name of the topology specified in the
	// ResourceFlavor spec.topologyName field.
	TopologyName kueue.TopologyReference
	// nodeLabels is a map of nodeLabels defined in the ResourceFlavor object.
	NodeLabels map[string]string
	// levels is a list of levels defined in the Topology object referenced
	// by the flavor corresponding to the cache.
	Levels []string

	// tolerations represents the list of tolerations specified for the resource
	// flavor
	Tolerations []corev1.Toleration
	// contains filtered or unexported fields
}

type TASFlavorSnapshot added in v0.9.0

type TASFlavorSnapshot struct {
	// contains filtered or unexported fields
}

func (*TASFlavorSnapshot) FindTopologyAssignmentsForFlavor added in v0.10.2

func (s *TASFlavorSnapshot) FindTopologyAssignmentsForFlavor(flavorTASRequests FlavorTASRequests, simulateEmpty bool) TASAssignmentsResult

FindTopologyAssignmentsForFlavor returns TAS assignment, if possible, for all the TAS requests in the flavor handled by the snapshot. The simulateEmpty parameter allows to look for the assignment under the assumption that all TAS workloads are preempted.

func (*TASFlavorSnapshot) Fits added in v0.11.0

func (s *TASFlavorSnapshot) Fits(flavorUsage workload.TASFlavorUsage) bool

Fits checks if the snapshot has enough capacity to accommodate the workload

func (*TASFlavorSnapshot) HasLevel added in v0.9.0

func (*TASFlavorSnapshot) SerializeFreeCapacityPerDomain added in v0.11.0

func (s *TASFlavorSnapshot) SerializeFreeCapacityPerDomain() (string, error)

type TASPodSetRequests added in v0.10.2

type TASPodSetRequests struct {
	PodSet            *kueue.PodSet
	SinglePodRequests resources.Requests
	Count             int32
	Flavor            kueue.ResourceFlavorReference
	Implied           bool
}

func (*TASPodSetRequests) TotalRequests added in v0.11.0

func (t *TASPodSetRequests) TotalRequests() resources.Requests

type WorkloadTASRequests added in v0.10.2

type WorkloadTASRequests map[kueue.ResourceFlavorReference]FlavorTASRequests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳