@@ -575,7 +575,9 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
575
575
}
576
576
}
577
577
578
- a .copyQueueIndexer .Enqueue (outCSV )
578
+ if ! outCSV .IsUncopiable () {
579
+ a .copyQueueIndexer .Enqueue (outCSV )
580
+ }
579
581
580
582
return
581
583
}
@@ -920,7 +922,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
920
922
logger .Info ("scheduling ClusterServiceVersion for install" )
921
923
out .SetPhaseWithEvent (v1alpha1 .CSVPhaseInstallReady , v1alpha1 .CSVReasonRequirementsMet , "all requirements found, attempting install" , now , a .recorder )
922
924
case v1alpha1 .CSVPhaseInstallReady :
923
- installer , strategy , _ := a .parseStrategiesAndUpdateStatus (out )
925
+ installer , strategy := a .parseStrategiesAndUpdateStatus (out )
924
926
if strategy == nil {
925
927
return
926
928
}
@@ -945,7 +947,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
945
947
return
946
948
947
949
case v1alpha1 .CSVPhaseInstalling :
948
- installer , strategy , _ := a .parseStrategiesAndUpdateStatus (out )
950
+ installer , strategy := a .parseStrategiesAndUpdateStatus (out )
949
951
if strategy == nil {
950
952
return
951
953
}
@@ -966,7 +968,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
966
968
return
967
969
}
968
970
969
- installer , strategy , _ := a .parseStrategiesAndUpdateStatus (out )
971
+ installer , strategy := a .parseStrategiesAndUpdateStatus (out )
970
972
if strategy == nil {
971
973
return
972
974
}
@@ -1009,7 +1011,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
1009
1011
}
1010
1012
1011
1013
case v1alpha1 .CSVPhaseFailed :
1012
- installer , strategy , _ := a .parseStrategiesAndUpdateStatus (out )
1014
+ installer , strategy := a .parseStrategiesAndUpdateStatus (out )
1013
1015
if strategy == nil {
1014
1016
return
1015
1017
}
@@ -1084,39 +1086,27 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
1084
1086
return
1085
1087
}
1086
1088
1087
- // If we are a leaf, we should requeue the replacement for processing
1089
+ // If there is a succeeded replacement, mark this for deletion
1088
1090
if next := a .isBeingReplaced (out , a .csvSet (out .GetNamespace (), v1alpha1 .CSVPhaseAny )); next != nil {
1089
- err := a .csvQueueSet .Requeue (next .GetName (), next .GetNamespace ())
1090
- if err != nil {
1091
- a .Log .WithError (err ).Warn ("error requeuing replacement" )
1092
- }
1093
- }
1094
-
1095
- // If we can find a newer version that's successfully installed, we're safe to mark all intermediates
1096
- for _ , csv := range a .findIntermediatesForDeletion (out ) {
1097
- // we only mark them in this step, in case some get deleted but others fail and break the replacement chain
1098
- csv .SetPhaseWithEvent (v1alpha1 .CSVPhaseDeleting , v1alpha1 .CSVReasonReplaced , "has been replaced by a newer ClusterServiceVersion that has successfully installed." , now , a .recorder )
1099
-
1100
- // Ignore errors and success here; this step is just an optimization to speed up GC
1101
- _ , _ = a .client .OperatorsV1alpha1 ().ClusterServiceVersions (csv .GetNamespace ()).UpdateStatus (csv )
1102
- err := a .csvQueueSet .Requeue (csv .GetName (), csv .GetNamespace ())
1103
- if err != nil {
1104
- a .Log .Warn (err .Error ())
1091
+ if next .Status .Phase == v1alpha1 .CSVPhaseSucceeded {
1092
+ out .SetPhaseWithEvent (v1alpha1 .CSVPhaseDeleting , v1alpha1 .CSVReasonReplaced , "has been replaced by a newer ClusterServiceVersion that has successfully installed." , now , a .recorder )
1093
+ } else {
1094
+ // If there's a replacement, but it's not yet succeeded, requeue both (this is an active replacement)
1095
+ if err := a .csvQueueSet .Requeue (next .GetName (), next .GetNamespace ()); err != nil {
1096
+ a .Log .Warn (err .Error ())
1097
+ }
1098
+ if err := a .csvQueueSet .Requeue (out .GetName (), out .GetNamespace ()); err != nil {
1099
+ a .Log .Warn (err .Error ())
1100
+ }
1105
1101
}
1106
- }
1107
-
1108
- // If there's no newer version, requeue for processing (likely will be GCable before resync)
1109
- err := a .csvQueueSet .Requeue (out .GetName (), out .GetNamespace ())
1110
- if err != nil {
1111
- a .Log .Warn (err .Error ())
1102
+ } else {
1103
+ syncError = fmt .Errorf ("CSV marked as replacement, but no replacmenet CSV found in cluster." )
1112
1104
}
1113
1105
case v1alpha1 .CSVPhaseDeleting :
1114
- var immediate int64 = 0
1115
-
1116
1106
if err := a .csvQueueSet .Remove (out .GetName (), out .GetNamespace ()); err != nil {
1117
1107
logger .WithError (err ).Debug ("error removing from queue" )
1118
1108
}
1119
- syncError = a .client .OperatorsV1alpha1 ().ClusterServiceVersions (out .GetNamespace ()).Delete (out .GetName (), & metav1.DeleteOptions { GracePeriodSeconds : & immediate } )
1109
+ syncError = a .client .OperatorsV1alpha1 ().ClusterServiceVersions (out .GetNamespace ()).Delete (out .GetName (), metav1 .NewDeleteOptions ( 0 ) )
1120
1110
if syncError != nil {
1121
1111
logger .Debugf ("unable to get delete csv marked for deletion: %s" , syncError .Error ())
1122
1112
}
@@ -1125,36 +1115,6 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
1125
1115
return
1126
1116
}
1127
1117
1128
- // findIntermediatesForDeletion starts at csv and follows the replacement chain until one is running and active
1129
- func (a * Operator ) findIntermediatesForDeletion (csv * v1alpha1.ClusterServiceVersion ) (csvs []* v1alpha1.ClusterServiceVersion ) {
1130
- csvsInNamespace := a .csvSet (csv .GetNamespace (), v1alpha1 .CSVPhaseAny )
1131
- current := csv
1132
-
1133
- // isBeingReplaced returns a copy
1134
- next := a .isBeingReplaced (current , csvsInNamespace )
1135
- for next != nil {
1136
- csvs = append (csvs , current )
1137
- a .Log .Debugf ("checking to see if %s is running so we can delete %s" , next .GetName (), csv .GetName ())
1138
- installer , nextStrategy , currentStrategy := a .parseStrategiesAndUpdateStatus (next )
1139
- if nextStrategy == nil {
1140
- a .Log .Debugf ("couldn't get strategy for %s" , next .GetName ())
1141
- continue
1142
- }
1143
- if currentStrategy == nil {
1144
- a .Log .Debugf ("couldn't get strategy for %s" , next .GetName ())
1145
- continue
1146
- }
1147
- installed , _ := installer .CheckInstalled (nextStrategy )
1148
- if installed && ! next .IsObsolete () && next .Status .Phase == v1alpha1 .CSVPhaseSucceeded {
1149
- return csvs
1150
- }
1151
- current = next
1152
- next = a .isBeingReplaced (current , csvsInNamespace )
1153
- }
1154
-
1155
- return nil
1156
- }
1157
-
1158
1118
// csvSet gathers all CSVs in the given namespace into a map keyed by CSV name; if metav1.NamespaceAll gets the set across all namespaces
1159
1119
func (a * Operator ) csvSet (namespace string , phase v1alpha1.ClusterServiceVersionPhase ) map [string ]* v1alpha1.ClusterServiceVersion {
1160
1120
csvsInNamespace , err := a .lister .OperatorsV1alpha1 ().ClusterServiceVersionLister ().ClusterServiceVersions (namespace ).List (labels .Everything ())
@@ -1234,11 +1194,11 @@ func (a *Operator) updateInstallStatus(csv *v1alpha1.ClusterServiceVersion, inst
1234
1194
}
1235
1195
1236
1196
// parseStrategiesAndUpdateStatus returns a StrategyInstaller and a Strategy for a CSV if it can, else it sets a status on the CSV and returns
1237
- func (a * Operator ) parseStrategiesAndUpdateStatus (csv * v1alpha1.ClusterServiceVersion ) (install.StrategyInstaller , install.Strategy , install. Strategy ) {
1197
+ func (a * Operator ) parseStrategiesAndUpdateStatus (csv * v1alpha1.ClusterServiceVersion ) (install.StrategyInstaller , install.Strategy ) {
1238
1198
strategy , err := a .resolver .UnmarshalStrategy (csv .Spec .InstallStrategy )
1239
1199
if err != nil {
1240
1200
csv .SetPhaseWithEvent (v1alpha1 .CSVPhaseFailed , v1alpha1 .CSVReasonInvalidStrategy , fmt .Sprintf ("install strategy invalid: %s" , err ), timeNow (), a .recorder )
1241
- return nil , nil , nil
1201
+ return nil , nil
1242
1202
}
1243
1203
1244
1204
previousCSV := a .isReplacing (csv )
@@ -1257,7 +1217,7 @@ func (a *Operator) parseStrategiesAndUpdateStatus(csv *v1alpha1.ClusterServiceVe
1257
1217
1258
1218
strName := strategy .GetStrategyName ()
1259
1219
installer := a .resolver .InstallerForStrategy (strName , a .OpClient , a .lister , csv , csv .Annotations , previousStrategy )
1260
- return installer , strategy , previousStrategy
1220
+ return installer , strategy
1261
1221
}
1262
1222
1263
1223
func (a * Operator ) crdOwnerConflicts (in * v1alpha1.ClusterServiceVersion , csvsInNamespace map [string ]* v1alpha1.ClusterServiceVersion ) error {
0 commit comments