@@ -961,23 +961,30 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
961
961
// not-satisfiable error
962
962
if _ , ok := err .(solver.NotSatisfiable ); ok {
963
963
logger .WithError (err ).Debug ("resolution failed" )
964
- updateErr := o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ConstraintsNotSatisfiable" , err .Error (), true )
964
+ subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ConstraintsNotSatisfiable" , err .Error (), true )
965
+ _ , updateErr := o .updateSubscriptionStatuses (subs )
965
966
if updateErr != nil {
966
967
logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
968
+ return updateErr
967
969
}
968
970
return nil
969
971
}
970
- updateErr := o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ErrorPreventedResolution" , err .Error (), true )
972
+ subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ErrorPreventedResolution" , err .Error (), true )
973
+ _ , updateErr := o .updateSubscriptionStatuses (subs )
971
974
if updateErr != nil {
972
975
logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
976
+ return updateErr
973
977
}
974
978
return err
975
- } else {
976
- updateErr := o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "" , "" , false )
979
+ }
980
+
981
+ defer func () {
982
+ subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "" , "" , false )
983
+ _ , updateErr := o .updateSubscriptionStatuses (subs )
977
984
if updateErr != nil {
978
- logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
985
+ logger .WithError (updateErr ).Warn ("failed to update subscription conditions" )
979
986
}
980
- }
987
+ }()
981
988
982
989
// create installplan if anything updated
983
990
if len (updatedSubs ) > 0 {
@@ -1008,9 +1015,13 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
1008
1015
logger .WithError (err ).Debug ("error ensuring installplan" )
1009
1016
return err
1010
1017
}
1011
- if err := o .updateSubscriptionStatus (namespace , maxGeneration + 1 , updatedSubs , installPlanReference ); err != nil {
1012
- logger .WithError (err ).Debug ("error ensuring subscription installplan state" )
1013
- return err
1018
+ updatedSubs = o .setIPReference (updatedSubs , maxGeneration + 1 , installPlanReference )
1019
+ for _ , updatedSub := range updatedSubs {
1020
+ for i , sub := range subs {
1021
+ if sub .Name == updatedSub .Name && sub .Namespace == updatedSub .Namespace {
1022
+ subs [i ] = updatedSub
1023
+ }
1024
+ }
1014
1025
}
1015
1026
} else {
1016
1027
logger .Debugf ("no subscriptions were updated" )
@@ -1128,12 +1139,8 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
1128
1139
return updatedSub , true , nil
1129
1140
}
1130
1141
1131
- func (o * Operator ) updateSubscriptionStatus ( namespace string , gen int , subs []* v1alpha1.Subscription , installPlanRef * corev1.ObjectReference ) error {
1142
+ func (o * Operator ) setIPReference ( subs []* v1alpha1.Subscription , gen int , installPlanRef * corev1.ObjectReference ) [] * v1alpha1. Subscription {
1132
1143
var (
1133
- errs []error
1134
- mu sync.Mutex
1135
- wg sync.WaitGroup
1136
- getOpts = metav1.GetOptions {}
1137
1144
lastUpdated = o .now ()
1138
1145
)
1139
1146
for _ , sub := range subs {
@@ -1144,33 +1151,8 @@ func (o *Operator) updateSubscriptionStatus(namespace string, gen int, subs []*v
1144
1151
sub .Status .State = v1alpha1 .SubscriptionStateUpgradePending
1145
1152
sub .Status .InstallPlanGeneration = gen
1146
1153
}
1147
-
1148
- wg .Add (1 )
1149
- go func (s v1alpha1.Subscription ) {
1150
- defer wg .Done ()
1151
-
1152
- update := func () error {
1153
- // Update the status of the latest revision
1154
- latest , err := o .client .OperatorsV1alpha1 ().Subscriptions (s .GetNamespace ()).Get (context .TODO (), s .GetName (), getOpts )
1155
- if err != nil {
1156
- return err
1157
- }
1158
-
1159
- latest .Status = s .Status
1160
- _ , err = o .client .OperatorsV1alpha1 ().Subscriptions (namespace ).UpdateStatus (context .TODO (), latest , metav1.UpdateOptions {})
1161
-
1162
- return err
1163
- }
1164
- if err := retry .RetryOnConflict (retry .DefaultRetry , update ); err != nil {
1165
- mu .Lock ()
1166
- defer mu .Unlock ()
1167
- errs = append (errs , err )
1168
- }
1169
- }(* sub )
1170
1154
}
1171
- wg .Wait ()
1172
-
1173
- return utilerrors .NewAggregate (errs )
1155
+ return subs
1174
1156
}
1175
1157
1176
1158
func (o * Operator ) ensureInstallPlan (logger * logrus.Entry , namespace string , gen int , subs []* v1alpha1.Subscription , installPlanApproval v1alpha1.Approval , steps []* v1alpha1.Step , bundleLookups []v1alpha1.BundleLookup ) (* corev1.ObjectReference , error ) {
@@ -1254,13 +1236,8 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
1254
1236
return reference .GetReference (res )
1255
1237
}
1256
1238
1257
- func (o * Operator ) setSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType , reason , message string , setTrue bool ) error {
1239
+ func (o * Operator ) setSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType , reason , message string , setTrue bool ) [] * v1alpha1. Subscription {
1258
1240
var (
1259
- errs []error
1260
- mu sync.Mutex
1261
- wg sync.WaitGroup
1262
- getOpts = metav1.GetOptions {}
1263
- updateOpts = metav1.UpdateOptions {}
1264
1241
lastUpdated = o .now ()
1265
1242
)
1266
1243
for _ , sub := range subs {
@@ -1274,33 +1251,44 @@ func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.
1274
1251
cond .Status = corev1 .ConditionFalse
1275
1252
}
1276
1253
sub .Status .SetCondition (cond )
1254
+ }
1255
+ return subs
1256
+ }
1257
+
1258
+ func (o * Operator ) updateSubscriptionStatuses (subs []* v1alpha1.Subscription ) ([]* v1alpha1.Subscription , error ) {
1259
+ var (
1260
+ errs []error
1261
+ mu sync.Mutex
1262
+ wg sync.WaitGroup
1263
+ getOpts = metav1.GetOptions {}
1264
+ updateOpts = metav1.UpdateOptions {}
1265
+ )
1277
1266
1267
+ for _ , sub := range subs {
1278
1268
wg .Add (1 )
1279
- go func (s v1alpha1.Subscription ) {
1269
+ go func (sub * v1alpha1.Subscription ) {
1280
1270
defer wg .Done ()
1281
1271
1282
1272
update := func () error {
1283
1273
// Update the status of the latest revision
1284
- latest , err := o .client .OperatorsV1alpha1 ().Subscriptions (s .GetNamespace ()).Get (context .TODO (), s .GetName (), getOpts )
1274
+ latest , err := o .client .OperatorsV1alpha1 ().Subscriptions (sub .GetNamespace ()).Get (context .TODO (), sub .GetName (), getOpts )
1285
1275
if err != nil {
1286
1276
return err
1287
1277
}
1288
-
1289
- latest .Status = s .Status
1290
- _ , err = o .client .OperatorsV1alpha1 ().Subscriptions (s .Namespace ).UpdateStatus (context .TODO (), latest , updateOpts )
1291
-
1278
+ latest .Status = sub .Status
1279
+ * sub = * latest
1280
+ _ , err = o .client .OperatorsV1alpha1 ().Subscriptions (sub .Namespace ).UpdateStatus (context .TODO (), latest , updateOpts )
1292
1281
return err
1293
1282
}
1294
1283
if err := retry .RetryOnConflict (retry .DefaultRetry , update ); err != nil {
1295
1284
mu .Lock ()
1296
1285
defer mu .Unlock ()
1297
1286
errs = append (errs , err )
1298
1287
}
1299
- }(* sub )
1288
+ }(sub )
1300
1289
}
1301
1290
wg .Wait ()
1302
-
1303
- return utilerrors .NewAggregate (errs )
1291
+ return subs , utilerrors .NewAggregate (errs )
1304
1292
}
1305
1293
1306
1294
type UnpackedBundleReference struct {
0 commit comments