@@ -1477,25 +1477,30 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
14771477 o .removeSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed )
14781478
14791479 for _ , updatedSub := range updatedSubs {
1480- newSub := true
1480+ isNewSub := true
14811481 updatedSub .Status .RemoveConditions (v1alpha1 .SubscriptionResolutionFailed )
14821482 for i , sub := range subs {
14831483 if sub .Name == updatedSub .Name && sub .Namespace == updatedSub .Namespace {
14841484 subs [i ] = updatedSub
1485- newSub = false
1485+ isNewSub = false
14861486 break
14871487 }
14881488 }
1489- if newSub {
1489+ if isNewSub {
14901490 subs = append (subs , updatedSub )
1491- continue
14921491 }
14931492 }
14941493
1494+ // *********************************** WARNING *********************************** //
1495+ // if updateSubscriptionStatuses call fails and the IP reference was changed //
1496+ // in this run, we'll be screwed because the IP would have been created but the //
1497+ // subscription won't carry its reference. And, if the CSV gets created by the IP, //
1498+ // it won't be associated with the Subscription -> perma-failure on resolution //
1499+ // ******************************************************************************* //
14951500 // Update subscriptions with all changes so far
14961501 _ , updateErr := o .updateSubscriptionStatuses (subs )
14971502 if updateErr != nil {
1498- logger .WithError (updateErr ).Warn ("failed to update subscription conditions" )
1503+ logger .WithField ( "irreconcilable-resolution" , namespace ). WithError (updateErr ).Warn ("failed to patch subscription conditions" )
14991504 return updateErr
15001505 }
15011506
@@ -1667,15 +1672,19 @@ func (o *Operator) ensureInstallPlan(logger *logrus.Entry, namespace string, gen
16671672 }
16681673 logger .Warn ("no installplan found with matching generation, creating new one" )
16691674
1670- return o .createInstallPlan (namespace , gen , subs , installPlanApproval , steps , bundleLookups )
1675+ ip , err := o .createInstallPlan (namespace , gen , subs , installPlanApproval , steps , bundleLookups )
1676+ if err != nil {
1677+ return nil , err
1678+ }
1679+ return reference .GetReference (ip )
16711680}
16721681
16731682func (o * Operator ) createInstallPlan (namespace string , gen int , subs []* v1alpha1.Subscription , installPlanApproval v1alpha1.Approval , steps []* v1alpha1.Step , bundleLookups []v1alpha1.BundleLookup ) (* corev1.ObjectReference , error ) {
16741683 if len (steps ) == 0 && len (bundleLookups ) == 0 {
16751684 return nil , nil
16761685 }
16771686
1678- csvNames := []string {}
1687+ var csvNames []string
16791688 catalogSourceMap := map [string ]struct {}{}
16801689 for _ , s := range steps {
16811690 if s .Resource .Kind == "ClusterServiceVersion" {
@@ -1684,7 +1693,7 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
16841693 catalogSourceMap [s .Resource .CatalogSource ] = struct {}{}
16851694 }
16861695
1687- catalogSources := []string {}
1696+ var catalogSources []string
16881697 for s := range catalogSourceMap {
16891698 catalogSources = append (catalogSources , s )
16901699 }
@@ -1720,12 +1729,18 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
17201729 CatalogSources : catalogSources ,
17211730 BundleLookups : bundleLookups ,
17221731 }
1723- res , err = o .client .OperatorsV1alpha1 ().InstallPlans (namespace ).UpdateStatus (context .TODO (), res , metav1.UpdateOptions {})
1732+
1733+ // *************************** WARNING *************************** //
1734+ // If this call fails, the IP will never do anything since it //
1735+ // requires the steps to exist in .status //
1736+ // *************************************************************** //
1737+ newRes , err := o .client .OperatorsV1alpha1 ().InstallPlans (namespace ).UpdateStatus (context .TODO (), res , metav1.UpdateOptions {})
17241738 if err != nil {
1739+ o .logger .WithField ("irreconcilable-ip" , res .GetName ()).WithError (err ).Warn ("error updating installplan status after creation" )
17251740 return nil , err
17261741 }
17271742
1728- return reference .GetReference (res )
1743+ return reference .GetReference (newRes )
17291744}
17301745
17311746// setSubsCond will set the condition to the subscription if it doesn't already
@@ -1749,7 +1764,7 @@ func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, cond v1alpha1.Subs
17491764 return subList
17501765}
17511766
1752- // removeSubsCond removes the given condition from all of the subscriptions in the input
1767+ // removeSubsCond removes the given condition from all the subscriptions in the input
17531768func (o * Operator ) removeSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType ) {
17541769 lastUpdated := o .now ()
17551770 for _ , sub := range subs {
0 commit comments