Skip to content

Commit a83ac33

Browse files
committed
fix(catalog): fix issue where subscriptions sometimes get "stuck"
we were not resetting the client when updating a catalogsource, which meant it was possible for the client to be stale and never attempt a reconnect if it didn't go unhealthy "in time" for us to detect and reconnect.
1 parent 7c22f02 commit a83ac33

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
446446
o.sourcesLastUpdate = timeNow()
447447
logger.Debug("registry server recreated")
448448

449+
func() {
450+
o.sourcesLock.Lock()
451+
defer o.sourcesLock.Unlock()
452+
delete(o.sources, sourceKey)
453+
}()
454+
449455
return nil
450456
}
451457
logger.Debug("registry state good")
@@ -717,7 +723,7 @@ func (o *Operator) nothingToUpdate(logger *logrus.Entry, sub *v1alpha1.Subscript
717723
logger.Debugf("skipping update: no new updates to catalog since last sync at %s", sub.Status.LastUpdated.String())
718724
return true
719725
}
720-
if sub.Status.Install != nil && sub.Status.State == v1alpha1.SubscriptionStateUpgradePending {
726+
if sub.Status.InstallPlanRef != nil && sub.Status.State == v1alpha1.SubscriptionStateUpgradePending {
721727
logger.Debugf("skipping update: installplan already created")
722728
return true
723729
}
@@ -797,13 +803,14 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
797803
out.Status.LastUpdated = timeNow()
798804

799805
// Update Subscription with status of transition. Log errors if we can't write them to the status.
800-
if sub, err = o.client.OperatorsV1alpha1().Subscriptions(out.GetNamespace()).UpdateStatus(out); err != nil {
806+
updatedSub, err := o.client.OperatorsV1alpha1().Subscriptions(out.GetNamespace()).UpdateStatus(out)
807+
if err != nil {
801808
logger.WithError(err).Info("error updating subscription status")
802809
return nil, false, fmt.Errorf("error updating Subscription status: " + err.Error())
803810
}
804811

805812
// subscription status represents cluster state
806-
return sub, true, nil
813+
return updatedSub, true, nil
807814
}
808815

809816
func (o *Operator) updateSubscriptionStatus(namespace string, subs []*v1alpha1.Subscription, installPlanRef *corev1.ObjectReference) error {

pkg/controller/operators/olm/operator.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,9 +1099,6 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
10991099
syncError = fmt.Errorf("CSV marked as replacement, but no replacmenet CSV found in cluster.")
11001100
}
11011101
case v1alpha1.CSVPhaseDeleting:
1102-
if err := a.csvQueueSet.Remove(out.GetName(), out.GetNamespace()); err != nil {
1103-
logger.WithError(err).Debug("error removing from queue")
1104-
}
11051102
syncError = a.client.OperatorsV1alpha1().ClusterServiceVersions(out.GetNamespace()).Delete(out.GetName(), metav1.NewDeleteOptions(0))
11061103
if syncError != nil {
11071104
logger.Debugf("unable to get delete csv marked for deletion: %s", syncError.Error())

pkg/controller/operators/olm/operatorgroup.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ func (a *Operator) ensureCSVsInNamespaces(csv *v1alpha1.ClusterServiceVersion, o
544544
}
545545

546546
func (a *Operator) copyToNamespace(csv *v1alpha1.ClusterServiceVersion, namespace string) error {
547+
if csv.GetNamespace() == namespace {
548+
return nil
549+
}
550+
547551
logger := a.Log.WithField("operator-ns", csv.GetNamespace()).WithField("target-ns", namespace)
548552
newCSV := csv.DeepCopy()
549553
delete(newCSV.Annotations, v1.OperatorGroupTargetsAnnotationKey)

test/e2e/e2e-values.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
writeStatusName: '""'
2+
debug: true
23

34
olm:
45
replicaCount: 1
@@ -7,7 +8,6 @@ olm:
78
pullPolicy: IfNotPresent
89
service:
910
internalPort: 8080
10-
commandArgs: -debug
1111

1212
catalog:
1313
replicaCount: 1
@@ -16,7 +16,6 @@ catalog:
1616
pullPolicy: IfNotPresent
1717
service:
1818
internalPort: 8080
19-
commandArgs: -debug
2019

2120
package:
2221
replicaCount: 1
@@ -25,7 +24,6 @@ package:
2524
pullPolicy: IfNotPresent
2625
service:
2726
internalPort: 5443
28-
commandArgs: --debug
2927

3028
e2e:
3129
image:

test/e2e/installplan_e2e_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func TestInstallPlanWithCSVsAcrossMultipleCatalogSources(t *testing.T) {
290290
require.NoError(t, err)
291291
require.NotNil(t, subscription)
292292

293-
installPlanName := subscription.Status.Install.Name
293+
installPlanName := subscription.Status.InstallPlanRef.Name
294294

295295
// Wait for InstallPlan to be status: Complete before checking resource presence
296296
fetchedInstallPlan, err := fetchInstallPlan(t, crc, installPlanName, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
@@ -339,11 +339,12 @@ EXPECTED:
339339
require.NotNil(t, dependentSubscription.Status.InstallPlanRef)
340340
require.Equal(t, dependentCSV.GetName(), dependentSubscription.Status.CurrentCSV)
341341

342-
fetchedCSV, err := awaitCSV(t, crc, testNamespace, dependentCSV.GetName(), csvAnyChecker)
342+
// Verify CSV is created
343+
_, err = awaitCSV(t, crc, testNamespace, dependentCSV.GetName(), csvAnyChecker)
343344
require.NoError(t, err)
344345

345346
// Update dependent subscription in catalog and wait for csv to update
346-
updatedDependentCSV := newCSV(dependentPackageStable+"v2", testNamespace, dependentPackageStable, semver.MustParse("0.1.1"), []apiextensions.CustomResourceDefinition{dependentCRD}, nil, dependentNamedStrategy)
347+
updatedDependentCSV := newCSV(dependentPackageStable+"-v2", testNamespace, dependentPackageStable, semver.MustParse("0.1.1"), []apiextensions.CustomResourceDefinition{dependentCRD}, nil, dependentNamedStrategy)
347348
dependentManifests = []registry.PackageManifest{
348349
{
349350
PackageName: dependentPackageName,
@@ -353,15 +354,21 @@ EXPECTED:
353354
DefaultChannelName: stableChannel,
354355
},
355356
}
357+
356358
updateInternalCatalog(t, c, crc, dependentCatalogName, testNamespace, []apiextensions.CustomResourceDefinition{dependentCRD}, []v1alpha1.ClusterServiceVersion{dependentCSV, updatedDependentCSV}, dependentManifests)
357359

358-
dependentSubscription, err = fetchSubscription(t, crc, testNamespace, strings.Join([]string{dependentPackageStable, dependentCatalogName, testNamespace}, "-"), subscriptionHasCurrentCSV(updatedDependentCSV.GetName()))
360+
// Wait for subscription to update
361+
updatedDepSubscription, err := fetchSubscription(t, crc, testNamespace, strings.Join([]string{dependentPackageStable, dependentCatalogName, testNamespace}, "-"), subscriptionHasCurrentCSV(updatedDependentCSV.GetName()))
359362
require.NoError(t, err)
360363

361-
fetchedCSV, err = awaitCSV(t, crc, testNamespace, updatedDependentCSV.GetName(), csvAnyChecker)
364+
// Verify installplan created and installed
365+
fetchedUpdatedDepInstallPlan, err := fetchInstallPlan(t, crc, updatedDepSubscription.Status.InstallPlanRef.Name, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
362366
require.NoError(t, err)
367+
log(fmt.Sprintf("Install plan %s fetched with status %s", fetchedUpdatedDepInstallPlan.GetName(), fetchedUpdatedDepInstallPlan.Status.Phase))
368+
require.NotEqual(t, fetchedInstallPlan.GetName(), fetchedUpdatedDepInstallPlan.GetName())
363369

364-
err = crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).Delete(fetchedCSV.GetName(), metav1.NewDeleteOptions(0))
370+
// Wait for csv to update
371+
_, err = awaitCSV(t, crc, testNamespace, updatedDependentCSV.GetName(), csvAnyChecker)
365372
require.NoError(t, err)
366373
}
367374

0 commit comments

Comments
 (0)