@@ -8,13 +8,15 @@ import (
8
8
9
9
"github.com/blang/semver/v4"
10
10
"github.com/operator-framework/api/pkg/operators/v1alpha1"
11
+ operatorv1clientset "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
11
12
v1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1"
12
13
v1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
13
14
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
14
15
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/projection"
15
16
"github.com/operator-framework/operator-registry/pkg/api"
16
17
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
17
18
"github.com/sirupsen/logrus"
19
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
20
"k8s.io/apimachinery/pkg/labels"
19
21
)
20
22
@@ -23,6 +25,7 @@ type csvSourceProvider struct {
23
25
subLister v1alpha1listers.SubscriptionLister
24
26
ogLister v1listers.OperatorGroupLister
25
27
logger logrus.StdLogger
28
+ client operatorv1clientset.Interface
26
29
}
27
30
28
31
func (csp * csvSourceProvider ) Sources (namespaces ... string ) map [cache.SourceKey ]cache.Source {
@@ -34,6 +37,7 @@ func (csp *csvSourceProvider) Sources(namespaces ...string) map[cache.SourceKey]
34
37
subLister : csp .subLister .Subscriptions (namespace ),
35
38
ogLister : csp .ogLister .OperatorGroups (namespace ),
36
39
logger : csp .logger ,
40
+ client : csp .client ,
37
41
}
38
42
break // first ns is assumed to be the target ns, todo: make explicit
39
43
}
@@ -46,6 +50,8 @@ type csvSource struct {
46
50
subLister v1alpha1listers.SubscriptionNamespaceLister
47
51
ogLister v1listers.OperatorGroupNamespaceLister
48
52
logger logrus.StdLogger
53
+
54
+ client operatorv1clientset.Interface
49
55
}
50
56
51
57
func (s * csvSource ) Snapshot (ctx context.Context ) (* cache.Snapshot , error ) {
@@ -85,6 +91,20 @@ func (s *csvSource) Snapshot(ctx context.Context) (*cache.Snapshot, error) {
85
91
continue
86
92
}
87
93
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
+
88
108
if failForwardEnabled {
89
109
replacementChainEndsInFailure , err := isReplacementChainThatEndsInFailure (csv , ReplacementMapping (csvs ))
90
110
if err != nil {
0 commit comments