Skip to content

Commit d3b12c9

Browse files
authored
machine: use patch.NewHelper instead of client.Update() in takeHardwareOwnership() (#511)
- should reduce contention on the Hardware object - avoids relying on the github.com/tinkerbell/tinkerbell/api version for the Hardware structure too much Signed-off-by: Ricardo Pardini <[email protected]>
2 parents 6159960 + e54a134 commit d3b12c9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

controller/machine/hardware.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ func (scope *machineReconcileScope) patchHardwareAnnotations(hw *tinkv1.Hardware
9696
}
9797

9898
func (scope *machineReconcileScope) takeHardwareOwnership(hw *tinkv1.Hardware) error {
99-
if len(hw.Labels) == 0 {
99+
patchHelper, err := patch.NewHelper(hw, scope.client)
100+
if err != nil {
101+
return fmt.Errorf("initializing patch helper for selected hardware: %w", err)
102+
}
103+
104+
if hw.Labels == nil {
100105
hw.Labels = map[string]string{}
101106
}
102107

@@ -106,8 +111,8 @@ func (scope *machineReconcileScope) takeHardwareOwnership(hw *tinkv1.Hardware) e
106111
// Add finalizer to hardware as well to make sure we release it before Machine object is removed.
107112
controllerutil.AddFinalizer(hw, infrastructurev1.MachineFinalizer)
108113

109-
if err := scope.client.Update(scope.ctx, hw); err != nil {
110-
return fmt.Errorf("updating Hardware object: %w", err)
114+
if err := patchHelper.Patch(scope.ctx, hw); err != nil {
115+
return fmt.Errorf("patching Hardware object: %w", err)
111116
}
112117

113118
return nil

0 commit comments

Comments
 (0)