watcher

package
v1.10.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// CacheMaxKeys is the maximum number of VMs for which to cache properties.
	//
	// A single VM takes 615 bytes when cached, which means 25,000 cached VMs
	// take only 14.66 MiB in memory.
	//
	// Even if each VM took 1 KiB, that would mean 25,000 VMs would only take up
	// 24.41 MiB in memory.
	CacheMaxKeys = 25000

	// CacheTTL is the expiry time for items in the cache.
	CacheTTL = time.Hour * 24
)

Variables

View Source
var (
	// ErrAsyncSignalDisabled is returned from the Add/Remove functions if they
	// are called while async signal is disabled.
	ErrAsyncSignalDisabled = errors.New("async signal disabled")

	// ErrNoWatcher is returned from the Add/Remove functions if they are called
	// without a watcher in the context.
	ErrNoWatcher = errors.New("no watcher")
)
View Source
var (
	// Cache is an LRU cache used to cache the properties of VMs.
	Cache expcache.Cache[moRef, map[string]string]
)

Functions

func Add

func Add(ctx context.Context, ref moRef, id string) (err error)

Add starts watching a container to which VirtualMachine resources may belong, such as a Folder, Cluster, ResourcePool, etc.

func CacheGetStats added in v1.10.0

func CacheGetStats() []any

CacheGetStats returns the key/value pairs required to log the cache's stats. This is an expensive operation as it locks the cache to get the base stats and then again, per object in the cache, to calculate the total size of the cache.

func Close added in v1.10.0

func Close(ctx context.Context) (err error)

Close closes the watcher associated with the context.

func DefaultWatchedPropertyPaths

func DefaultWatchedPropertyPaths() []string

DefaultWatchedPropertyPaths returns the default set of property paths to watch.

func JoinContext

func JoinContext(left, right context.Context) context.Context

JoinContext returns a new context that contains a reference to the functions object from the specified context. This function panics if the provided context does not contain a functions object. This function is thread-safe.

func NewContext

func NewContext() context.Context

NewContext returns a new context with a new functions object.

func Remove

func Remove(ctx context.Context, ref moRef, id string) (err error)

Remove stops watching a container to which VirtualMachine resources may belong, such as a Folder, Cluster, ResourcePool, etc.

func ValidateContext

func ValidateContext(ctx context.Context) bool

ValidateContext returns true if the provided context contains the functions object.

func WithContext

func WithContext(parent context.Context) context.Context

WithContext returns a new context with a new functions object.

Types

type LookupNamespacedNameResult

type LookupNamespacedNameResult struct {
	Namespace string
	Name      string

	// Verified indicates whether or not the VM's Kubernetes resource has the
	// vSphere VM's managed object ID in status.uniqueID.
	Verified    bool
	VerifiedObj any

	// Deleted indicates whether the VM's Kubernetes resource has a
	// non-zero deletion timestamp.
	Deleted bool
}

LookupNamespacedNameResult is returned from a call to lookup the namespaced name of a vSphere VM.

type Result

type Result struct {
	// Namespace is the namespace to which the VirtualMachine resource belongs.
	Namespace string

	// Name is the name of the VirtualMachine resource.
	Name string

	// Ref is the ManagedObjectReference for the VM in vSphere.
	Ref moRef

	// Verified is true if the VirtualMachine resource identified by Namespace
	// and Name has already been verified to exist in this Kubernetes cluster.
	Verified    bool
	VerifiedObj any
}

type Watcher

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

func Start

func Start(
	ctx context.Context,
	client *vim25.Client,
	watchedPropertyPaths []string,
	additionalIgnoredExtraConfigKeys []string,
	lookupNamespacedName lookupNamespacedNameFn,
	containerRefsWithIDs map[moRef][]string) (*Watcher, error)

Start begins watching a vSphere server for updates to VM Service managed VMs. If watchedPropertyPaths is nil, DefaultWatchedPropertyPaths will be used. The containerRefsWithIDs parameter may be used to start the watcher with an initial list of entities to watch.

func (*Watcher) Done

func (w *Watcher) Done() <-chan struct{}

Done returns a channel that is closed when the watcher is shutdown.

func (*Watcher) Err

func (w *Watcher) Err() error

Err returns the error that caused the watcher to stop.

func (*Watcher) Result

func (w *Watcher) Result() <-chan Result

Result returns a channel on which new results are received.

Jump to

Keyboard shortcuts

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