@@ -961,34 +961,28 @@ 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
979
} else {
976
- subs , updateErr := o .setSubsCond (updatedSubs , v1alpha1 .SubscriptionResolutionFailed , "" , "" , false )
977
- if updateErr != nil {
978
- logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
979
- }
980
- updatedSubs = subs
981
-
982
- // Also clear the condition from the subscriptions there were not included in the list of updatedSubs
983
- allSubs , err := o .listSubscriptions (namespace )
984
- if err != nil {
985
- logger .WithError (err ).Debug ("couldn't list subscriptions" )
986
- return err
987
- }
988
- _ , updateErr = o .setSubsCond (allSubs , v1alpha1 .SubscriptionResolutionFailed , "" , "" , false )
980
+ subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "" , "" , false )
981
+ _ , updateErr := o .updateSubscriptionStatuses (subs )
989
982
if updateErr != nil {
990
983
logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
991
984
}
985
+ updatedSubs = o .setSubsCond (updatedSubs , v1alpha1 .SubscriptionResolutionFailed , "" , "" , false )
992
986
}
993
987
994
988
// create installplan if anything updated
@@ -1020,7 +1014,8 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
1020
1014
logger .WithError (err ).Debug ("error ensuring installplan" )
1021
1015
return err
1022
1016
}
1023
- if err := o .updateSubscriptionStatus (namespace , maxGeneration + 1 , updatedSubs , installPlanReference ); err != nil {
1017
+ updatedSubs = o .setIPReference (updatedSubs , maxGeneration + 1 , installPlanReference )
1018
+ if _ , err := o .updateSubscriptionStatuses (updatedSubs ); err != nil {
1024
1019
logger .WithError (err ).Debug ("error ensuring subscription installplan state" )
1025
1020
return err
1026
1021
}
@@ -1140,12 +1135,8 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
1140
1135
return updatedSub , true , nil
1141
1136
}
1142
1137
1143
- func (o * Operator ) updateSubscriptionStatus ( namespace string , gen int , subs []* v1alpha1.Subscription , installPlanRef * corev1.ObjectReference ) error {
1138
+ func (o * Operator ) setIPReference ( subs []* v1alpha1.Subscription , gen int , installPlanRef * corev1.ObjectReference ) [] * v1alpha1. Subscription {
1144
1139
var (
1145
- errs []error
1146
- mu sync.Mutex
1147
- wg sync.WaitGroup
1148
- getOpts = metav1.GetOptions {}
1149
1140
lastUpdated = o .now ()
1150
1141
)
1151
1142
for _ , sub := range subs {
@@ -1156,33 +1147,8 @@ func (o *Operator) updateSubscriptionStatus(namespace string, gen int, subs []*v
1156
1147
sub .Status .State = v1alpha1 .SubscriptionStateUpgradePending
1157
1148
sub .Status .InstallPlanGeneration = gen
1158
1149
}
1159
-
1160
- wg .Add (1 )
1161
- go func (s v1alpha1.Subscription ) {
1162
- defer wg .Done ()
1163
-
1164
- update := func () error {
1165
- // Update the status of the latest revision
1166
- latest , err := o .client .OperatorsV1alpha1 ().Subscriptions (s .GetNamespace ()).Get (context .TODO (), s .GetName (), getOpts )
1167
- if err != nil {
1168
- return err
1169
- }
1170
-
1171
- latest .Status = s .Status
1172
- _ , err = o .client .OperatorsV1alpha1 ().Subscriptions (namespace ).UpdateStatus (context .TODO (), latest , metav1.UpdateOptions {})
1173
-
1174
- return err
1175
- }
1176
- if err := retry .RetryOnConflict (retry .DefaultRetry , update ); err != nil {
1177
- mu .Lock ()
1178
- defer mu .Unlock ()
1179
- errs = append (errs , err )
1180
- }
1181
- }(* sub )
1182
1150
}
1183
- wg .Wait ()
1184
-
1185
- return utilerrors .NewAggregate (errs )
1151
+ return subs
1186
1152
}
1187
1153
1188
1154
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 ) {
@@ -1266,13 +1232,8 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
1266
1232
return reference .GetReference (res )
1267
1233
}
1268
1234
1269
- func (o * Operator ) setSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType , reason , message string , setTrue bool ) ( []* v1alpha1.Subscription , error ) {
1235
+ func (o * Operator ) setSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType , reason , message string , setTrue bool ) []* v1alpha1.Subscription {
1270
1236
var (
1271
- errs []error
1272
- mu sync.Mutex
1273
- wg sync.WaitGroup
1274
- getOpts = metav1.GetOptions {}
1275
- updateOpts = metav1.UpdateOptions {}
1276
1237
lastUpdated = o .now ()
1277
1238
)
1278
1239
for _ , sub := range subs {
@@ -1292,7 +1253,20 @@ func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.
1292
1253
cond .Status = corev1 .ConditionFalse
1293
1254
}
1294
1255
sub .Status .SetCondition (cond )
1256
+ }
1257
+ return subs
1258
+ }
1295
1259
1260
+ func (o * Operator ) updateSubscriptionStatuses (subs []* v1alpha1.Subscription ) ([]* v1alpha1.Subscription , error ) {
1261
+ var (
1262
+ errs []error
1263
+ mu sync.Mutex
1264
+ wg sync.WaitGroup
1265
+ getOpts = metav1.GetOptions {}
1266
+ updateOpts = metav1.UpdateOptions {}
1267
+ )
1268
+
1269
+ for _ , sub := range subs {
1296
1270
wg .Add (1 )
1297
1271
go func (sub v1alpha1.Subscription ) {
1298
1272
defer wg .Done ()
@@ -1316,7 +1290,6 @@ func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.
1316
1290
}(* sub )
1317
1291
}
1318
1292
wg .Wait ()
1319
-
1320
1293
return subs , utilerrors .NewAggregate (errs )
1321
1294
}
1322
1295
0 commit comments