-
Notifications
You must be signed in to change notification settings - Fork 253
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
refactor to move more processing to the API #1082
Conversation
Skipping CI for Draft Pull Request. |
Codecov Report
@@ 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
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
Overall looks good. I have a concern about using cmd.CombinedOutput
vs cmd.Output
and a few other nits/comments
switch output { | ||
case "yaml": | ||
// do nothing | ||
case "json": | ||
// do nothing | ||
default: | ||
log.Fatalf("invalid --output value %q, expected (json|yaml)", output) |
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: 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
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) |
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
Unless we think we'll add customizations here for each case, I'd agree that it's a bit clearer using an if statement.
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'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
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.
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
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 to @oceanc80's point
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.
Not a huge deal though, so if you prefer leaving this as is I'm okay with it
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: 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]>
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.
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 == "" { |
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 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
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 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.
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.
lgtm
[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 |
/lgtm |
* 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]>
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
/docs