cache

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeStrategyFingerprint

func ComputeStrategyFingerprint(strategies []*domain.SchedulingStrategy) string

ComputeStrategyFingerprint generates a unique fingerprint for scheduling strategies This excludes PID field as PIDs are calculated, not part of input strategy

func GetKubernetesPod

func GetKubernetesPod(podUID string) (apiv1.Pod, bool)

GetKubernetesPod retrieves pod information from the cache if available

func SetKubernetesPodCache

func SetKubernetesPodCache(podUID string, pod apiv1.Pod)

SetKubernetesPodCache sets the pod information in the cache

func StartPodWatcher

func StartPodWatcher(cache *StrategyCache, kubeClient *kubernetes.Clientset) (stopCh chan struct{}, err error)

StartPodWatcher starts watching Kubernetes pod events and invalidates cache on changes

Types

type PodChangeDetector

type PodChangeDetector struct{}

PodChangeDetector computes fingerprints for pod states

func NewPodChangeDetector

func NewPodChangeDetector() *PodChangeDetector

NewPodChangeDetector creates a new pod change detector

func (*PodChangeDetector) ComputeFingerprint

func (d *PodChangeDetector) ComputeFingerprint(pods []*domain.PodInfo) string

ComputeFingerprint generates a unique fingerprint for pod state

type PodEvent

type PodEvent struct {
	Type string
	Pod  apiv1.Pod
}

PodEvent represents a Kubernetes pod event

type PodFingerprint

type PodFingerprint struct {
	UID       string
	Processes []ProcessFingerprint
}

PodFingerprint represents essential pod information for change detection

type PodWatcher

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

PodWatcher watches for Kubernetes pod changes

func NewPodWatcher

func NewPodWatcher() *PodWatcher

NewPodWatcher creates a new pod watcher

func (*PodWatcher) OnPodChange

func (w *PodWatcher) OnPodChange(callback func())

OnPodChange registers a callback for pod changes

func (*PodWatcher) SimulateEvent

func (w *PodWatcher) SimulateEvent(event PodEvent)

SimulateEvent simulates a pod event (for testing)

func (*PodWatcher) Start

func (w *PodWatcher) Start() error

Start begins watching for pod changes

func (*PodWatcher) Stop

func (w *PodWatcher) Stop()

Stop stops the watcher

type ProcessFingerprint

type ProcessFingerprint struct {
	PID     int
	Command string
}

ProcessFingerprint represents essential process information

type StrategyCache

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

StrategyCache manages caching of scheduling strategies

func NewStrategyCache

func NewStrategyCache() *StrategyCache

NewStrategyCache creates a new strategy cache with default TTL

func NewStrategyCacheWithTTL

func NewStrategyCacheWithTTL(ttl time.Duration) *StrategyCache

NewStrategyCacheWithTTL creates a cache with custom TTL

func (*StrategyCache) GetCacheHits

func (c *StrategyCache) GetCacheHits() int

GetCacheHits returns number of cache hits

func (*StrategyCache) GetCacheMisses

func (c *StrategyCache) GetCacheMisses() int

GetCacheMisses returns number of cache misses

func (*StrategyCache) GetStats

func (c *StrategyCache) GetStats() map[string]interface{}

GetStats returns cache statistics

func (*StrategyCache) GetStrategies

func (c *StrategyCache) GetStrategies(currentPods []*domain.PodInfo, inputStrategies []*domain.SchedulingStrategy) []*domain.SchedulingStrategy

GetStrategies returns cached strategies if valid, otherwise returns nil This version still checks pod fingerprint for backward compatibility

func (*StrategyCache) GetStrategiesQuick

func (c *StrategyCache) GetStrategiesQuick(inputStrategies []*domain.SchedulingStrategy) []*domain.SchedulingStrategy

GetStrategiesQuick returns cached strategies without checking pod state Relies on Kubernetes Watch to invalidate cache when pods change

func (*StrategyCache) HasPodsChanged

func (c *StrategyCache) HasPodsChanged(pods []*domain.PodInfo) bool

HasPodsChanged checks if pods have changed since last snapshot

func (*StrategyCache) Invalidate

func (c *StrategyCache) Invalidate()

Invalidate marks cache as invalid

func (*StrategyCache) IsValid

func (c *StrategyCache) IsValid() bool

IsValid returns whether cache is valid

func (*StrategyCache) SetStrategies

func (c *StrategyCache) SetStrategies(strategies []*domain.SchedulingStrategy)

SetStrategies stores strategies in cache

func (*StrategyCache) UpdatePodSnapshot

func (c *StrategyCache) UpdatePodSnapshot(pods []*domain.PodInfo)

UpdatePodSnapshot updates the pod fingerprint

func (*StrategyCache) UpdateStrategySnapshot

func (c *StrategyCache) UpdateStrategySnapshot(strategies []*domain.SchedulingStrategy)

UpdateStrategySnapshot updates the strategy fingerprint

Jump to

Keyboard shortcuts

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