Skip to content

Commit fe101a6

Browse files
put mutex around installplan creation (#2545)
Signed-off-by: akihikokuroda <[email protected]>
1 parent b7c918e commit fe101a6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/controller/operators/catalog/operator.go

+21
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type Operator struct {
116116
installPlanTimeout time.Duration
117117
bundleUnpackTimeout time.Duration
118118
clientFactory clients.Factory
119+
muInstallPlan sync.Mutex
119120
}
120121

121122
type CatalogSourceSyncFunc func(logger *logrus.Entry, in *v1alpha1.CatalogSource) (out *v1alpha1.CatalogSource, continueSync bool, syncError error)
@@ -1167,6 +1168,26 @@ func (o *Operator) ensureInstallPlan(logger *logrus.Entry, namespace string, gen
11671168
return nil, err
11681169
}
11691170

1171+
// There are multiple(2) worker threads process the namespaceQueue.
1172+
// Both worker can work at the same time when 2 separate updates are made for the namespace.
1173+
// The following sequence causes 2 installplans are created for a subscription
1174+
// 1. worker 1 doesn't find the installplan
1175+
// 2. worker 2 doesn't find the installplan
1176+
// 3. both worker 1 and 2 create the installplan
1177+
//
1178+
// This lock prevents the step 2 in the sequence so that only one installplan is created for a subscription.
1179+
// The sequence is like the following with this lock
1180+
// 1. worker 1 locks
1181+
// 2. worker 1 doesn't find the installplan
1182+
// 3. worker 2 wait for unlock <--- difference
1183+
// 4. worker 1 creates the installplan
1184+
// 5. worker 1 unlocks
1185+
// 6. worker 2 locks
1186+
// 7. worker 2 finds the installplan <--- difference
1187+
// 8. worker 2 unlocks
1188+
o.muInstallPlan.Lock()
1189+
defer o.muInstallPlan.Unlock()
1190+
11701191
for _, installPlan := range installPlans {
11711192
if installPlan.Spec.Generation == gen {
11721193
return reference.GetReference(installPlan)

0 commit comments

Comments
 (0)