resourcewatcher

package
v0.1.0-alpha.9 Latest Latest
Warning

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

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

README

pkg/controller/resourcewatcher

Resource watcher lifecycle management.

Overview

Manages lifecycle of Kubernetes resource watchers based on controller configuration.

Quick Start

watcher := resourcewatcher.NewResourceWatcherComponent(bus, k8sClient, logger)
go watcher.Start(ctx)

Events

  • Subscribes: ConfigValidatedEvent
  • Publishes: ResourceIndexUpdatedEvent, ResourceSyncCompleteEvent

License

See main repository for license information.

Documentation

Overview

Package resourcewatcher provides the ResourceWatcherComponent that creates and manages watchers for all Kubernetes resources defined in the controller configuration.

The component:

  • Creates a k8s.Watcher for each resource type in Config.WatchedResources
  • Merges global WatchedResourcesIgnoreFields with per-resource ignore fields
  • Publishes ResourceIndexUpdatedEvent on resource changes
  • Publishes ResourceSyncCompleteEvent when a resource type completes initial sync
  • Provides access to stores for template rendering

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResourceWatcherComponent

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

ResourceWatcherComponent creates and manages watchers for all configured resources.

func New

func New(
	cfg *coreconfig.Config,
	k8sClient *client.Client,
	eventBus *busevents.EventBus,
	logger *slog.Logger,
) (*ResourceWatcherComponent, error)

New creates a new ResourceWatcherComponent.

For each entry in cfg.WatchedResources, this creates a k8s.Watcher that:

  • Watches the specified Kubernetes resource type
  • Indexes resources using the configured IndexBy expressions
  • Filters fields by merging global WatchedResourcesIgnoreFields with per-resource ignore fields
  • Publishes events to the EventBus on resource changes

Returns an error if:

  • Configuration validation fails
  • Watcher creation fails for any resource type

func (*ResourceWatcherComponent) AllSynced

func (r *ResourceWatcherComponent) AllSynced() bool

AllSynced returns true if all resource types have completed initial sync.

func (*ResourceWatcherComponent) GetAllStores

func (r *ResourceWatcherComponent) GetAllStores() map[string]types.Store

GetAllStores returns a map of all stores keyed by resource type name.

Returns a copy of the internal map to prevent external modification.

func (*ResourceWatcherComponent) GetStore

func (r *ResourceWatcherComponent) GetStore(resourceTypeName string) types.Store

GetStore returns the store for a specific resource type.

Returns:

  • The store if the resource type exists
  • nil if the resource type is not watched

func (*ResourceWatcherComponent) IsSynced

func (r *ResourceWatcherComponent) IsSynced(resourceTypeName string) bool

IsSynced returns true if the specified resource type has completed initial sync.

func (*ResourceWatcherComponent) Start

Start begins watching all configured resources.

This method:

  • Starts all watchers in separate goroutines
  • Returns immediately without blocking
  • Continues running until ctx is cancelled

Use WaitForAllSync() to wait for initial synchronization to complete.

func (*ResourceWatcherComponent) WaitForAllSync

func (r *ResourceWatcherComponent) WaitForAllSync(ctx context.Context) error

WaitForAllSync blocks until all watchers have completed initial synchronization.

Returns:

  • nil if all watchers synced successfully
  • error if sync fails or context is cancelled

Jump to

Keyboard shortcuts

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