Skip to content

Commit da9d438

Browse files
Remove oudated subscription update logic to improve resolution delay (#2369) (#2856)
Currently, olm logic checks for upgrade in subscription via another obsolete API that is no longer in use for dependency solution. As a result, sometimes, subscriptions display `UpgradeAvailable` status but there will be no upgrades as the upgrade is not valid in the resolver. Also, the `UpgradeAvailable` status is used to trigger the new resolution even though that status is no longer a valid indicator of having a pending upgrade. This leads to unwanted upgrade delay when the obsolete API works properly. This commit will remove the code that is using this obsolete API and allow the resolution to happen when there is a subscription change. Signed-off-by: Vu Dinh <[email protected]> Signed-off-by: perdasilva <[email protected]> Signed-off-by: Vu Dinh <[email protected]> Signed-off-by: perdasilva <[email protected]> Co-authored-by: Vu Dinh <[email protected]>
1 parent 64cff34 commit da9d438

File tree

4 files changed

+5
-195
lines changed

4 files changed

+5
-195
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -951,11 +951,6 @@ func (o *Operator) syncSubscriptions(obj interface{}) error {
951951
}
952952

953953
func (o *Operator) nothingToUpdate(logger *logrus.Entry, sub *v1alpha1.Subscription) bool {
954-
// Only sync if catalog has been updated since last sync time
955-
if o.sourcesLastUpdate.Before(sub.Status.LastUpdated.Time) && sub.Status.State != v1alpha1.SubscriptionStateNone && sub.Status.State != v1alpha1.SubscriptionStateUpgradeAvailable {
956-
logger.Debugf("skipping update: no new updates to catalog since last sync at %s", sub.Status.LastUpdated.String())
957-
return true
958-
}
959954
if sub.Status.InstallPlanRef != nil && sub.Status.State == v1alpha1.SubscriptionStateUpgradePending {
960955
logger.Debugf("skipping update: installplan already created")
961956
return true
@@ -1009,7 +1004,7 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
10091004
return sub, false, nil
10101005
}
10111006

1012-
csv, err := o.client.OperatorsV1alpha1().ClusterServiceVersions(sub.GetNamespace()).Get(context.TODO(), sub.Status.CurrentCSV, metav1.GetOptions{})
1007+
_, err := o.client.OperatorsV1alpha1().ClusterServiceVersions(sub.GetNamespace()).Get(context.TODO(), sub.Status.CurrentCSV, metav1.GetOptions{})
10131008
out := sub.DeepCopy()
10141009
if err != nil {
10151010
logger.WithError(err).WithField("currentCSV", sub.Status.CurrentCSV).Debug("error fetching csv listed in subscription status")
@@ -1019,14 +1014,7 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha
10191014
if err := querier.Queryable(); err != nil {
10201015
return nil, false, err
10211016
}
1022-
b, _, _ := querier.FindReplacement(&csv.Spec.Version.Version, sub.Status.CurrentCSV, sub.Spec.Package, sub.Spec.Channel, registry.CatalogKey{Name: sub.Spec.CatalogSource, Namespace: sub.Spec.CatalogSourceNamespace})
1023-
if b != nil {
1024-
o.logger.Tracef("replacement %s bundle found for current bundle %s", b.CsvName, sub.Status.CurrentCSV)
1025-
out.Status.State = v1alpha1.SubscriptionStateUpgradeAvailable
1026-
} else {
1027-
out.Status.State = v1alpha1.SubscriptionStateAtLatest
1028-
}
1029-
1017+
out.Status.State = v1alpha1.SubscriptionStateAtLatest
10301018
out.Status.InstalledCSV = sub.Status.CurrentCSV
10311019
}
10321020

pkg/controller/registry/resolver/querier.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type SourceQuerier interface {
3131
FindProvider(api opregistry.APIKey, initialSource registry.CatalogKey, excludedPackages map[string]struct{}) (*api.Bundle, *registry.CatalogKey, error)
3232
FindBundle(pkgName, channelName, bundleName string, initialSource registry.CatalogKey) (*api.Bundle, *registry.CatalogKey, error)
3333
FindLatestBundle(pkgName, channelName string, initialSource registry.CatalogKey) (*api.Bundle, *registry.CatalogKey, error)
34+
// Deprecated: This FindReplacement function will be deprecated soon
3435
FindReplacement(currentVersion *semver.Version, bundleName, pkgName, channelName string, initialSource registry.CatalogKey) (*api.Bundle, *registry.CatalogKey, error)
3536
Queryable() error
3637
}
@@ -123,6 +124,7 @@ func (q *NamespaceSourceQuerier) FindLatestBundle(pkgName, channelName string, i
123124
return nil, nil, fmt.Errorf("%s/%s not found in any available CatalogSource", pkgName, channelName)
124125
}
125126

127+
// Deprecated: This FindReplacement function will be deprecated soon
126128
func (q *NamespaceSourceQuerier) FindReplacement(currentVersion *semver.Version, bundleName, pkgName, channelName string, initialSource registry.CatalogKey) (*api.Bundle, *registry.CatalogKey, error) {
127129
errs := []error{}
128130

pkg/controller/registry/resolver/querier_test.go

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@ package resolver
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"testing"
87

9-
"github.com/blang/semver/v4"
108
"github.com/operator-framework/operator-registry/pkg/api"
119
"github.com/operator-framework/operator-registry/pkg/client"
1210
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1311
"github.com/stretchr/testify/require"
14-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1512

16-
"github.com/operator-framework/api/pkg/lib/version"
17-
"github.com/operator-framework/api/pkg/operators/v1alpha1"
1813
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
1914
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/fakes"
2015
)
@@ -344,178 +339,3 @@ func TestNamespaceSourceQuerier_FindPackage(t *testing.T) {
344339
})
345340
}
346341
}
347-
348-
func TestNamespaceSourceQuerier_FindReplacement(t *testing.T) {
349-
// TODO: clean up this test setup
350-
initialSource := fakes.FakeClientInterface{}
351-
otherSource := fakes.FakeClientInterface{}
352-
replacementSource := fakes.FakeClientInterface{}
353-
replacementAndLatestSource := fakes.FakeClientInterface{}
354-
replacementAndNoAnnotationLatestSource := fakes.FakeClientInterface{}
355-
356-
latestVersion := semver.MustParse("1.0.0-1556661308")
357-
csv := v1alpha1.ClusterServiceVersion{
358-
TypeMeta: metav1.TypeMeta{
359-
Kind: v1alpha1.ClusterServiceVersionKind,
360-
APIVersion: v1alpha1.GroupVersion,
361-
},
362-
ObjectMeta: metav1.ObjectMeta{
363-
Name: "latest",
364-
Namespace: "placeholder",
365-
Annotations: map[string]string{
366-
"olm.skipRange": ">= 1.0.0-0 < 1.0.0-1556661308",
367-
},
368-
},
369-
Spec: v1alpha1.ClusterServiceVersionSpec{
370-
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
371-
Owned: []v1alpha1.CRDDescription{},
372-
Required: []v1alpha1.CRDDescription{},
373-
},
374-
APIServiceDefinitions: v1alpha1.APIServiceDefinitions{
375-
Owned: []v1alpha1.APIServiceDescription{},
376-
Required: []v1alpha1.APIServiceDescription{},
377-
},
378-
Version: version.OperatorVersion{latestVersion},
379-
},
380-
}
381-
csvJson, err := json.Marshal(csv)
382-
require.NoError(t, err)
383-
384-
nextBundle := &api.Bundle{CsvName: "test.v1", PackageName: "testPkg", ChannelName: "testChannel"}
385-
latestBundle := &api.Bundle{CsvName: "latest", PackageName: "testPkg", ChannelName: "testChannel", CsvJson: string(csvJson), Object: []string{string(csvJson)}, SkipRange: ">= 1.0.0-0 < 1.0.0-1556661308", Version: latestVersion.String()}
386-
387-
csv.SetAnnotations(map[string]string{})
388-
csvUnstNoAnnotationJson, err := json.Marshal(csv)
389-
require.NoError(t, err)
390-
latestBundleNoAnnotation := &api.Bundle{CsvName: "latest", PackageName: "testPkg", ChannelName: "testChannel", CsvJson: string(csvUnstNoAnnotationJson), Object: []string{string(csvUnstNoAnnotationJson)}}
391-
392-
initialSource.GetReplacementBundleInPackageChannelStub = func(ctx context.Context, bundleName, pkgName, channelName string) (*api.Bundle, error) {
393-
return nil, fmt.Errorf("not found")
394-
}
395-
replacementSource.GetReplacementBundleInPackageChannelStub = func(ctx context.Context, bundleName, pkgName, channelName string) (*api.Bundle, error) {
396-
return nextBundle, nil
397-
}
398-
initialSource.GetBundleInPackageChannelStub = func(ctx context.Context, pkgName, channelName string) (*api.Bundle, error) {
399-
if pkgName != latestBundle.PackageName {
400-
return nil, fmt.Errorf("not found")
401-
}
402-
return latestBundle, nil
403-
}
404-
otherSource.GetBundleInPackageChannelStub = func(ctx context.Context, pkgName, channelName string) (*api.Bundle, error) {
405-
if pkgName != latestBundle.PackageName {
406-
return nil, fmt.Errorf("not found")
407-
}
408-
return latestBundle, nil
409-
}
410-
replacementAndLatestSource.GetReplacementBundleInPackageChannelStub = func(ctx context.Context, bundleName, pkgName, channelName string) (*api.Bundle, error) {
411-
return nextBundle, nil
412-
}
413-
replacementAndLatestSource.GetBundleInPackageChannelStub = func(ctx context.Context, pkgName, channelName string) (*api.Bundle, error) {
414-
return latestBundle, nil
415-
}
416-
replacementAndNoAnnotationLatestSource.GetReplacementBundleInPackageChannelStub = func(ctx context.Context, bundleName, pkgName, channelName string) (*api.Bundle, error) {
417-
return nextBundle, nil
418-
}
419-
replacementAndNoAnnotationLatestSource.GetBundleInPackageChannelStub = func(ctx context.Context, pkgName, channelName string) (*api.Bundle, error) {
420-
return latestBundleNoAnnotation, nil
421-
}
422-
423-
initialKey := registry.CatalogKey{"initial", "ns"}
424-
otherKey := registry.CatalogKey{"other", "other"}
425-
replacementKey := registry.CatalogKey{"replacement", "ns"}
426-
replacementAndLatestKey := registry.CatalogKey{"replat", "ns"}
427-
replacementAndNoAnnotationLatestKey := registry.CatalogKey{"replatbad", "ns"}
428-
429-
sources := map[registry.CatalogKey]registry.ClientInterface{
430-
initialKey: &initialSource,
431-
otherKey: &otherSource,
432-
replacementKey: &replacementSource,
433-
replacementAndLatestKey: &replacementAndLatestSource,
434-
replacementAndNoAnnotationLatestKey: &replacementAndNoAnnotationLatestSource,
435-
}
436-
437-
startVersion := semver.MustParse("1.0.0-0")
438-
notInRange := semver.MustParse("1.0.0-1556661347")
439-
440-
type fields struct {
441-
sources map[registry.CatalogKey]registry.ClientInterface
442-
}
443-
type args struct {
444-
currentVersion *semver.Version
445-
pkgName string
446-
channelName string
447-
bundleName string
448-
initialSource registry.CatalogKey
449-
}
450-
type out struct {
451-
bundle *api.Bundle
452-
key *registry.CatalogKey
453-
err error
454-
}
455-
tests := []struct {
456-
name string
457-
fields fields
458-
args args
459-
out out
460-
}{
461-
{
462-
name: "FindsLatestInPrimaryCatalog",
463-
fields: fields{sources: sources},
464-
args: args{&startVersion, "testPkg", "testChannel", "test.v1", initialKey},
465-
out: out{bundle: latestBundle, key: &initialKey, err: nil},
466-
},
467-
{
468-
name: "FindsLatestInSecondaryCatalog",
469-
fields: fields{sources: sources},
470-
args: args{&startVersion, "testPkg", "testChannel", "test.v1", otherKey},
471-
out: out{bundle: latestBundle, key: &otherKey, err: nil},
472-
},
473-
{
474-
name: "PrefersLatestToReplaced/SameCatalog",
475-
fields: fields{sources: sources},
476-
args: args{&startVersion, "testPkg", "testChannel", "test.v1", replacementAndLatestKey},
477-
out: out{bundle: latestBundle, key: &replacementAndLatestKey, err: nil},
478-
},
479-
{
480-
name: "PrefersLatestToReplaced/OtherCatalog",
481-
fields: fields{sources: sources},
482-
args: args{&startVersion, "testPkg", "testChannel", "test.v1", initialKey},
483-
out: out{bundle: latestBundle, key: &initialKey, err: nil},
484-
},
485-
{
486-
name: "IgnoresLatestWithoutAnnotation",
487-
fields: fields{sources: sources},
488-
args: args{&startVersion, "testPkg", "testChannel", "test.v1", replacementAndNoAnnotationLatestKey},
489-
out: out{bundle: nextBundle, key: &replacementAndNoAnnotationLatestKey, err: nil},
490-
},
491-
{
492-
name: "IgnoresLatestNotInRange",
493-
fields: fields{sources: sources},
494-
args: args{&notInRange, "testPkg", "testChannel", "test.v1", replacementAndLatestKey},
495-
out: out{bundle: nextBundle, key: &replacementAndLatestKey, err: nil},
496-
},
497-
{
498-
name: "IgnoresLatestAtLatest",
499-
fields: fields{sources: sources},
500-
args: args{&latestVersion, "testPkg", "testChannel", "test.v1", otherKey},
501-
out: out{bundle: nil, key: nil, err: nil},
502-
},
503-
}
504-
for _, tt := range tests {
505-
t.Run(tt.name, func(t *testing.T) {
506-
q := &NamespaceSourceQuerier{
507-
sources: tt.fields.sources,
508-
}
509-
var got *api.Bundle
510-
var key *registry.CatalogKey
511-
var err error
512-
got, key, err = q.FindReplacement(tt.args.currentVersion, tt.args.bundleName, tt.args.pkgName, tt.args.channelName, tt.args.initialSource)
513-
if err != nil {
514-
t.Log(err.Error())
515-
}
516-
require.Equal(t, tt.out.err, err, "%v", err)
517-
require.Equal(t, tt.out.bundle, got)
518-
require.Equal(t, tt.out.key, key)
519-
})
520-
}
521-
}

test/e2e/subscription_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ var _ = Describe("Subscription", func() {
20442044
}
20452045
updateInternalCatalog(GinkgoT(), kubeClient, crClient, catalogSourceName, testNamespace, []apiextensions.CustomResourceDefinition{crd, crd2}, []v1alpha1.ClusterServiceVersion{csvNewA, csvA, csvB}, manifests)
20462046
csvAsub := strings.Join([]string{packageName1, stableChannel, catalogSourceName, testNamespace}, "-")
2047-
_, err = fetchSubscription(crClient, testNamespace, csvAsub, subscriptionStateUpgradeAvailableChecker)
2047+
_, err = fetchSubscription(crClient, testNamespace, csvAsub, subscriptionStateAtLatestChecker)
20482048
require.NoError(GinkgoT(), err)
20492049
// Ensure csvNewA is not installed
20502050
_, err = crClient.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).Get(context.Background(), csvNewA.Name, metav1.GetOptions{})

0 commit comments

Comments
 (0)