diff --git a/pkg/controller/operators/catalog/operator.go b/pkg/controller/operators/catalog/operator.go index c26c3da927..2c07966e77 100644 --- a/pkg/controller/operators/catalog/operator.go +++ b/pkg/controller/operators/catalog/operator.go @@ -1654,12 +1654,6 @@ func (o *Operator) ensureInstallPlan(logger *logrus.Entry, namespace string, gen return nil, nil } - // Check if any existing installplans are creating the same resources - installPlans, err := o.listInstallPlans(namespace) - if err != nil { - return nil, err - } - // There are multiple(2) worker threads process the namespaceQueue. // Both worker can work at the same time when 2 separate updates are made for the namespace. // The following sequence causes 2 installplans are created for a subscription @@ -1680,6 +1674,14 @@ func (o *Operator) ensureInstallPlan(logger *logrus.Entry, namespace string, gen o.muInstallPlan.Lock() defer o.muInstallPlan.Unlock() + // Check if any existing installplans are creating the same resources + // This must be done AFTER acquiring the lock to ensure worker 2 sees + // the installplan created by worker 1 + installPlans, err := o.listInstallPlans(namespace) + if err != nil { + return nil, err + } + for _, installPlan := range installPlans { if installPlan.Spec.Generation == gen { return reference.GetReference(installPlan)