@@ -39,6 +39,7 @@ type foundBundle struct {
3939
4040// Resolve returns a Bundle from a catalog that needs to get installed on the cluster.
4141func (r * CatalogResolver ) Resolve (ctx context.Context , ext * ocv1.ClusterExtension , installedBundle * ocv1.BundleMetadata ) (* declcfg.Bundle , * bsemver.Version , * declcfg.Deprecation , error ) {
42+ l := log .FromContext (ctx )
4243 packageName := ext .Spec .Source .Catalog .PackageName
4344 versionRange := ext .Spec .Source .Catalog .Version
4445 channels := ext .Spec .Source .Catalog .Channels
@@ -65,6 +66,15 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
6566 }
6667 }
6768
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+
6878 resolvedBundles := []foundBundle {}
6979 var priorDeprecation * declcfg.Deprecation
7080
@@ -76,6 +86,16 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
7686 return fmt .Errorf ("error getting package %q from catalog %q: %w" , packageName , cat .Name , err )
7787 }
7888
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+
7999 var predicates []filter.Predicate [declcfg.Bundle ]
80100 if len (channels ) > 0 {
81101 channelSet := sets .New (channels ... )
@@ -99,6 +119,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
99119
100120 // Apply the predicates to get the candidate bundles
101121 packageFBC .Bundles = filter .Filter (packageFBC .Bundles , filter .And (predicates ... ))
122+ cs .MatchedBundles = len (packageFBC .Bundles )
102123 if len (packageFBC .Bundles ) == 0 {
103124 return nil
104125 }
@@ -158,6 +179,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
158179
159180 // Check for ambiguity
160181 if len (resolvedBundles ) != 1 {
182+ l .Info ("resolution failed" , "stats" , catStats )
161183 return nil , nil , nil , resolutionError {
162184 PackageName : packageName ,
163185 Version : versionRange ,
@@ -174,12 +196,15 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
174196
175197 // Run validations against the resolved bundle to ensure only valid resolved bundles are being returned
176198 // 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.
177201 for _ , validation := range r .Validations {
178202 if err := validation (resolvedBundle ); err != nil {
179203 return nil , nil , nil , fmt .Errorf ("validating bundle %q: %w" , resolvedBundle .Name , err )
180204 }
181205 }
182206
207+ l .V (4 ).Info ("resolution succeeded" , "stats" , catStats )
183208 return resolvedBundle , resolvedBundleVersion , priorDeprecation , nil
184209}
185210
@@ -257,6 +282,9 @@ func CatalogWalker(
257282 return false
258283 })
259284
285+ availableCatalogNames := mapSlice (catalogs , func (c catalogd.ClusterCatalog ) string { return c .Name })
286+ l .Info ("using ClusterCatalogs for resolution" , "catalogs" , availableCatalogNames )
287+
260288 for i := range catalogs {
261289 cat := & catalogs [i ]
262290
@@ -271,3 +299,18 @@ func CatalogWalker(
271299 return nil
272300 }
273301}
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