kubernetesk8s.io/kubernetes/pkg/kubelet/util/manager Index | Files

package manager

import "k8s.io/kubernetes/pkg/kubelet/util/manager"

Index

Types

type GetObjectFunc

type GetObjectFunc func(string, string, metav1.GetOptions) (runtime.Object, error)

GetObjectFunc defines a function to get object with a given namespace and name.

type GetObjectTTLFunc

type GetObjectTTLFunc func() (time.Duration, bool)

GetObjectTTLFunc defines a function to get value of TTL.

func GetObjectTTLFromNodeFunc

func GetObjectTTLFromNodeFunc(getNode func() (*v1.Node, error)) GetObjectTTLFunc

GetObjectTTLFromNodeFunc returns a function that returns TTL value from a given Node object.

type Manager

type Manager interface {
	// Get object by its namespace and name.
	GetObject(namespace, name string) (runtime.Object, error)

	// RegisterPod registers all objects referenced from a given pod.
	//
	// NOTE: All implementations of RegisterPod should be idempotent.
	RegisterPod(pod *v1.Pod)

	// UnregisterPod unregisters objects referenced from a given pod that are not
	// used by any other registered pod.
	//
	// NOTE: All implementations of UnregisterPod should be idempotent.
	UnregisterPod(pod *v1.Pod)
}

Manager is the interface for registering and unregistering objects referenced by pods in the underlying cache and extracting those from that cache if needed.

func NewCacheBasedManager

func NewCacheBasedManager(objectStore Store, getReferencedObjects func(*v1.Pod) sets.Set[string]) Manager

NewCacheBasedManager creates a manager that keeps a cache of all objects necessary for registered pods. It implements the following logic:

func NewWatchBasedManager

func NewWatchBasedManager(
	listObject listObjectFunc,
	watchObject watchObjectFunc,
	newObject newObjectFunc,
	isImmutable isImmutableFunc,
	groupResource schema.GroupResource,
	resyncInterval time.Duration,
	getReferencedObjects func(*v1.Pod) sets.Set[string]) Manager

NewWatchBasedManager creates a manager that keeps a cache of all objects necessary for registered pods. It implements the following logic:

type Store

type Store interface {
	// AddReference adds a reference from referencedFrom to the object to the store.
	// Note that multiple additions to the store has to be allowed
	// in the implementations and effectively treated as refcounted.
	AddReference(namespace, name string, referencedFrom types.UID)
	// DeleteReference deletes a reference from referencedFrom to the object from the store.
	// Note that object should be deleted only when there was a
	// corresponding Delete call for each of Add calls (effectively
	// when refcount of every referenceFrom was reduced to zero).
	DeleteReference(namespace, name string, referencedFrom types.UID)
	// Get an object from a store.
	Get(namespace, name string) (runtime.Object, error)
}

Store is the interface for a object cache that can be used by cacheBasedManager.

func NewObjectCache

func NewObjectCache(
	listObject listObjectFunc,
	watchObject watchObjectFunc,
	newObject newObjectFunc,
	isImmutable isImmutableFunc,
	groupResource schema.GroupResource,
	clock clock.Clock,
	maxIdleTime time.Duration,
	stopCh <-chan struct{}) Store

NewObjectCache returns a new watch-based instance of Store interface.

func NewObjectStore

func NewObjectStore(getObject GetObjectFunc, clock clock.Clock, getTTL GetObjectTTLFunc, ttl time.Duration) Store

NewObjectStore returns a new ttl-based instance of Store interface.

Source Files

cache_based_manager.go manager.go watch_based_manager.go

Version
v1.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
19 packages
Last checked
3 hours ago

Tools for package owners.