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 ¶
- type Option
- type ResourceWatcherComponent
- func (r *ResourceWatcherComponent) FreshStores(ctx context.Context) (map[string]types.Store, error)
- func (r *ResourceWatcherComponent) GetAllStores() map[string]types.Store
- func (r *ResourceWatcherComponent) GetStore(resourceTypeName string) types.Store
- func (r *ResourceWatcherComponent) Start(ctx context.Context) error
- func (r *ResourceWatcherComponent) WaitForAllSync(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options)
Option configures New beyond its required arguments.
func WithSelfWriteFilter ¶
func WithSelfWriteFilter(f types.SelfWriteFilter) Option
WithSelfWriteFilter hands every watcher the filter that recognises this controller's own writes, so an echoed status write refreshes the store without triggering a reconciliation.
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, opts ...Option, ) (*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) FreshStores ¶
FreshStores snapshots each watched collection directly from the API server.
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) Start ¶
func (r *ResourceWatcherComponent) Start(ctx context.Context) error
Start begins watching all configured resources.
This method:
- Starts all watchers in separate goroutines
- Continues running until ctx is cancelled
- Waits for every watcher to stop before returning
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