8
8
"sync"
9
9
"time"
10
10
11
+ "k8s.io/apimachinery/pkg/util/errors"
12
+
11
13
"github.com/sirupsen/logrus"
12
14
13
15
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
@@ -79,6 +81,19 @@ type NamespacedOperatorCache struct {
79
81
snapshots map [registry.CatalogKey ]* CatalogSnapshot
80
82
}
81
83
84
+ func (c * NamespacedOperatorCache ) Error () error {
85
+ var errs []error
86
+ for key , snapshot := range c .snapshots {
87
+ snapshot .m .Lock ()
88
+ err := snapshot .err
89
+ snapshot .m .Unlock ()
90
+ if err != nil {
91
+ errs = append (errs , fmt .Errorf ("error using catalog %s (in namespace %s): %w" , key .Name , key .Namespace , err ))
92
+ }
93
+ }
94
+ return errors .NewAggregate (errs )
95
+ }
96
+
82
97
func (c * OperatorCache ) Expire (catalog registry.CatalogKey ) {
83
98
c .m .Lock ()
84
99
defer c .m .Unlock ()
@@ -183,6 +198,12 @@ func (c *OperatorCache) Namespaced(namespaces ...string) MultiCatalogOperatorFin
183
198
184
199
func (c * OperatorCache ) populate (ctx context.Context , snapshot * CatalogSnapshot , registry client.Interface ) {
185
200
defer snapshot .m .Unlock ()
201
+ defer func () {
202
+ // Don't cache an errorred snapshot.
203
+ if snapshot .err != nil {
204
+ snapshot .expiry = time.Time {}
205
+ }
206
+ }()
186
207
187
208
c .sem <- struct {}{}
188
209
defer func () { <- c .sem }()
@@ -195,6 +216,7 @@ func (c *OperatorCache) populate(ctx context.Context, snapshot *CatalogSnapshot,
195
216
it , err := registry .ListBundles (ctx )
196
217
if err != nil {
197
218
snapshot .logger .Errorf ("failed to list bundles: %s" , err .Error ())
219
+ snapshot .err = err
198
220
return
199
221
}
200
222
c .logger .WithField ("catalog" , snapshot .key .String ()).Debug ("updating cache" )
@@ -223,6 +245,7 @@ func (c *OperatorCache) populate(ctx context.Context, snapshot *CatalogSnapshot,
223
245
}
224
246
if err := it .Error (); err != nil {
225
247
snapshot .logger .Warnf ("error encountered while listing bundles: %s" , err .Error ())
248
+ snapshot .err = err
226
249
}
227
250
snapshot .operators = operators
228
251
}
@@ -293,6 +316,7 @@ type CatalogSnapshot struct {
293
316
m sync.RWMutex
294
317
pop context.CancelFunc
295
318
priority catalogSourcePriority
319
+ err error
296
320
}
297
321
298
322
func (s * CatalogSnapshot ) Cancel () {
@@ -400,6 +424,7 @@ type MultiCatalogOperatorFinder interface {
400
424
Catalog (registry.CatalogKey ) OperatorFinder
401
425
FindPreferred (* registry.CatalogKey , ... OperatorPredicate ) []* Operator
402
426
WithExistingOperators (* CatalogSnapshot ) MultiCatalogOperatorFinder
427
+ Error () error
403
428
OperatorFinder
404
429
}
405
430
0 commit comments