cache

package
v1.18.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultAssumptionTTL = 5 * time.Minute

DefaultAssumptionTTL is the default duration a reservation is kept alive after it is created. Once a workload's AggregatedStatus becomes Healthy the reservation is released immediately; this TTL serves as a safety net for workloads that take unusually long to start or whose health signal never arrives.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssigningResourceBindingCache added in v1.17.0

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

AssigningResourceBindingCache acts as a temporary buffer for ResourceBindings that have new scheduling decisions ("assigning" state) but are not yet fully reflected in the local Informer cache or member clusters.

func (*AssigningResourceBindingCache) Add added in v1.17.0

Add records a ResourceBinding that has a new scheduling decision committed to the API server. This binding is considered to be in an "assigning" state and will be served by the scheduler as the intended state until its full reflection in the Informer cache and member clusters.

func (*AssigningResourceBindingCache) Assume added in v1.18.0

func (b *AssigningResourceBindingCache) Assume(bindingKey, clusterName string, entry AssumedWorkload)

Assume records (or replaces) the resource footprint for the given binding+cluster pair. Calling Assume again for the same pair overwrites the previous entry and resets the TTL, reflecting the latest scheduling decision. entry.Components are deep-copied before storage to prevent callers from unintentionally mutating the cache's internal state via shared slice backing arrays.

func (*AssigningResourceBindingCache) GC added in v1.18.0

GC removes all assumptions whose TTL has expired. It is intended to be called periodically (e.g., every minute) as a safety net for assumptions whose normal release path (Healthy signal) was never triggered. Returns the number of binding entries that were removed.

func (*AssigningResourceBindingCache) GetAssumedWorkloads added in v1.18.0

func (b *AssigningResourceBindingCache) GetAssumedWorkloads(clusterName string) []AssumedWorkload

GetAssumedWorkloads returns the reserved workloads for a given cluster across all bindings. Only assumptions that have not yet expired are included; expired entries are skipped (they will be cleaned up by the next GC sweep). Each returned AssumedWorkload is a deep copy, so callers may safely read or modify the result without affecting the cache's internal state.

func (*AssigningResourceBindingCache) GetBindings added in v1.17.0

GetBindings returns all currently cached ResourceBindings that are in the "assigning" state, providing the scheduler with the most up-to-date view of pending assignments.

func (*AssigningResourceBindingCache) IsAssumptionExist added in v1.18.0

func (b *AssigningResourceBindingCache) IsAssumptionExist(bindingKey string) bool

IsAssumptionExist checks if there is an existing assumption for the given binding key.

func (*AssigningResourceBindingCache) OnBindingDelete added in v1.17.0

func (b *AssigningResourceBindingCache) OnBindingDelete(binding *workv1alpha2.ResourceBinding)

OnBindingDelete is called when a delete event for a ResourceBinding is received from the Informer.

func (*AssigningResourceBindingCache) OnBindingUpdate added in v1.17.0

func (b *AssigningResourceBindingCache) OnBindingUpdate(binding *workv1alpha2.ResourceBinding)

OnBindingUpdate is called when an update event for a ResourceBinding is received from the Informer. It removes the binding from this temporary cache if the Informer's version has caught up to or surpassed the version we recorded, indicating that the scheduling decision is now reflected in the Informer's state. This means the binding is no longer in the "assigning" state from the cache's perspective.

func (*AssigningResourceBindingCache) ReleaseAssumption added in v1.18.0

func (b *AssigningResourceBindingCache) ReleaseAssumption(bindingKey string)

ReleaseAssumption removes all cluster assumptions for a given binding at once. It is used when a binding is fully rescheduled or deleted.

func (*AssigningResourceBindingCache) ReleaseClusterAssumption added in v1.18.0

func (b *AssigningResourceBindingCache) ReleaseClusterAssumption(bindingKey, clusterName string)

ReleaseClusterAssumption removes the reservation for a specific cluster within a binding. It is called when the workload on that cluster has reached a Healthy state. If the binding has no remaining cluster assumptions after the removal, the binding entry itself is also deleted.

type AssumedWorkload added in v1.18.0

type AssumedWorkload struct {
	// Namespace is the namespace of the reserved workload.
	Namespace string
	// Components lists the component types and their per-replica resource requirements
	// that are reserved on the target cluster.
	Components []workv1alpha2.Component
}

AssumedWorkload holds the resource footprint of an in-flight workload set that has been assigned to a specific cluster by the scheduler but whose pods have not yet reached a Healthy state. The estimator deducts this footprint from the cluster's available capacity to avoid over-commitment when multiple workloads are scheduled in rapid succession.

type BindingAssumption added in v1.18.0

type BindingAssumption struct {

	// ExpiresAt is the wall-clock time after which this reservation is considered stale
	// and will be removed by the GC sweep.
	ExpiresAt time.Time
	// contains filtered or unexported fields
}

BindingAssumption groups all per-cluster assumptions belonging to a single ResourceBinding and carries the expiry time for the entire binding entry.

type Cache

type Cache interface {
	AddCluster(cluster *clusterv1alpha1.Cluster)
	UpdateCluster(cluster *clusterv1alpha1.Cluster)
	DeleteCluster(cluster *clusterv1alpha1.Cluster)
	// Snapshot returns a snapshot of the current clusters info
	Snapshot() Snapshot

	// ResourceBindingIndexer returns the indexer for ResourceBindings, used for advanced scheduling logic.
	ResourceBindingIndexer() cache.Indexer

	// AssigningResourceBindings returns a cache for ResourceBindings that are in the "assigning" state.
	// After the control plane generates scheduling results and commits them to the API server,
	// there is a period before these results are fully propagated to and reflected in the member clusters.
	// This cache stores these "assigning" bindings to provide the scheduler with a more accurate and
	// immediate view of the intended state, enabling more precise decision-making during subsequent scheduling cycles.
	AssigningResourceBindings() *AssigningResourceBindingCache
}

Cache is an interface for scheduler internal cache.

func NewCache

func NewCache(clusterLister clusterlister.ClusterLister, resourceBindingIndexer cache.Indexer, assumptionTTL time.Duration) Cache

NewCache instantiates a cache used only by scheduler.

type Snapshot

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

Snapshot is a snapshot of cache ClusterInfo. The scheduler takes a snapshot at the beginning of each scheduling cycle and uses it for its operations in that cycle.

func NewEmptySnapshot

func NewEmptySnapshot() Snapshot

NewEmptySnapshot initializes a Snapshot struct and returns it.

func (*Snapshot) GetCluster added in v0.9.0

func (s *Snapshot) GetCluster(clusterName string) *framework.ClusterInfo

GetCluster returns the given clusters.

func (*Snapshot) GetClusters

func (s *Snapshot) GetClusters() []*framework.ClusterInfo

GetClusters returns all the clusters.

func (*Snapshot) GetReadyClusterNames added in v0.8.0

func (s *Snapshot) GetReadyClusterNames() sets.Set[string]

GetReadyClusterNames returns the clusterNames in ready status.

func (*Snapshot) GetReadyClusters added in v0.3.0

func (s *Snapshot) GetReadyClusters() []*framework.ClusterInfo

GetReadyClusters returns the clusters in ready status.

func (*Snapshot) NumOfClusters

func (s *Snapshot) NumOfClusters() int

NumOfClusters returns the number of clusters.

Jump to

Keyboard shortcuts

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