Skip to content

Commit 3d2e856

Browse files
committed
fix concurrent map access
1 parent 57d2dcf commit 3d2e856

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/controllers/capacityreservation/expiration/controller.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,27 @@ func (c *Controller) Reconcile(ctx context.Context) (reconcile.Result, error) {
100100
}
101101
return expiringCRs.Has(id)
102102
})
103-
errs := map[*karpv1.NodeClaim]error{}
103+
errs := make([]error, len(toDelete))
104104
workqueue.ParallelizeUntil(ctx, 10, len(toDelete), func(i int) {
105105
if err := c.kubeClient.Delete(ctx, toDelete[i]); err != nil {
106106
if apierrors.IsNotFound(err) {
107107
return
108108
}
109-
errs[ncs[i]] = err
109+
errs[i] = err
110110
return
111111
}
112112
log.FromContext(ctx).
113-
WithValues("NodeClaim", klog.KObj(ncs[i]), "capacity-reservation-id", toDelete[i].Labels[v1.LabelCapacityReservationID]).
113+
WithValues("NodeClaim", klog.KObj(toDelete[i]), "capacity-reservation-id", toDelete[i].Labels[v1.LabelCapacityReservationID]).
114114
Info("initiating delete for capacity block expiration")
115115
})
116-
if len(errs) != 0 {
116+
if lo.ContainsBy(errs, func(err error) bool { return err != nil }) {
117117
return reconcile.Result{}, serrors.Wrap(
118-
fmt.Errorf("deleting nodeclaims, %w", multierr.Combine(lo.Values(errs)...)),
119-
"NodeClaims", lo.Map(lo.Keys(errs), func(nc *karpv1.NodeClaim, _ int) klog.ObjectRef {
120-
return klog.KObj(nc)
118+
fmt.Errorf("deleting nodeclaims, %w", multierr.Combine(errs...)),
119+
"NodeClaims", lo.FilterMap(errs, func(err error, i int) (klog.ObjectRef, bool) {
120+
if err == nil {
121+
return klog.ObjectRef{}, false
122+
}
123+
return klog.KObj(toDelete[i]), true
121124
}),
122125
)
123126
}

0 commit comments

Comments
 (0)