Skip to content

refactor to move more processing to the API #1082

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

Merged
merged 7 commits into from
Apr 25, 2023

Conversation

grokspawn
Copy link
Contributor

@grokspawn grokspawn commented Mar 28, 2023

Description of the change:
move all parsing and template logic into the API, out of the cobra command parser
facilitate testing of the HTTP access for catalog files

to accomplish this, we exposed a dynamic set of builders as a property of the template, but we didn't want to export it, so that meant unexporting all template fields and leveraging the options pattern to provide access to external callers. This meant that we could mock out the builder interactions with dummy objects to limit test interactions to just this package.
In addition, we moved the http/filesystem processing for the catalogs.yaml access to an exported function so we could utest interactions here.

Motivation for the change:
to facilitate ability to test with different input file/URI

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 28, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 28, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 28, 2023
@codecov
Copy link

codecov bot commented Apr 19, 2023

Codecov Report

Merging #1082 (4a5ad8a) into master (49eae7b) will increase coverage by 0.37%.
The diff coverage is 88.39%.

❗ Current head 4a5ad8a differs from pull request most recent head 097ed19. Consider uploading reports for the commit 097ed19 to get more accurate results

@@            Coverage Diff             @@
##           master    #1082      +/-   ##
==========================================
+ Coverage   52.57%   52.95%   +0.37%     
==========================================
  Files         107      107              
  Lines        9384     9482      +98     
==========================================
+ Hits         4934     5021      +87     
- Misses       3523     3531       +8     
- Partials      927      930       +3     
Impacted Files Coverage Δ
alpha/template/composite/composite.go 89.09% <87.50%> (-10.91%) ⬇️
alpha/template/composite/builder.go 83.44% <90.90%> (-0.12%) ⬇️
pkg/cache/json.go 53.15% <100.00%> (+1.75%) ⬆️
pkg/cache/pkgs.go 70.63% <100.00%> (+1.03%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@grokspawn grokspawn marked this pull request as ready for review April 19, 2023 12:46
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 19, 2023
@openshift-ci openshift-ci bot requested review from benluddy and exdx April 19, 2023 12:46
Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. I have a concern about using cmd.CombinedOutput vs cmd.Output and a few other nits/comments

Comment on lines +30 to +36
switch output {
case "yaml":
// do nothing
case "json":
// do nothing
default:
log.Fatalf("invalid --output value %q, expected (json|yaml)", output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I get what we are going for here, but I think using an if here ends up being more explicit about the intentions and makes it a bit more readable

Suggested change
switch output {
case "yaml":
// do nothing
case "json":
// do nothing
default:
log.Fatalf("invalid --output value %q, expected (json|yaml)", output)
if output != "yaml" && output != "json" {
log.Fatalf("invalid --output value %q, expected (json|yaml)", output)

Copy link
Contributor

@oceanc80 oceanc80 Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1
Unless we think we'll add customizations here for each case, I'd agree that it's a bit clearer using an if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll push back on this one, because I noticed it too but made the conscious choice to perpetuate a common pattern which was also demonstrated in
cmd/opm/init/cmd.go
cmd/opm/render/cmd.go
cmd/opm/alpha/template/basic.go

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but in all three of those cases there is custom logic for the yaml and json cases vs a no-op.
e.g. https://github.com/operator-framework/operator-registry/blob/master/cmd/opm/alpha/template/basic.go#L41-L48

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to @oceanc80's point

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal though, so if you prefer leaving this as is I'm okay with it

grokspawn and others added 6 commits April 24, 2023 14:47
Signed-off-by: Catherine Chan-Tse <[email protected]>
Signed-off-by: Jordan Keister <[email protected]>
Signed-off-by: Jordan Keister <[email protected]>
* refactor a bit and update unit tests

Signed-off-by: Bryce Palmer <[email protected]>

* add more utests and minor tweaks

Signed-off-by: Bryce Palmer <[email protected]>

---------

Signed-off-by: Bryce Palmer <[email protected]>
Signed-off-by: Jordan Keister <[email protected]>
Signed-off-by: Jordan Keister <[email protected]>
Signed-off-by: Jordan Keister <[email protected]>
@grokspawn grokspawn requested a review from everettraven April 24, 2023 20:27
Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Have a comment that could be addressed now or in a follow up - I'll leave it up to you.

Going to hold off on adding the LGTM label to prevent an auto-merge so others have a chance to review

setupErrors := map[string][]string{}
for _, catalog := range catalogs {
errs := []string{}
if catalog.Destination.BaseImage == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be done in a follow up, but is the .Destination.BaseImage field still necessary since we aren't running opm images anymore? If the image isn't going to be taken into account by the rendering process we should probably remove it (or at least comment it out if we plan to use it later) to prevent confusion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this should be commented-out, since I don't think discussion is dead on it right now, but we definitely don't want to enforce it.
However, because dependencies are starting to stack up against this PR refactor, I'd prefer to handle in another PR.

Copy link
Contributor

@oceanc80 oceanc80 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 24, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: everettraven, grokspawn, oceanc80

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@everettraven
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2023
@openshift-merge-robot openshift-merge-robot merged commit 00a4cce into operator-framework:master Apr 25, 2023
@grokspawn grokspawn deleted the cmd-move branch April 25, 2023 18:06
theishshah pushed a commit to theishshah/operator-registry that referenced this pull request Jun 7, 2023
* refactor to move more processing to the template

Signed-off-by: Jordan Keister <[email protected]>

* better diagnostics on custom exec error

Signed-off-by: Jordan Keister <[email protected]>

* Remove obsolete fields

Signed-off-by: Catherine Chan-Tse <[email protected]>
Signed-off-by: Jordan Keister <[email protected]>

* caching wip

Signed-off-by: Jordan Keister <[email protected]>

* refactor a bit and update unit tests (operator-framework#2)

* refactor a bit and update unit tests

Signed-off-by: Bryce Palmer <[email protected]>

* add more utests and minor tweaks

Signed-off-by: Bryce Palmer <[email protected]>

---------

Signed-off-by: Bryce Palmer <[email protected]>
Signed-off-by: Jordan Keister <[email protected]>

* whitespace sanity hell

Signed-off-by: Jordan Keister <[email protected]>

* drop STDERR for nominal case

Signed-off-by: Jordan Keister <[email protected]>

---------

Signed-off-by: Jordan Keister <[email protected]>
Signed-off-by: Catherine Chan-Tse <[email protected]>
Signed-off-by: Bryce Palmer <[email protected]>
Co-authored-by: Catherine Chan-Tse <[email protected]>
Co-authored-by: Bryce Palmer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants