@@ -162,7 +162,8 @@ func (r *PatternReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
162162
163163 // -- GitOps Subscription
164164 targetSub , _ := newSubscriptionFromConfigMap (r .fullClient )
165- if operatorConfigMap , err := GetOperatorConfigmap (); err == nil {
165+ operatorConfigMap , err := GetOperatorConfigmap ()
166+ if err == nil {
166167 if err := controllerutil .SetOwnerReference (operatorConfigMap , targetSub , r .Scheme ); err != nil {
167168 return r .actionPerformed (qualifiedInstance , "error setting owner of gitops subscription" , err )
168169 }
@@ -182,7 +183,20 @@ func (r *PatternReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
182183 return r .actionPerformed (qualifiedInstance , "update gitops subscription" , errSub )
183184 }
184185 } else {
185- logOnce ("The gitops subscription is not owned by us, leaving untouched" )
186+ // Historically the subscription was owned by the pattern, not the operator. If this is the case,
187+ // we update the owner reference to the operator itself.
188+ if err := controllerutil .RemoveOwnerReference (qualifiedInstance , sub , r .Scheme ); err == nil {
189+ if err := controllerutil .SetOwnerReference (operatorConfigMap , sub , r .Scheme ); err != nil {
190+ return r .actionPerformed (qualifiedInstance , "error setting patterns operator owner reference of gitops subscription" , err )
191+ }
192+ // Persist the updated ownerReferences on the Subscription
193+ if _ , err := r .olmClient .OperatorsV1alpha1 ().Subscriptions (SubscriptionNamespace ).Update (context .Background (), sub , metav1.UpdateOptions {}); err != nil {
194+ return r .actionPerformed (qualifiedInstance , "error updating gitops subscription owner references" , err )
195+ }
196+ return r .actionPerformed (qualifiedInstance , "updated patterns operator owner reference of gitops subscription" , nil )
197+ } else {
198+ logOnce ("The gitops subscription is not owned by us, leaving untouched" )
199+ }
186200 }
187201 logOnce ("subscription found" )
188202
@@ -534,8 +548,14 @@ func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
534548 return fmt .Errorf ("updated application %q for removal" , app .Name )
535549 }
536550
537- if err := syncApplicationWithPrune (r .argoClient , app , ns ); err != nil {
538- return err
551+ if app .Status .Sync .Status == argoapi .SyncStatusCodeOutOfSync {
552+ inProgress , err := syncApplicationWithPrune (r .argoClient , app , ns )
553+ if err != nil {
554+ return err
555+ }
556+ if inProgress {
557+ return fmt .Errorf ("sync with prune and force is already in progress for application %q" , app .Name )
558+ }
539559 }
540560
541561 if haveACMHub (r ) {
0 commit comments