@@ -199,6 +199,29 @@ type WatchInput struct {
199
199
Predicates []predicate.Predicate
200
200
}
201
201
202
+ // TypedWatcher is a scoped-down interface from Controller that only knows how to watch.
203
+ type TypedWatcher [request comparable ] interface {
204
+ Watch (src source.TypedSource [request ]) error
205
+ }
206
+
207
+ // TypedWatchInput specifies the parameters used to establish a new watch for a remote cluster.
208
+ type TypedWatchInput [object client.Object , request comparable ] struct {
209
+ // Name represents a unique watch request for the specified Cluster.
210
+ Name string
211
+
212
+ // Watcher is the watcher (controller) whose Reconcile() function will be called for events.
213
+ Watcher TypedWatcher [request ]
214
+
215
+ // Kind is the type of resource to watch.
216
+ Kind object
217
+
218
+ // EventHandler contains the event handlers to invoke for resource events.
219
+ EventHandler handler.TypedEventHandler [object , request ]
220
+
221
+ // Predicates is used to filter resource events.
222
+ Predicates []predicate.TypedPredicate [object ]
223
+ }
224
+
202
225
// GetClusterSourceOption is an option that modifies GetClusterSourceOptions for a GetClusterSource call.
203
226
type GetClusterSourceOption interface {
204
227
// ApplyToGetClusterSourceOptions applies this option to the given GetClusterSourceOptions.
@@ -350,6 +373,15 @@ func (cc *clusterCache) Watch(ctx context.Context, cluster client.ObjectKey, inp
350
373
return accessor .Watch (ctx , input )
351
374
}
352
375
376
+ // TypedWatch starts a typed watch.
377
+ func TypedWatch [object client.Object , request comparable ](ctx context.Context , cc * clusterCache , cluster client.ObjectKey , input TypedWatchInput [object , request ]) error {
378
+ accessor := cc .getClusterAccessor (cluster )
379
+ if accessor == nil {
380
+ return errors .Wrapf (ErrClusterNotConnected , "error creating watch %s for %T" , input .Name , input .Kind )
381
+ }
382
+ return typedWatch (ctx , accessor , input )
383
+ }
384
+
353
385
func (cc * clusterCache ) GetLastProbeSuccessTimestamp (ctx context.Context , cluster client.ObjectKey ) time.Time {
354
386
accessor := cc .getClusterAccessor (cluster )
355
387
if accessor == nil {
0 commit comments