mux

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mux multiplexes Kubernetes dynamic informers created on demand.

Each registered GroupVersionResource gets its own shared informer that lists existing objects and then watches for changes. All events are delivered on a single unified channel accessible via Mux.Events.

The underlying informers handle gap recovery automatically (HTTP 410 Gone, timeouts, etc.), so no events are missed. Consumers may see duplicates and should deduplicate if exactly-once semantics are required.

Index

Constants

This section is empty.

Variables

View Source
var ErrStopped = errors.New("mux is stopped")

ErrStopped is returned by Add when the Mux has already been stopped.

Functions

This section is empty.

Types

type Mux

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

Mux manages a dynamic set of Kubernetes informers and merges their events into a single channel. Watches can be added and removed at runtime. All methods are safe for concurrent use.

func New

func New(ctx context.Context, client dynamic.Interface, opts ...Option) (*Mux, error)

New creates a Mux that will create informers using the provided dynamic client. No watches are started until Add is called. The parent context controls the lifetime of all informers; canceling it is equivalent to calling Stop.

func (*Mux) Add

func (m *Mux) Add(gvr schema.GroupVersionResource) error

Add registers a watch for the given GVR. It blocks until the informer's cache has synced (the initial list is complete). Calling Add for an already-watched GVR (including a concurrent Add for the same GVR) blocks until that watch has synced, then returns.

func (*Mux) Events

func (m *Mux) Events() <-chan watch.Event

Events returns the unified, read-only event stream. The channel is closed when Stop is called.

func (*Mux) GVRs

func (m *Mux) GVRs() []schema.GroupVersionResource

GVRs returns all currently watched GroupVersionResources.

func (*Mux) Has

func (m *Mux) Has(gvr schema.GroupVersionResource) bool

Has reports whether the given GVR is currently being watched.

func (*Mux) Len

func (m *Mux) Len() int

Len returns the number of active watches.

func (*Mux) Remove

func (m *Mux) Remove(gvr schema.GroupVersionResource) bool

Remove stops the watch for the given GVR and returns true. If the GVR is not being watched, Remove returns false.

func (*Mux) Stop

func (m *Mux) Stop()

Stop terminates all watches and closes the event channel. It is safe to call multiple times.

type Option

type Option func(*muxConfig)

Option configures a Mux during construction.

func WithBuffer

func WithBuffer(n int) Option

WithBuffer sets the capacity of the internal event channel. Values below 1 are ignored and the default (1024) is used instead.

func WithFieldSelector

func WithFieldSelector(s string) Option

WithFieldSelector applies a Kubernetes field selector to every informer created by this Mux.

func WithLabelSelector

func WithLabelSelector(s string) Option

WithLabelSelector applies a Kubernetes label selector to every informer created by this Mux.

Jump to

Keyboard shortcuts

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