Skip to content

Commit 72ec216

Browse files
committed
use source.Kind generics
1 parent b6fcb62 commit 72ec216

File tree

5 files changed

+36
-36
lines changed

5 files changed

+36
-36
lines changed

controllers/gcpcluster_controller.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,27 @@ func (r *GCPClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
7474

7575
clusterToInfraFn := util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("GCPCluster"), mgr.GetClient(), &infrav1.GCPCluster{})
7676
if err = c.Watch(
77-
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
78-
handler.EnqueueRequestsFromMapFunc(func(mapCtx context.Context, o client.Object) []reconcile.Request {
79-
requests := clusterToInfraFn(mapCtx, o)
80-
if requests == nil {
81-
return nil
82-
}
77+
source.Kind[client.Object](mgr.GetCache(), &clusterv1.Cluster{},
78+
handler.EnqueueRequestsFromMapFunc(func(mapCtx context.Context, o client.Object) []reconcile.Request {
79+
requests := clusterToInfraFn(mapCtx, o)
80+
if requests == nil {
81+
return nil
82+
}
8383

84-
gcpCluster := &infrav1.GCPCluster{}
85-
if err := r.Get(ctx, requests[0].NamespacedName, gcpCluster); err != nil {
86-
log.V(4).Error(err, "Failed to get GCP cluster")
87-
return nil
88-
}
84+
gcpCluster := &infrav1.GCPCluster{}
85+
if err := r.Get(ctx, requests[0].NamespacedName, gcpCluster); err != nil {
86+
log.V(4).Error(err, "Failed to get GCP cluster")
87+
return nil
88+
}
8989

90-
if annotations.IsExternallyManaged(gcpCluster) {
91-
log.V(4).Info("GCPCluster is externally managed, skipping mapping.")
92-
return nil
93-
}
94-
return requests
95-
}),
96-
predicates.ClusterUnpaused(log),
97-
); err != nil {
90+
if annotations.IsExternallyManaged(gcpCluster) {
91+
log.V(4).Info("GCPCluster is externally managed, skipping mapping.")
92+
return nil
93+
}
94+
return requests
95+
}),
96+
predicates.ClusterUnpaused(log),
97+
)); err != nil {
9898
return errors.Wrap(err, "failed adding a watch for ready clusters")
9999
}
100100

controllers/gcpmachine_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func (r *GCPMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
8181

8282
// Add a watch on clusterv1.Cluster object for unpause & ready notifications.
8383
if err := c.Watch(
84-
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
85-
handler.EnqueueRequestsFromMapFunc(clusterToObjectFunc),
86-
predicates.ClusterUnpausedAndInfrastructureReady(log),
87-
); err != nil {
84+
source.Kind[client.Object](mgr.GetCache(), &clusterv1.Cluster{},
85+
handler.EnqueueRequestsFromMapFunc(clusterToObjectFunc),
86+
predicates.ClusterUnpausedAndInfrastructureReady(log),
87+
)); err != nil {
8888
return errors.Wrap(err, "failed adding a watch for ready clusters")
8989
}
9090

exp/controllers/gcpmanagedcluster_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ func (r *GCPManagedClusterReconciler) SetupWithManager(ctx context.Context, mgr
156156
}
157157

158158
if err = c.Watch(
159-
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
160-
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1exp.GroupVersion.WithKind("GCPManagedCluster"), mgr.GetClient(), &infrav1exp.GCPManagedCluster{})),
161-
predicates.ClusterUnpaused(log),
162-
predicates.ResourceNotPausedAndHasFilterLabel(log, r.WatchFilterValue),
163-
); err != nil {
159+
source.Kind[client.Object](mgr.GetCache(), &clusterv1.Cluster{},
160+
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1exp.GroupVersion.WithKind("GCPManagedCluster"), mgr.GetClient(), &infrav1exp.GCPManagedCluster{})),
161+
predicates.ClusterUnpaused(log),
162+
predicates.ResourceNotPausedAndHasFilterLabel(log, r.WatchFilterValue),
163+
)); err != nil {
164164
return fmt.Errorf("adding watch for ready clusters: %v", err)
165165
}
166166

exp/controllers/gcpmanagedcontrolplane_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ func (r *GCPManagedControlPlaneReconciler) SetupWithManager(ctx context.Context,
7474
}
7575

7676
if err = c.Watch(
77-
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
78-
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, gcpManagedControlPlane.GroupVersionKind(), mgr.GetClient(), &infrav1exp.GCPManagedControlPlane{})),
79-
predicates.ClusterUnpausedAndInfrastructureReady(log),
80-
); err != nil {
77+
source.Kind[client.Object](mgr.GetCache(), &clusterv1.Cluster{},
78+
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, gcpManagedControlPlane.GroupVersionKind(), mgr.GetClient(), &infrav1exp.GCPManagedControlPlane{})),
79+
predicates.ClusterUnpausedAndInfrastructureReady(log),
80+
)); err != nil {
8181
return fmt.Errorf("failed adding a watch for ready clusters: %w", err)
8282
}
8383

exp/controllers/gcpmanagedmachinepool_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ func (r *GCPManagedMachinePoolReconciler) SetupWithManager(ctx context.Context,
178178

179179
// Add a watch on clusterv1.Cluster object for unpause & ready notifications.
180180
if err := c.Watch(
181-
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
182-
handler.EnqueueRequestsFromMapFunc(clusterToObjectFunc),
183-
predicates.ClusterUnpausedAndInfrastructureReady(log),
184-
); err != nil {
181+
source.Kind[client.Object](mgr.GetCache(), &clusterv1.Cluster{},
182+
handler.EnqueueRequestsFromMapFunc(clusterToObjectFunc),
183+
predicates.ClusterUnpausedAndInfrastructureReady(log),
184+
)); err != nil {
185185
return errors.Wrap(err, "failed adding a watch for ready clusters")
186186
}
187187

0 commit comments

Comments
 (0)