Skip to content

Commit 6f751b7

Browse files
controller/registry/resolver: detect incoherent state
Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 5a680ad commit 6f751b7

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

pkg/controller/registry/resolver/source_csvs.go

+20
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import (
88

99
"github.com/blang/semver/v4"
1010
"github.com/operator-framework/api/pkg/operators/v1alpha1"
11+
operatorv1clientset "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
1112
v1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1"
1213
v1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
1314
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
1415
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/projection"
1516
"github.com/operator-framework/operator-registry/pkg/api"
1617
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1718
"github.com/sirupsen/logrus"
19+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1820
"k8s.io/apimachinery/pkg/labels"
1921
)
2022

@@ -23,6 +25,7 @@ type csvSourceProvider struct {
2325
subLister v1alpha1listers.SubscriptionLister
2426
ogLister v1listers.OperatorGroupLister
2527
logger logrus.StdLogger
28+
client operatorv1clientset.Interface
2629
}
2730

2831
func (csp *csvSourceProvider) Sources(namespaces ...string) map[cache.SourceKey]cache.Source {
@@ -34,6 +37,7 @@ func (csp *csvSourceProvider) Sources(namespaces ...string) map[cache.SourceKey]
3437
subLister: csp.subLister.Subscriptions(namespace),
3538
ogLister: csp.ogLister.OperatorGroups(namespace),
3639
logger: csp.logger,
40+
client: csp.client,
3741
}
3842
break // first ns is assumed to be the target ns, todo: make explicit
3943
}
@@ -46,6 +50,8 @@ type csvSource struct {
4650
subLister v1alpha1listers.SubscriptionNamespaceLister
4751
ogLister v1listers.OperatorGroupNamespaceLister
4852
logger logrus.StdLogger
53+
54+
client operatorv1clientset.Interface
4955
}
5056

5157
func (s *csvSource) Snapshot(ctx context.Context) (*cache.Snapshot, error) {
@@ -85,6 +91,20 @@ func (s *csvSource) Snapshot(ctx context.Context) (*cache.Snapshot, error) {
8591
continue
8692
}
8793

94+
if cachedSubscription, ok := csvSubscriptions[csv]; !ok || cachedSubscription == nil {
95+
// we might be in an incoherent state, so let's check with live clients to make sure
96+
realSubscriptions, err := s.client.OperatorsV1alpha1().Subscriptions(csv.Namespace).List(ctx, metav1.ListOptions{})
97+
if err != nil {
98+
return nil, fmt.Errorf("failed to list subscriptions: %w", err)
99+
}
100+
for _, realSubscription := range realSubscriptions.Items {
101+
if realSubscription.Status.InstalledCSV == csv.Name {
102+
// oops, live cluster state is coherent
103+
return nil, fmt.Errorf("lister caches incoherent for CSV %s/%s - found owning Subscription %s/%s", csv.Namespace, csv.Name, realSubscription.Namespace, realSubscription.Name)
104+
}
105+
}
106+
}
107+
88108
if failForwardEnabled {
89109
replacementChainEndsInFailure, err := isReplacementChainThatEndsInFailure(csv, ReplacementMapping(csvs))
90110
if err != nil {

pkg/controller/registry/resolver/step_resolver.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ import (
55
"context"
66
"fmt"
77

8-
"github.com/sirupsen/logrus"
9-
corev1 "k8s.io/api/core/v1"
10-
"k8s.io/apimachinery/pkg/api/errors"
11-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12-
138
"github.com/operator-framework/api/pkg/operators/v1alpha1"
149
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
1510
v1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
1611
controllerbundle "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle"
1712
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
1813
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/projection"
1914
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
15+
"github.com/sirupsen/logrus"
16+
corev1 "k8s.io/api/core/v1"
17+
"k8s.io/apimachinery/pkg/api/errors"
18+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2019
)
2120

2221
const (
@@ -63,6 +62,7 @@ func NewOperatorStepResolver(lister operatorlister.OperatorLister, client versio
6362
subLister: lister.OperatorsV1alpha1().SubscriptionLister(),
6463
ogLister: lister.OperatorsV1().OperatorGroupLister(),
6564
logger: log,
65+
client: client,
6666
},
6767
},
6868
}

0 commit comments

Comments
 (0)