informer

package
v0.62.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package informer provides a shared informer manager for Kubernetes resources.

Index

Constants

View Source
const PodIndexerName = "spec.NodeName"
View Source
const VANodeNameIndexer = "spec.nodeName"

VANodeNameIndexer is the indexer key for looking up VolumeAttachments by node name.

Variables

View Source
var ErrIndexerMissing = errors.New("missing indexer")

Functions

func NewNodeInformer added in v0.62.0

func NewNodeInformer(
	informer cache.SharedIndexInformer,
	lister listerv1.NodeLister,
) *nodeInformer

func NewPodInformer added in v0.62.0

func NewPodInformer(
	informer cache.SharedIndexInformer,
	lister listerv1.PodLister,
	indexer cache.Indexer,
) *podInformer

Types

type Manager

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

Manager manages the global SharedInformerFactory and provides access to specific informers and listers.

func NewManager

func NewManager(
	log logrus.FieldLogger,
	clientset kubernetes.Interface,
	resyncPeriod time.Duration,
	opts ...Option,
) *Manager

NewManager creates a new Manager with the given clientset and resync period.

func (*Manager) GetFactory

func (m *Manager) GetFactory() informers.SharedInformerFactory

GetFactory returns the underlying SharedInformerFactory for advanced use cases.

func (*Manager) GetNodeInformer

func (m *Manager) GetNodeInformer() NodeInformer

GetNodeInformer returns the node informer for watching node events.

func (*Manager) GetNodeLister

func (m *Manager) GetNodeLister() listerv1.NodeLister

GetNodeLister returns the node lister for querying the node cache.

func (*Manager) GetPodLister

func (m *Manager) GetPodLister() listerv1.PodLister

GetPodLister returns the pod lister for querying the pod cache.

func (*Manager) GetVAIndexer

func (m *Manager) GetVAIndexer() cache.Indexer

GetVAIndexer returns the VolumeAttachment indexer for indexed lookups. Use with VANodeNameIndexer to look up VolumeAttachments by node name. Returns nil if the VA informer is not available or not synced.

func (*Manager) GetVAInformer

func (m *Manager) GetVAInformer() cache.SharedIndexInformer

GetVAInformer returns the VolumeAttachment informer for watching VA events. Returns nil if the VA informer is not available or not synced.

func (*Manager) GetVALister

GetVALister returns the VolumeAttachment lister for querying the VA cache. Returns nil if the VA informer is not available or not synced.

func (*Manager) IsVAAvailable

func (m *Manager) IsVAAvailable() bool

IsVAAvailable indicates whether the VolumeAttachment informer is available.

func (*Manager) Nodes added in v0.62.0

func (m *Manager) Nodes() NodeInformer

Nodes returns the node informer for node domain operations. This is a convenience method that returns the same as GetNodeInformer().

func (*Manager) Pods added in v0.62.0

func (m *Manager) Pods() PodInformer

Pods returns the pod informer for pod domain operations.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start starts the informer factory and waits for all caches to sync. This method blocks until caches are synchronized or the context is canceled.

func (*Manager) Stop

func (m *Manager) Stop()

Stop gracefully stops the informer factory.

type NodeInformer added in v0.62.0

type NodeInformer interface {
	// Get retrieves a node by name from cache
	Get(name string) (*corev1.Node, error)

	// List returns all nodes from cache
	List() ([]*corev1.Node, error)

	// Wait watches for a node to meet a condition.
	// Returns a channel that signals when condition is met or context is canceled.
	// Used for event-driven waiting (e.g., wait for node to become ready).
	Wait(ctx context.Context, name string, condition Predicate) chan error
}

NodeInformer provides domain operations for nodes. Lifecycle (start/stop/sync) is managed by Manager.

type Option

type Option func(*Manager)

Option is a functional option for configuring the Manager.

func EnableNodeInformer

func EnableNodeInformer() Option

func EnablePodInformer

func EnablePodInformer() Option

func WithCacheSyncTimeout

func WithCacheSyncTimeout(timeout time.Duration) Option

WithCacheSyncTimeout sets the timeout for waiting for informer caches to sync.

func WithDefaultPodNodeNameIndexer added in v0.62.0

func WithDefaultPodNodeNameIndexer() Option

func WithDefaultVANodeNameIndexer

func WithDefaultVANodeNameIndexer() Option

WithDefaultVANodeNameIndexer adds the default spec.nodeName indexer for VolumeAttachments. This is commonly used to look up VolumeAttachments by node name.

func WithNodeIndexers

func WithNodeIndexers(indexers cache.Indexers) Option

WithNodeIndexers sets custom indexers for the node informer.

func WithPodIndexers

func WithPodIndexers(indexers cache.Indexers) Option

WithPodIndexers sets custom indexers for the pod informer.

func WithVAIndexers

func WithVAIndexers(indexers cache.Indexers) Option

WithVAIndexers sets custom indexers for the VolumeAttachment informer.

type PodInformer added in v0.62.0

type PodInformer interface {
	// Get retrieves a pod by namespace and name from cache
	Get(namespace, name string) (*corev1.Pod, error)

	// List returns all pods from cache
	List() ([]*corev1.Pod, error)

	// ListByNode returns all pods running on a specific node
	ListByNode(nodeName string) ([]*corev1.Pod, error)

	// ListByNamespace returns all pods in a namespace
	ListByNamespace(namespace string) ([]*corev1.Pod, error)
}

PodInformer provides domain operations for pods.

type Predicate added in v0.62.0

type Predicate func(node *corev1.Node) (bool, error)

type VAPermissionError

type VAPermissionError struct {
	// MissingVerb is the verb that was denied (e.g., "get", "list", "watch").
	MissingVerb string
}

VAPermissionError indicates that required RBAC permissions for VolumeAttachments are missing.

func (*VAPermissionError) Error

func (e *VAPermissionError) Error() string

Jump to

Keyboard shortcuts

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