Skip to content

Commit 414c623

Browse files
committed
Add typing to controller runtime calls
Signed-off-by: Nolan Brubaker <[email protected]>
1 parent 2604140 commit 414c623

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

pkg/controller/machine/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ func addWithOpts(mgr manager.Manager, opts controller.Options, controllerName st
123123

124124
// Watch for changes to Machine
125125
return c.Watch(
126-
source.Kind(mgr.GetCache(), &machinev1.Machine{}),
127-
&handler.EnqueueRequestForObject{},
128-
)
126+
source.Kind(mgr.GetCache(), &machinev1.Machine{},
127+
&handler.TypedEnqueueRequestForObject[*machinev1.Machine]{},
128+
))
129129
}
130130

131131
// ReconcileMachine reconciles a Machine object

pkg/controller/machinehealthcheck/machinehealthcheck_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,23 @@ func indexMachineByNodeName(object client.Object) []string {
121121
}
122122

123123
// add adds a new Controller to mgr with r as the reconcile.Reconciler
124-
func add(mgr manager.Manager, r reconcile.Reconciler, mapMachineToMHC, mapNodeToMHC handler.MapFunc) error {
124+
func add(mgr manager.Manager, r reconcile.Reconciler, mapMachineToMHC handler.TypedMapFunc[*machinev1.Machine], mapNodeToMHC handler.TypedMapFunc[*corev1.Node]) error {
125125
c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r})
126126
if err != nil {
127127
return err
128128
}
129129

130-
err = c.Watch(source.Kind(mgr.GetCache(), &machinev1.MachineHealthCheck{}), &handler.EnqueueRequestForObject{})
130+
err = c.Watch(source.Kind(mgr.GetCache(), &machinev1.MachineHealthCheck{}, &handler.TypedEnqueueRequestForObject[*machinev1.MachineHealthCheck]{}))
131131
if err != nil {
132132
return err
133133
}
134134

135-
err = c.Watch(source.Kind(mgr.GetCache(), &machinev1.Machine{}), handler.EnqueueRequestsFromMapFunc(mapMachineToMHC))
135+
err = c.Watch(source.Kind(mgr.GetCache(), &machinev1.Machine{}, handler.TypedEnqueueRequestsFromMapFunc[*machinev1.Machine](mapMachineToMHC)))
136136
if err != nil {
137137
return err
138138
}
139139

140-
return c.Watch(source.Kind(mgr.GetCache(), &corev1.Node{}), handler.EnqueueRequestsFromMapFunc(mapNodeToMHC))
140+
return c.Watch(source.Kind(mgr.GetCache(), &corev1.Node{}, handler.TypedEnqueueRequestsFromMapFunc[*corev1.Node](mapNodeToMHC)))
141141
}
142142

143143
var _ reconcile.Reconciler = &ReconcileMachineHealthCheck{}
@@ -561,7 +561,7 @@ func (r *ReconcileMachineHealthCheck) getMachineFromNode(nodeName string) (*mach
561561
return &machineList.Items[0], nil
562562
}
563563

