@@ -962,15 +962,15 @@ 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 )
965
+ subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ConstraintsNotSatisfiable" , err .Error (), corev1 . ConditionTrue )
966
966
_ , updateErr := o .updateSubscriptionStatuses (subs )
967
967
if updateErr != nil {
968
968
logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
969
969
return updateErr
970
970
}
971
971
return nil
972
972
}
973
- subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ErrorPreventedResolution" , err .Error (), true )
973
+ subs = o .setSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed , "ErrorPreventedResolution" , err .Error (), corev1 . ConditionTrue )
974
974
_ , updateErr := o .updateSubscriptionStatuses (subs )
975
975
if updateErr != nil {
976
976
logger .WithError (updateErr ).Debug ("failed to update subs conditions" )
@@ -979,14 +979,6 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
979
979
return err
980
980
}
981
981
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
982
// create installplan if anything updated
991
983
if len (updatedSubs ) > 0 {
992
984
logger .Debug ("resolution caused subscription changes, creating installplan" )
@@ -1017,17 +1009,35 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
1017
1009
return err
1018
1010
}
1019
1011
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
1012
} else {
1028
1013
logger .Debugf ("no subscriptions were updated" )
1029
1014
}
1030
1015
1016
+ // Remove resolutionfailed condition from subscriptions
1017
+ subs = o .removeSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed )
1018
+ newSub := true
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
+ newSub = false
1024
+ break
1025
+ }
1026
+ }
1027
+ if newSub {
1028
+ subs = append (subs , updatedSub )
1029
+ continue
1030
+ }
1031
+ newSub = true
1032
+ }
1033
+
1034
+ // Update subscriptions with all changes so far
1035
+ _ , updateErr := o .updateSubscriptionStatuses (subs )
1036
+ if updateErr != nil {
1037
+ logger .WithError (updateErr ).Warn ("failed to update subscription conditions" )
1038
+ return updateErr
1039
+ }
1040
+
1031
1041
return nil
1032
1042
}
1033
1043
@@ -1084,12 +1094,7 @@ func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub
1084
1094
out .Status .CurrentCSV = out .Spec .StartingCSV
1085
1095
out .Status .LastUpdated = o .now ()
1086
1096
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
1097
+ return out , true , nil
1093
1098
}
1094
1099
1095
1100
func (o * Operator ) ensureSubscriptionCSVState (logger * logrus.Entry , sub * v1alpha1.Subscription , querier SourceQuerier ) (* v1alpha1.Subscription , bool , error ) {
@@ -1225,23 +1230,50 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
1225
1230
return reference .GetReference (res )
1226
1231
}
1227
1232
1228
- func (o * Operator ) setSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType , reason , message string , setTrue bool ) []* v1alpha1.Subscription {
1233
+ // setSubsCond will set the condition to the subscription if it doesn't already
1234
+ // exist or if it is different
1235
+ // Only return the list of updated subscriptions
1236
+ func (o * Operator ) setSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType , reason , message string , status corev1.ConditionStatus ) []* v1alpha1.Subscription {
1229
1237
var (
1230
1238
lastUpdated = o .now ()
1239
+ subList []* v1alpha1.Subscription
1231
1240
)
1241
+ newCond := v1alpha1.SubscriptionCondition {
1242
+ Type : condType ,
1243
+ Status : status ,
1244
+ Reason : reason ,
1245
+ Message : message ,
1246
+ }
1232
1247
for _ , sub := range subs {
1248
+ cond := sub .Status .GetCondition (condType )
1249
+ if cond .Equals (newCond ) {
1250
+ continue
1251
+ }
1233
1252
sub .Status .LastUpdated = lastUpdated
1253
+ sub .Status .SetCondition (newCond )
1254
+ subList = append (subList , sub )
1255
+ }
1256
+ return subList
1257
+ }
1258
+
1259
+ // removeSubsCond will remove the condition to the subscription if it exists
1260
+ // Only return the list of updated subscriptions
1261
+ func (o * Operator ) removeSubsCond (subs []* v1alpha1.Subscription , condType v1alpha1.SubscriptionConditionType ) []* v1alpha1.Subscription {
1262
+ var (
1263
+ lastUpdated = o .now ()
1264
+ )
1265
+ var subList []* v1alpha1.Subscription
1266
+ for _ , sub := range subs {
1234
1267
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
1268
+ // if status is ConditionUnknown, the condition doesn't exist. Just skip
1269
+ if cond .Status == corev1 .ConditionUnknown {
1270
+ continue
1241
1271
}
1242
- sub .Status .SetCondition (cond )
1272
+ sub .Status .LastUpdated = lastUpdated
1273
+ sub .Status .RemoveConditions (condType )
1274
+ subList = append (subList , sub )
1243
1275
}
1244
- return subs
1276
+ return subList
1245
1277
}
1246
1278
1247
1279
func (o * Operator ) updateSubscriptionStatuses (subs []* v1alpha1.Subscription ) ([]* v1alpha1.Subscription , error ) {
0 commit comments