-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to catalogd's CatalogMetadata
APIs
#343
Conversation
Codecov Report
@@ Coverage Diff @@
## main #343 +/- ##
==========================================
- Coverage 82.35% 81.88% -0.48%
==========================================
Files 21 21
Lines 907 911 +4
==========================================
- Hits 747 746 -1
Misses 113 113
- Partials 47 52 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
|
bbb4f35
to
4a43091
Compare
50c9237
to
b568602
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov is reporting decrease in coverage becasue there is a bunch of new if err != nil { return err}
cases. Our existing tests do not cover failure scenarios at the moment.
I'm not adding any new tests for these code branches because this all will be changed as part of #347.
} | ||
} | ||
func validateCatalogMetadataCreation(g Gomega, operatorCatalog *catalogd.Catalog, pkgName string, versions []string) { | ||
cmList := catalogd.CatalogMetadataList{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests were passing without change to this function, but since we switched to using CatalogMetadata
instead of BundleMetadata
in the controller, I think it makes sense to update this pice too.
Also I switched to using g.Expect
here since it makes a bit easier to track down a specific failure vs this being logged in the calling case.
return allEntitiesList, nil | ||
} | ||
|
||
func MetadataToEntities(catalogName string, channels []declcfg.Channel, bundles []declcfg.Bundle) (input.EntityList, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I'm reviewing this function I have some concerns about it's performance. How frequently are we retrieving and transforming this data?
If this is an issue, we can address it in a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain your concerns?
I'm concerned about CatalogdEntitySource
since it seems to call getEntities
on each Filter
call. I decided not to touch it since we will be removing entity sources in #347.
I think as part of #347 we should think about some cache which will be valid for the duration of one resolution.
In the CLI we cache entites into the enttiy source property:
operator-controller/cmd/resolutioncli/entity_source.go
Lines 92 to 109 in b568602
func (es *indexRefEntitySource) entities(ctx context.Context) (input.EntityList, error) { | |
if es.entitiesCache == nil { | |
cfg, err := es.renderer.Run(ctx) | |
if err != nil { | |
return nil, err | |
} | |
// TODO: update empty catalog name string to be catalog name once we support multiple catalogs in CLI | |
entities, err := entitysources.MetadataToEntities("", cfg.Channels, cfg.Bundles) | |
if err != nil { | |
return nil, err | |
} | |
es.entitiesCache = entities | |
} | |
return es.entitiesCache, nil | |
} |
In operator controller we can not do the same since entity source is resused between reconciliations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a chat with Alex on this. The consern is not about MetadataToEntities
where we just convert data from declcfg
to entities, but about fetching the data from API server on each reconcile & multiple times during one resolution.
We came to an agreement that this is something which needs to be addressed, but not as part as this PR since this is problem with an entity source in general, not with the way we consume catalog medatada. Moreover entity sources will be removed soon as part of #347.
@awgreene please correct me if I captured it incorrectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetching the data from API server on each reconcile & multiple times during one resolution.
Is that true? I thought we had informer caches setup for the catalogd data such that cl.Get
and cl.List
would only ever hit the cache (and never the real apiserver)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you might be right! I totally forgot about informers.
for _, catalog := range catalogList.Items { | ||
channels, bundles, err := fetchCatalogMetadata(ctx, cl, catalog.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to fetch and loop through all the catalogs here? If we want to ensure we fetch all CatalogMetadata
for all Catalog
resources I think we can simplify this to listing all CatalogMetadata
resources and then processing each one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea is that we process one catalog at a time and let garbage collection do its thing while we move onto the next catalog.
But yes, we definitevely can fetch all the data from all catalogs and loop trough it, but the data won't be garbage collectable until after we process whole slice. So we need to find a balance between 1) how much we want to hold in memory and 2) how many network calls we make.
Notice: I haven't tested/measured memory consumption with multipe catalogs. So it is based on gut feeling and maybe it is not very beneficial from memory consumption point of view.
But another benefit of doing one catalog at a time is that it avoids doing more mapping between catalogs, channels and bundles.
ab7400c
to
21d3ac5
Compare
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
21d3ac5
to
2d61258
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This /lgtm, I've taken note of the concerns and hopefully I can help take care of them during the next efforts on the refactor. Thanks Mikalai!
2114da6
Description
Closes #342
This is a minimal set of changes required to switch from
BundleMetadata
API toCatalogMetadata
and remove code duplication between resolution CLI and operator controller itself.I expect more refactoring to be done as part of #347 where we will be removing entities/entity sources from operator controller and switching to
VariableSources
. E.g. we might want to create a wrapper fordeclcfg
structs which makes it easier to traverse catalog (e.g. package might contain refs to channels and channels might contain refs to bundles). But this to be defined separately and out of scope for this PR.The main goal of this PR is to make removal of entities and entity sources easier.
Reviewer Checklist