Skip to content

Commit 56dbdf9

Browse files
committed
feat(olm): speed up csv updates
1 parent 5837a4b commit 56dbdf9

File tree

1 file changed

+24
-64
lines changed

1 file changed

+24
-64
lines changed

pkg/controller/operators/olm/operator.go

Lines changed: 24 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
575575
}
576576
}
577577

578-
a.copyQueueIndexer.Enqueue(outCSV)
578+
if !outCSV.IsUncopiable() {
579+
a.copyQueueIndexer.Enqueue(outCSV)
580+
}
579581

580582
return
581583
}
@@ -920,7 +922,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
920922
logger.Info("scheduling ClusterServiceVersion for install")
921923
out.SetPhaseWithEvent(v1alpha1.CSVPhaseInstallReady, v1alpha1.CSVReasonRequirementsMet, "all requirements found, attempting install", now, a.recorder)
922924
case v1alpha1.CSVPhaseInstallReady:
923-
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
925+
installer, strategy := a.parseStrategiesAndUpdateStatus(out)
924926
if strategy == nil {
925927
return
926928
}
@@ -945,7 +947,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
945947
return
946948

947949
case v1alpha1.CSVPhaseInstalling:
948-
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
950+
installer, strategy := a.parseStrategiesAndUpdateStatus(out)
949951
if strategy == nil {
950952
return
951953
}
@@ -966,7 +968,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
966968
return
967969
}
968970

969-
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
971+
installer, strategy := a.parseStrategiesAndUpdateStatus(out)
970972
if strategy == nil {
971973
return
972974
}
@@ -1009,7 +1011,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
10091011
}
10101012

10111013
case v1alpha1.CSVPhaseFailed:
1012-
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
1014+
installer, strategy := a.parseStrategiesAndUpdateStatus(out)
10131015
if strategy == nil {
10141016
return
10151017
}
@@ -1084,39 +1086,27 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
10841086
return
10851087
}
10861088

1087-
// If we are a leaf, we should requeue the replacement for processing
1089+
// If there is a succeeded replacement, mark this for deletion
10881090
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+
}
11051101
}
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.")
11121104
}
11131105
case v1alpha1.CSVPhaseDeleting:
1114-
var immediate int64 = 0
1115-
11161106
if err := a.csvQueueSet.Remove(out.GetName(), out.GetNamespace()); err != nil {
11171107
logger.WithError(err).Debug("error removing from queue")
11181108
}
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))
11201110
if syncError != nil {
11211111
logger.Debugf("unable to get delete csv marked for deletion: %s", syncError.Error())
11221112
}
@@ -1125,36 +1115,6 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
11251115
return
11261116
}
11271117

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-
11581118
// csvSet gathers all CSVs in the given namespace into a map keyed by CSV name; if metav1.NamespaceAll gets the set across all namespaces
11591119
func (a *Operator) csvSet(namespace string, phase v1alpha1.ClusterServiceVersionPhase) map[string]*v1alpha1.ClusterServiceVersion {
11601120
csvsInNamespace, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(namespace).List(labels.Everything())
@@ -1234,11 +1194,11 @@ func (a *Operator) updateInstallStatus(csv *v1alpha1.ClusterServiceVersion, inst
12341194
}
12351195

12361196
// 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) {
12381198
strategy, err := a.resolver.UnmarshalStrategy(csv.Spec.InstallStrategy)
12391199
if err != nil {
12401200
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
12421202
}
12431203

12441204
previousCSV := a.isReplacing(csv)
@@ -1257,7 +1217,7 @@ func (a *Operator) parseStrategiesAndUpdateStatus(csv *v1alpha1.ClusterServiceVe
12571217

12581218
strName := strategy.GetStrategyName()
12591219
installer := a.resolver.InstallerForStrategy(strName, a.OpClient, a.lister, csv, csv.Annotations, previousStrategy)
1260-
return installer, strategy, previousStrategy
1220+
return installer, strategy
12611221
}
12621222

12631223
func (a *Operator) crdOwnerConflicts(in *v1alpha1.ClusterServiceVersion, csvsInNamespace map[string]*v1alpha1.ClusterServiceVersion) error {

0 commit comments

Comments
 (0)