Skip to content

Commit

Permalink
fix: concurrent map writes when replicating namespaced objects
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Tranchitella <[email protected]>
  • Loading branch information
prometherion committed Nov 29, 2024
1 parent 1d53811 commit 7f0786b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions controllers/resources/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ func (r *Processor) HandleSection(ctx context.Context, tnt capsulev1beta2.Tenant

objLabels[Label] = fmt.Sprintf("%d", resourceIndex)
objLabels[tenantLabel] = tnt.GetName()

// processedRaw is used to avoid concurrent map writes during iteration of namespaced items:
// the objects will be then added to processed variable.
//
// processed will contain the sets of resources replicated, both for the raw and the Namespaced ones:
// these are required to perform a final pruning once the replication has been occurred.
processed := sets.NewString()
processedRaw, processed := []string{}, sets.NewString()

tntNamespaces := sets.NewString(tnt.Status.Namespaces...)

Expand Down Expand Up @@ -204,7 +206,7 @@ func (r *Processor) HandleSection(ctx context.Context, tnt capsulev1beta2.Tenant
replicatedItem.Namespace = ns.Name
replicatedItem.APIVersion = obj.GetAPIVersion()

processed.Insert(replicatedItem.String())
processedRaw = append(processedRaw, replicatedItem.String())
}(obj)
}

Expand All @@ -218,6 +220,8 @@ func (r *Processor) HandleSection(ctx context.Context, tnt capsulev1beta2.Tenant
}
}

processed.Insert(processedRaw...)

for rawIndex, item := range spec.RawItems {
template := string(item.Raw)

Expand Down

0 comments on commit 7f0786b

Please sign in to comment.