From f9bf6222609e7fac1b27f644a5895938fc76c685 Mon Sep 17 00:00:00 2001 From: Ryan Zhang Date: Thu, 12 Oct 2023 08:35:24 -0700 Subject: [PATCH] fix race --- pkg/controllers/workgenerator/controller.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/controllers/workgenerator/controller.go b/pkg/controllers/workgenerator/controller.go index a2a598b5f..c198b38d3 100644 --- a/pkg/controllers/workgenerator/controller.go +++ b/pkg/controllers/workgenerator/controller.go @@ -272,6 +272,7 @@ func (r *Reconciler) syncAllWork(ctx context.Context, resourceBinding *fleetv1be if err != nil { return false, err } + activeWork[work.Name] = work newWork = append(newWork, work) } else { simpleManifests = append(simpleManifests, fleetv1beta1.Manifest(selectedResource)) @@ -279,16 +280,17 @@ func (r *Reconciler) syncAllWork(ctx context.Context, resourceBinding *fleetv1be } if len(simpleManifests) != 0 { // generate a work object for the manifests if there are still any non enveloped resources - newWork = append(newWork, generateSnapshotWorkObj(workNamePrefix, resourceBinding, snapshot, simpleManifests)) + work := generateSnapshotWorkObj(workNamePrefix, resourceBinding, snapshot, simpleManifests) + activeWork[work.Name] = work + newWork = append(newWork, work) } else { klog.V(2).InfoS("the snapshot contains enveloped resource only", "snapshot", klog.KObj(snapshot)) } // issue all the create/update requests for the corresponding works for each snapshot in parallel for i := range newWork { work := newWork[i] - activeWork[work.Name] = work errs.Go(func() error { - updated, err := r.upsertWork(cctx, work, existingWorks[work.Name], snapshot) + updated, err := r.upsertWork(cctx, work, existingWorks[work.Name].DeepCopy(), snapshot) if err != nil { return err }