@@ -60,13 +60,22 @@ type Options struct {
60
60
// will never be created.
61
61
WatchFilterValue string
62
62
63
+ // ClusterFilter is a function that can be used to filter which clusters should be handled
64
+ // by the ClusterCache. If nil, all clusters will be handled. If set, only clusters for which
65
+ // the filter returns true will be handled.
66
+ ClusterFilter ClusterFilter
67
+
63
68
// Cache are the cache options for the caches that are created per cluster.
64
69
Cache CacheOptions
65
70
66
71
// Client are the client options for the clients that are created per cluster.
67
72
Client ClientOptions
68
73
}
69
74
75
+ // ClusterFilter is a function that filters which clusters should be handled by the ClusterCache.
76
+ // It returns true if the cluster should be handled, false otherwise.
77
+ type ClusterFilter func (cluster * clusterv1.Cluster ) bool
78
+
70
79
// CacheOptions are the cache options for the caches that are created per cluster.
71
80
type CacheOptions struct {
72
81
// SyncPeriod is the sync period of the cache.
@@ -357,6 +366,11 @@ type clusterCache struct {
357
366
358
367
// cacheCtxCancel is used during Shutdown to stop caches.
359
368
cacheCtxCancel context.CancelCauseFunc
369
+
370
+ // ClusterFilter is a function that can be used to filter which clusters should be handled
371
+ // by the ClusterCache. If nil, all clusters will be handled. If set, only clusters for which
372
+ // the filter returns true will be handled.
373
+ clusterFilter ClusterFilter
360
374
}
361
375
362
376
// clusterSource stores the necessary information so we can enqueue reconcile.Requests for reconcilers that
@@ -451,6 +465,15 @@ func (cc *clusterCache) Reconcile(ctx context.Context, req reconcile.Request) (r
451
465
return ctrl.Result {RequeueAfter : defaultRequeueAfter }, nil
452
466
}
453
467
468
+ // Apply cluster filter if set
469
+ if cc .clusterFilter != nil && ! cc .clusterFilter (cluster ) {
470
+ log .V (6 ).Info ("Cluster filtered out by ClusterFilter, not connecting" )
471
+ accessor .Disconnect (ctx )
472
+ cc .deleteClusterAccessor (clusterKey )
473
+ cc .cleanupClusterSourcesForCluster (clusterKey )
474
+ return ctrl.Result {}, nil
475
+ }
476
+
454
477
// Return if infrastructure is not ready yet to avoid trying to open a connection when it cannot succeed.
455
478
// Requeue is not needed as there will be a new reconcile.Request when Cluster.status.initialization.infrastructureProvisioned is set.
456
479
if ! ptr .Deref (cluster .Status .Initialization .InfrastructureProvisioned , false ) {
0 commit comments