@@ -962,31 +962,34 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
962
962
// not-satisfiable error
963
963
if _ , ok := err .(solver.NotSatisfiable ); ok {
964
964
logger .WithError (err ).Debug ("resolution failed" )
965
- subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ConstraintsNotSatisfiable" , err .Error (), true )
966
- _ , updateErr := o .updateSubscriptionStatuses (subs )
965
+ _ , updateErr := o .updateSubscriptionStatuses (
966
+ o .setSubsCond (subs , v1alpha1.SubscriptionCondition {
967
+ Type : v1alpha1 .SubscriptionResolutionFailed ,
968
+ Reason : "ConstraintsNotSatisfiable" ,
969
+ Message : err .Error (),
970
+ Status : corev1 .ConditionTrue ,
971
+ }))
967
972
if updateErr != nil {
968
973
logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
969
974
return updateErr
970
975
}
971
976
return nil
972
977
}
973
- subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ErrorPreventedResolution" , err .Error (), true )
974
- _ , updateErr := o .updateSubscriptionStatuses (subs )
978
+
979
+ _ , updateErr := o .updateSubscriptionStatuses (
980
+ o .setSubsCond (subs , v1alpha1.SubscriptionCondition {
981
+ Type : v1alpha1 .SubscriptionResolutionFailed ,
982
+ Reason : "ErrorPreventedResolution" ,
983
+ Message : err .Error (),
984
+ Status : corev1 .ConditionTrue ,
985
+ }))
975
986
if updateErr != nil {
976
987
logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
977
988
return updateErr
978
989
}
979
990
return err
980
991
}
981
992
982
- defer func () {
983
- subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "" , "" , false )
984
- _ , updateErr := o .updateSubscriptionStatuses (subs )
985
- if updateErr != nil {
986
- logger .WithError (updateErr ).Warn ("failed to update subscription conditions" )
987
- }
988
- }()
989
-
990
993
// create installplan if anything updated
991
994
if len (updatedSubs ) > 0 {
992
995
logger .Debug ("resolution caused subscription changes, creating installplan" )
@@ -1017,17 +1020,36 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
1017
1020
return err
1018
1021
}
1019
1022
updatedSubs = o .setIPReference (updatedSubs , maxGeneration + 1 , installPlanReference )
1020
- for _ , updatedSub := range updatedSubs {
1021
- for i , sub := range subs {
1022
- if sub .Name == updatedSub .Name && sub .Namespace == updatedSub .Namespace {
1023
- subs [i ] = updatedSub
1024
- }
1025
- }
1026
- }
1027
1023
} else {
1028
1024
logger .Debugf ("no subscriptions were updated" )
1029
1025
}
1030
1026
1027
+ // Remove resolutionfailed condition from subscriptions
1028
+ subs = o .removeSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed )
1029
+ newSub := true
1030
+ for _ , updatedSub := range updatedSubs {
1031
+ updatedSub .Status .RemoveConditions (v1alpha1 .SubscriptionResolutionFailed )
1032
+ for i , sub := range subs {
1033
+ if sub .Name == updatedSub .Name && sub .Namespace == updatedSub .Namespace {
1034
+ subs [i ] = updatedSub
1035
+ newSub = false
1036
+ break
1037
+ }
1038
+ }
1039
+ if newSub {
1040
+ subs = append (subs , updatedSub )
1041
+ continue
1042
+ }
1043
+ newSub = true
1044
+ }
1045
+
1046
+ // Update subscriptions with all changes so far
1047
+ _ , updateErr := o .updateSubscriptionStatuses (subs )
1048
+ if updateErr != nil {
1049
+ logger .WithError (updateErr ).Warn ("failed to update subscription conditions" )
1050
+ return updateErr
1051
+ }
1052
+
1031
1053
return nil
1032
1054
}
1033
1055
@@ -1084,12 +1106,7 @@ func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub
1084
1106
out .Status .CurrentCSV = out .Spec .StartingCSV
1085
1107
out .Status .LastUpdated = o .now ()
1086
1108
1087
- updated , err := o .client .OperatorsV1alpha1 ().Subscriptions (sub .GetNamespace ()).UpdateStatus (context .TODO (), out , metav1.UpdateOptions {})
1088
- if err != nil {
1089
- return nil , false , err
1090
- }
1091
-
1092
- return updated , true , nil
1109
+ return out , true , nil
1093
1110
}
1094
1111
1095
1112
func (o * Operator ) ensureSubscriptionCSVState (logger * logrus.Entry , sub * v1alpha1.Subscription , querier SourceQuerier ) (* v1alpha1.Subscription , bool , error ) {
@@ -1225,23 +1242,45 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
1225
1242
return reference .GetReference (res )
1226
1243
}
1227
1244
1228
- func (o * Operator ) setSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType , reason , message string , setTrue bool ) []* v1alpha1.Subscription {
1245
+ // setSubsCond will set the condition to the subscription if it doesn't already
1246
+ // exist or if it is different
1247
+ // Only return the list of updated subscriptions
1248
+ func (o * Operator ) setSubsCond (subs []* v1alpha1.Subscription , cond v1alpha1.SubscriptionCondition ) []* v1alpha1.Subscription {
1229
1249
var (
1230
1250
lastUpdated = o .now ()
1251
+ subList []* v1alpha1.Subscription
1231
1252
)
1253
+
1232
1254
for _ , sub := range subs {
1255
+ subCond := sub .Status .GetCondition (cond .Type )
1256
+ if subCond .Equals (cond ) {
1257
+ continue
1258
+ }
1233
1259
sub .Status .LastUpdated = lastUpdated
1260
+ sub .Status .SetCondition (cond )
1261
+ subList = append (subList , sub )
1262
+ }
1263
+ return subList
1264
+ }
1265
+
1266
+ // removeSubsCond will remove the condition to the subscription if it exists
1267
+ // Only return the list of updated subscriptions
1268
+ func (o * Operator ) removeSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType ) []* v1alpha1.Subscription {
1269
+ var (
1270
+ lastUpdated = o .now ()
1271
+ )
1272
+ var subList []* v1alpha1.Subscription
1273
+ for _ , sub := range subs {
1234
1274
cond := sub .Status .GetCondition (condType )
1235
- cond .Reason = reason
1236
- cond .Message = message
1237
- if setTrue {
1238
- cond .Status = corev1 .ConditionTrue
1239
- } else {
1240
- cond .Status = corev1 .ConditionFalse
1275
+ // if status is ConditionUnknown, the condition doesn't exist. Just skip
1276
+ if cond .Status == corev1 .ConditionUnknown {
1277
+ continue
1241
1278
}
1242
- sub .Status .SetCondition (cond )
1279
+ sub .Status .LastUpdated = lastUpdated
1280
+ sub .Status .RemoveConditions (condType )
1281
+ subList = append (subList , sub )
1243
1282
}
1244
- return subs
1283
+ return subList
1245
1284
}
1246
1285
1247
1286
func (o * Operator ) updateSubscriptionStatuses (subs []* v1alpha1.Subscription ) ([]* v1alpha1.Subscription , error ) {
0 commit comments