-
Notifications
You must be signed in to change notification settings - Fork 239
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
render: add alpha support for filtering #1231
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1231 +/- ##
==========================================
+ Coverage 50.06% 55.08% +5.01%
==========================================
Files 135 113 -22
Lines 12995 11577 -1418
==========================================
- Hits 6506 6377 -129
+ Misses 5405 4207 -1198
+ Partials 1084 993 -91 ☔ View full report in Codecov by Sentry. |
alpha/declcfg/filter/filter.go
Outdated
type Filterer interface { | ||
FilterCatalog(ctx context.Context, fbc *declcfg.DeclarativeConfig) (*declcfg.DeclarativeConfig, error) | ||
} | ||
|
||
type MetaFilterer interface { | ||
KeepMeta(meta *declcfg.Meta) bool | ||
} |
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.
Nit: Andy did a great job of getting this stuck in my head over the course of a few PRs: https://go.dev/wiki/CodeReviewComments#interfaces
The gist is that the interfaces should be defined where the values of the interface are used and not by the package that implements them. I'm not strongly opinionated on this (yet) but is something that crossed my mind while reviewing so figured I would point it out.
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.
Yep, this is an outcome of the way this code evolved before I submitted it. I'll move it to the declcfg
package.
alpha/action/render.go
Outdated
if r.Filterer != nil { | ||
if metaFilterer, ok := r.Filterer.(filter.MetaFilterer); ok { | ||
keepMeta = metaFilterer.KeepMeta | ||
} | ||
} |
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.
Why not have an explicit field for the MetaFilterer
?
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.
At the time, I think it was because I was actually implementing inlined functions with that same signature, so it was lighter weight than implementing a full struct.
I'll add a function type that implements the interface (sorta like http.Handler and http.HandlerFunc).
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.
I'm also thinking about names... the age old problem.
} | ||
} | ||
|
||
func (f *filterer) FilterCatalog(_ context.Context, fbc *declcfg.DeclarativeConfig) (*declcfg.DeclarativeConfig, 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.
Is it anticipated that the context will be required by some implementation of the filterer interface? If not, we can probably remove it from the interface and as a parameter from this function
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.
I've seen context.Context
get added to so many functions at this point that I pretty much add it defensively for functions I expect:
- could be long running
- could need to call other functions that accept a context
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.
Ok, I'm going to leave it in. One possibility I thought of is an interaction with an OCI registry to get the labels of bundle images and filter based on them. I'm considering adding a context to the meta filter signature as well for the same reason. WDYT?
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.
IMHO, we should have it for consistency reasons (most of the declcfg code follows this convention), but it's also proven really helpful when we refactored for parallelism previously, and the downside ... ?
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.
I think it's fine to include if we are anticipating the addition of a filtering method that will use it in the near future. Just calling out that it may be a premature optimization that could be added in the future when needed.
I also am not strongly opinionated here so if folks feel strongly we should keep it - fine by me
alpha/declcfg/filter/packages.go
Outdated
keepPackages sets.Set[string] | ||
} | ||
|
||
func (f *packageFilter) FilterCatalog(ctx context.Context, fbc *declcfg.DeclarativeConfig) (*declcfg.DeclarativeConfig, 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.
My eyes could be deceiving me, but looks like this function doesn't use the ctx
parameter.
alpha/declcfg/load.go
Outdated
type pathMetas struct { | ||
path string | ||
metas []pathMeta | ||
} | ||
|
||
type pathMeta struct { | ||
meta *Meta | ||
err 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.
What are these for? I can't seem to see where they are being used, am I just missing it?
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.
Oh good catch. PR went through some optimization iteration and these are now unused.
cmd/opm/render/cmd.go
Outdated
var obj struct { | ||
metav1.TypeMeta `json:",inline"` | ||
} | ||
if err := yaml.Unmarshal(data, &obj); err != nil { | ||
return nil, err | ||
} | ||
|
||
if obj.Kind != "FilterConfiguration" { | ||
return nil, fmt.Errorf("unexpected kind %q", obj.Kind) | ||
} | ||
|
||
switch obj.APIVersion { | ||
case "olm.operatorframework.io/v1alpha1": | ||
cfg, err := configv1alpha1.LoadFilterConfiguration(data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return configv1alpha1.NewFilterer(cfg, configv1alpha1.WithLogger(log)), nil | ||
default: | ||
return nil, fmt.Errorf("unexpected API version %q", obj.APIVersion) | ||
} |
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.
It looks like the configv1alpha1.LoadFilterConfiguration
function already performs validation. Could this whole thing just be simplified to something like:
if filterFile == "" {
return nil, nil
}
data, err := os.ReadFile(filterFile)
if err != nil {
return nil, err
}
cfg, err := configv1alpha1.LoadFilterConfiguration(data)
if err != nil {
return nil, err
}
return configv1alpha1.NewFilterer(cfg, configv1alpha1.WithLogger(log)), nil
?
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.
I do realize that maybe this isn't as extensible because it only validates against the specific config version but this could be updated when/if we add another version
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.
+1, this is premature optimization. I'll reduce and add some comments about what we might do if we add new config file versions.
c47b060
to
29c9db1
Compare
3a2da31
to
4e18534
Compare
Here's the promised
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: everettraven, joelanford The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This commit adds two alpha flags to `opm render` and updates FBC library code to support efficient filtering of FBC: - `--alpha-filter-config=./path/to/config` - `--alpha-keep-packages=pkg1,pkg2` To support the filter config option, this commits defines a new configuration file format that supports: - filtering by package - within a package, filtering by channel - within a package, selecting a new default channel (required if the original default channel is filtered out) - within each channel, filtering by a version range In order to support correct version range filtering, some bundles that fall outside the version range may remain in the channel to ensure that the filtered channel is still valid and includes all bundles that did fall in the range Included in this commit is an update to declcfg.WalkMetasFS to enable concurrency, similar to recent changes in declcfg.LoadFS. declcfg.LoadFS is also refactored internally to use the new declcfg.WalkMetasFS implementation. Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
/override go-apidiff |
@perdasilva: Overrode contexts on behalf of perdasilva: go-apidiff In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/hold to discuss with another team |
@joelanford I tried to resolve conflicts using the GitHub UI |
I think we're going to eventually close this, and hand the important bits of code to a stakeholder. For now, there is some consensus among maintainers that this is beyond the scope of core |
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Description of the change:
This commit adds two alpha flags to
opm render
and updates FBC library code to support efficient filtering of FBC:--alpha-filter-config=./path/to/config
--alpha-keep-packages=pkg1,pkg2
To support the filter config option, this commits defines a new configuration file format that supports:
In order to support correct version range filtering, some bundles that fall outside the version range may remain in the channel to ensure that the filtered channel is still valid and includes all bundles that did fall in the range
Included in this commit is an update to declcfg.WalkMetasFS to enable concurrency, similar to recent changes in declcfg.LoadFS. declcfg.LoadFS is also refactored internally to use the new declcfg.WalkMetasFS implementation.
Motivation for the change:
There are two motivations:
render
is significantly faster than rendering an entire catalog and then using a post-render tool like jq or yq to filter after the fact.I ran the existing benchmark to confirm that this update does not regress performance, even in the case of no filtering being applied. I will post those results in a comment.
Reviewer Checklist
/docs