564-
func (r *ReconcileMachineHealthCheck) mhcRequestsFromNode(ctx context.Context, o client.Object) []reconcile.Request {
564+
func (r *ReconcileMachineHealthCheck) mhcRequestsFromNode(ctx context.Context, o *corev1.Node) []reconcile.Request {
565565
klog.V(4).Infof("Getting MHC requests from node %q", namespacedName(o).String())
566566
node := &corev1.Node{}
567567
if err := r.client.Get(ctx, namespacedName(o), node); err != nil {
@@ -595,7 +595,7 @@ func (r *ReconcileMachineHealthCheck) mhcRequestsFromNode(ctx context.Context, o
595595
return requests
596596
}
597597

598-
func (r *ReconcileMachineHealthCheck) mhcRequestsFromMachine(ctx context.Context, o client.Object) []reconcile.Request {
598+
func (r *ReconcileMachineHealthCheck) mhcRequestsFromMachine(ctx context.Context, o *machinev1.Machine) []reconcile.Request {
599599
klog.V(4).Infof("Getting MHC requests from machine %q", namespacedName(o).String())
600600
machine := &machinev1.Machine{}
601601
if err := r.client.Get(ctx,

pkg/controller/machineset/controller.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func newReconciler(mgr manager.Manager) *ReconcileMachineSet {
7171
}
7272

7373
// add adds a new Controller to mgr with r as the reconcile.Reconciler.
74-
func add(mgr manager.Manager, r reconcile.Reconciler, mapFn handler.MapFunc) error {
74+
func add(mgr manager.Manager, r reconcile.Reconciler, mapFn handler.TypedMapFunc[*machinev1.Machine]) error {
7575
// Create a new controller.
7676
c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r})
7777
if err != nil {
@@ -80,27 +80,27 @@ func add(mgr manager.Manager, r reconcile.Reconciler, mapFn handler.MapFunc) err
8080

8181
// Watch for changes to MachineSet.
8282
err = c.Watch(
83-
source.Kind(mgr.GetCache(), &machinev1.MachineSet{}),
84-
&handler.EnqueueRequestForObject{},
85-
)
83+
source.Kind(mgr.GetCache(), &machinev1.MachineSet{},
84+
&handler.TypedEnqueueRequestForObject[*machinev1.MachineSet]{},
85+
))
8686
if err != nil {
8787
return err
8888
}
8989

9090
// Map Machine changes to MachineSets using ControllerRef.
9191
err = c.Watch(
92-
source.Kind(mgr.GetCache(), &machinev1.Machine{}),
93-
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &machinev1.MachineSet{}, handler.OnlyControllerOwner()),
94-
)
92+
source.Kind(mgr.GetCache(), &machinev1.Machine{},
93+
handler.TypedEnqueueRequestForOwner[*machinev1.Machine](mgr.GetScheme(), mgr.GetRESTMapper(), &machinev1.MachineSet{}, handler.OnlyControllerOwner()),
94+
))
9595
if err != nil {
9696
return err
9797
}
9898

9999
// Map Machine changes to MachineSets by machining labels.
100100
return c.Watch(
101-
source.Kind(mgr.GetCache(), &machinev1.Machine{}),
102-
handler.EnqueueRequestsFromMapFunc(mapFn),
103-
)
101+
source.Kind(mgr.GetCache(), &machinev1.Machine{},
102+
handler.TypedEnqueueRequestsFromMapFunc[*machinev1.Machine](mapFn),
103+
))
104104
}
105105

106106
// ReconcileMachineSet reconciles a MachineSet object
@@ -110,7 +110,7 @@ type ReconcileMachineSet struct {
110110
recorder record.EventRecorder
111111
}
112112

113-
func (r *ReconcileMachineSet) MachineToMachineSets(ctx context.Context, o client.Object) []reconcile.Request {
113+
func (r *ReconcileMachineSet) MachineToMachineSets(ctx context.Context, o *machinev1.Machine) []reconcile.Request {
114114
result := []reconcile.Request{}
115115
m := &machinev1.Machine{}
116116
key := client.ObjectKey{Namespace: o.GetNamespace(), Name: o.GetName()}

pkg/controller/machineset/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestMachineSetToMachines(t *testing.T) {
109109
}
110110
testsCases := []struct {
111111
machine machinev1.Machine
112-
object client.Object
112+
object *machinev1.Machine
113113
expected []reconcile.Request
114114
}{
115115
{

pkg/controller/nodelink/nodelink_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,21 @@ func newReconciler(mgr manager.Manager) (*ReconcileNodeLink, error) {
161161
}
162162

163163
// add adds a new Controller to mgr with r as the reconcile.Reconciler
164-
func add(mgr manager.Manager, r reconcile.Reconciler, mapFn handler.MapFunc) error {
164+
func add(mgr manager.Manager, r reconcile.Reconciler, mapFn handler.TypedMapFunc[*machinev1.Machine]) error {
165165
// Create a new controller
166166
c, err := controller.New("nodelink-controller", mgr, controller.Options{Reconciler: r})
167167
if err != nil {
168168
return err
169169
}
170170

171171
//Watch for changes to Node
172-
err = c.Watch(source.Kind(mgr.GetCache(), &corev1.Node{}), &handler.EnqueueRequestForObject{})
172+
err = c.Watch(source.Kind(mgr.GetCache(), &corev1.Node{}, &handler.TypedEnqueueRequestForObject[*corev1.Node]{}))
173173
if err != nil {
174174
return err
175175
}
176176

177177
// Watch for changes to Machines and enqueue if it exists the backed node
178-
err = c.Watch(source.Kind(mgr.GetCache(), &machinev1.Machine{}), handler.EnqueueRequestsFromMapFunc(mapFn))
178+
err = c.Watch(source.Kind(mgr.GetCache(), &machinev1.Machine{}, handler.TypedEnqueueRequestsFromMapFunc[*machinev1.Machine](mapFn)))
179179
if err != nil {
180180
return err
181181
}
@@ -290,7 +290,7 @@ func (r *ReconcileNodeLink) updateNodeRef(machine *machinev1.Machine, node *core
290290
}
291291

292292
// nodeRequestFromMachine returns a reconcile.request for the node backed by the received machine
293-
func (r *ReconcileNodeLink) nodeRequestFromMachine(ctx context.Context, o client.Object) []reconcile.Request {
293+
func (r *ReconcileNodeLink) nodeRequestFromMachine(ctx context.Context, o *machinev1.Machine) []reconcile.Request {
294294
klog.V(3).Infof("Watched machine event, finding node to reconcile.Request")
295295
// get machine
296296
machine := &machinev1.Machine{}

0 commit comments

Comments
 (0)