@@ -39,6 +39,7 @@ type foundBundle struct {
39
39
40
40
// Resolve returns a Bundle from a catalog that needs to get installed on the cluster.
41
41
func (r * CatalogResolver ) Resolve (ctx context.Context , ext * ocv1.ClusterExtension , installedBundle * ocv1.BundleMetadata ) (* declcfg.Bundle , * bsemver.Version , * declcfg.Deprecation , error ) {
42
+ l := log .FromContext (ctx )
42
43
packageName := ext .Spec .Source .Catalog .PackageName
43
44
versionRange := ext .Spec .Source .Catalog .Version
44
45
channels := ext .Spec .Source .Catalog .Channels
@@ -65,6 +66,15 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
65
66
}
66
67
}
67
68
69
+ type catStat struct {
70
+ CatalogName string `json:"catalogName"`
71
+ PackageFound bool `json:"packageFound"`
72
+ TotalBundles int `json:"totalBundles"`
73
+ MatchedBundles int `json:"matchedBundles"`
74
+ }
75
+
76
+ var catStats []* catStat
77
+
68
78
resolvedBundles := []foundBundle {}
69
79
var priorDeprecation * declcfg.Deprecation
70
80
@@ -76,6 +86,16 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
76
86
return fmt .Errorf ("error getting package %q from catalog %q: %w" , packageName , cat .Name , err )
77
87
}
78
88
89
+ cs := catStat {CatalogName : cat .Name }
90
+ catStats = append (catStats , & cs )
91
+
92
+ if isFBCEmpty (packageFBC ) {
93
+ return nil
94
+ }
95
+
96
+ cs .PackageFound = true
97
+ cs .TotalBundles = len (packageFBC .Bundles )
98
+
79
99
var predicates []filter.Predicate [declcfg.Bundle ]
80
100
if len (channels ) > 0 {
81
101
channelSet := sets .New (channels ... )
@@ -99,6 +119,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
99
119
100
120
// Apply the predicates to get the candidate bundles
101
121
packageFBC .Bundles = filter .Filter (packageFBC .Bundles , filter .And (predicates ... ))
122
+ cs .MatchedBundles = len (packageFBC .Bundles )
102
123
if len (packageFBC .Bundles ) == 0 {
103
124
return nil
104
125
}
@@ -158,6 +179,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
158
179
159
180
// Check for ambiguity
160
181
if len (resolvedBundles ) != 1 {
182
+ l .Info ("resolution failed" , "stats" , catStats )
161
183
return nil , nil , nil , resolutionError {
162
184
PackageName : packageName ,
163
185
Version : versionRange ,
@@ -174,12 +196,15 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
174
196
175
197
// Run validations against the resolved bundle to ensure only valid resolved bundles are being returned
176
198
// Open Question: Should we grab the first valid bundle earlier?
199
+ // Answer: No, that would be a hidden resolution input, which we should avoid at all costs; the query can be
200
+ // constrained in order to eliminate the invalid bundle from the resolution.
177
201
for _ , validation := range r .Validations {
178
202
if err := validation (resolvedBundle ); err != nil {
179
203
return nil , nil , nil , fmt .Errorf ("validating bundle %q: %w" , resolvedBundle .Name , err )
180
204
}
181
205
}
182
206
207
+ l .V (4 ).Info ("resolution succeeded" , "stats" , catStats )
183
208
return resolvedBundle , resolvedBundleVersion , priorDeprecation , nil
184
209
}
185
210
@@ -257,6 +282,9 @@ func CatalogWalker(
257
282
return false
258
283
})
259
284
285
+ availableCatalogNames := mapSlice (catalogs , func (c catalogd.ClusterCatalog ) string { return c .Name })
286
+ l .Info ("using ClusterCatalogs for resolution" , "catalogs" , availableCatalogNames )
287
+
260
288
for i := range catalogs {
261
289
cat := & catalogs [i ]
262
290
@@ -271,3 +299,18 @@ func CatalogWalker(
271
299
return nil
272
300
}
273
301
}
302
+
303
+ func isFBCEmpty (fbc * declcfg.DeclarativeConfig ) bool {
304
+ if fbc == nil {
305
+ return true
306
+ }
307
+ return len (fbc .Packages ) == 0 && len (fbc .Channels ) == 0 && len (fbc .Bundles ) == 0 && len (fbc .Deprecations ) == 0 && len (fbc .Others ) == 0
308
+ }
309
+
310
+ func mapSlice [I any , O any ](in []I , f func (I ) O ) []O {
311
+ out := make ([]O , len (in ))
312
+ for i := range in {
313
+ out [i ] = f (in [i ])
314
+ }
315
+ return out
316
+ }
0 commit comments