Skip to content

Commit

Permalink
Merge pull request #701 from pierrecregut/fix_defer
Browse files Browse the repository at this point in the history
🐛 Fix ignored errors while patching resources
  • Loading branch information
metal3-io-bot authored Oct 16, 2024
2 parents ded724e + 2379fb4 commit 99664dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions controllers/ippool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (r *IPPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ c
err := helper.Patch(ctx, ipamv1IPPool)
if err != nil {
metadataLog.Info("failed to Patch ipamv1IPPool")
rerr = err
}
}()

Expand Down
8 changes: 7 additions & 1 deletion ipam/ippool_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,21 @@ func (m *IPPoolManager) UpdateAddresses(ctx context.Context) (int, error) {

func (m *IPPoolManager) updateAddress(ctx context.Context,
addressClaim *ipamv1.IPClaim, addresses map[ipamv1.IPAddressStr]string,
) (map[ipamv1.IPAddressStr]string, error) {
) (_ map[ipamv1.IPAddressStr]string, rerr error) {
helper, err := patch.NewHelper(addressClaim, m.client)
if err != nil {
return addresses, errors.Wrap(err, "failed to init patch helper")
}
deleted := false
// Always patch addressClaim exiting this function so we can persist any changes.
defer func() {
if deleted {
return
}
err := helper.Patch(ctx, addressClaim)
if err != nil {
m.Log.Error(err, "failed to Patch IPClaim")
rerr = err
}
}()

Expand All @@ -243,6 +248,7 @@ func (m *IPPoolManager) updateAddress(ctx context.Context,
if err != nil {
return addresses, err
}
deleted = true
}
return addresses, nil
}
Expand Down

0 comments on commit 99664dd

Please sign in to comment.