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 ResourceWatcherComponent
- func (r *ResourceWatcherComponent) AllSynced() bool
- func (r *ResourceWatcherComponent) GetAllStores() map[string]types.Store
- func (r *ResourceWatcherComponent) GetStore(resourceTypeName string) types.Store
- func (r *ResourceWatcherComponent) IsSynced(resourceTypeName string) bool
- 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 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 ¶
func (r *ResourceWatcherComponent) Start(ctx context.Context) error
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