Skip to content
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

Proposal: apb tool refactor #197

Closed

Conversation

rthallisey
Copy link
Contributor

No description provided.

@dymurray dymurray self-assigned this Jan 12, 2018
@mhrivnak
Copy link
Member

One aspect that adds substantial noise and overhead to the "engine" today is printing output. I suggest that would be best paired with the other CLI parts. The actions themselves, currently called "commands", would be more like a library that just gets stuff done.

cli.go (or cli.py) would have all of the Subcommand features you listed. It would parse+validate input, determine the correct function to call that will perform real work, and call it with the right arguments. Additionally I'm suggesting that it would receive a return value from that function, and then be fully responsible for all output to stdout.

This would isolate output serialization decisions, such as yaml or json or pretty-print or other, which fields to include, etc. to the same part of code that handles input. For example:

cli.go would have a subcommand for apb list. It would parse and validate arguments somehow. It would then call the correct function in commands/broker_requests/apb_list.go. The return value would be a collection of results in native golang structures. Then the subcommand would serialize those results in the appropriate way, based on user input (-o something), and print them to stdout.

Thoughts on that?

If we went that direction, we might then consider having a commands package that holds everything cli.go has plus whatever serialization code there is, and a separate actions or lib package (not sure of the best name) that contains the remaining "engine" code (of course organized into classes as proposed).

into a series of classes in order to reuse code and unifiy duplicate code paths.

If the community is interested in changing the apb tool's structure then there
should be an addition consideration. Most of the future work for the apb tool
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: additional

@rthallisey
Copy link
Contributor Author

@mhrivnak that sounds good to me. I'll make sure your comment is reflected in the proposal.



## Python to Golang discussion
Changing from Python to Go will benifit the apb execution future work. But,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: benefit

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the cross-section between how the apb tool touches the things written in python and the things written in golang should be weighed. If we make heavy use of external python libraries from say ansible, then it might be helpful to keep it in python. If not, then re-writing to make use of bundle-lib makes sense.

The subcommands will be classified into 3 groups:
- Broker subcommands
- Docker subcommands
- Apb directory subcommands
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth adding direct OCP subcommands? I'm thinking of instances across the code where we are creating service accounts and checking for OCP resources. Perhaps it's not really a subcommand but more of a client package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we can do is initialize the OCP data like the token and OCP functions in the base class base.go. So in that case it would be like a client package. Or we can have a class for the Cluster (openshift/kubernetes) and initialize that in base.go.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, makes sense to me.

@shawn-hurley
Copy link
Contributor

I would like to suggest that use the cobra library for developing the commands in go.

@eriknelson
Copy link
Contributor

We've been having a lot of conversations in the broker project about breaking the current repo into 3 projects. The relevant one would be a libapb, which would directly affect this effort. Fortunately, I think it should make this easier. The basic idea is that the bulk of the actual APB logic, data structures, validation, execution etc., will be vendorable via libapb. It is the authoritative project for all things APB. Anyone working with APBs can standardize on top of this library and benefit from upstream feature development and maintenance. It also means libapb consumers become lean layers on top of it, only containing their particular concerns. apb becomes basically just a cli wrapper for driving libapb.

@eriknelson
Copy link
Contributor

It would be interesting to continue the discussion around this in light of the past month's work. Since my last comment, APB should be replaced with "Service Bundle", and we actually have a vendorable bundle-lib that is effectively what I described as libapb thanks to @shawn-hurley's work.

@jmrodri
Copy link
Contributor

jmrodri commented Mar 9, 2018

@shawn-hurley @eriknelson is cobra really the best CLI parsing for golang? When I used it for my sm-photo-tool project I wasn't a fan. I found it intrusive. But it's been a year since I last played with it.

Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

typo changes

involves facilitating execution of an apb. This work, in python, is going to be
more difficult than if it were written in go because an apb tool written in go
can vendor the broker. This would reduce the amount of work to add the features,
isolate the code maintainace to the broker's code paths, and give the community
Copy link
Contributor

Choose a reason for hiding this comment

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

TYPO: maintainace -> maintenance

more difficult than if it were written in go because an apb tool written in go
can vendor the broker. This would reduce the amount of work to add the features,
isolate the code maintainace to the broker's code paths, and give the community
an addition way to test broker code.
Copy link
Contributor

Choose a reason for hiding this comment

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

TYPO: addition -> additional

an addition way to test broker code.

Finally, my proposal to the community is to change the structure of the apb tool
in a two ways:
Copy link
Contributor

Choose a reason for hiding this comment

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

TYPO: a two -> two

- Apb directory subcommands

```cli.go``` will expect a return value from the subcommand it called. Based on
that subcommand, the return value will be processed before its printed to
Copy link
Contributor

Choose a reason for hiding this comment

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

TYPO: its -> it's


This leads me to propose to the community that I think the apb tool should
undergo some major changes. The focus would be to break apart ```engine.py```
into a series of classes in order to reuse code and unifiy duplicate code paths.
Copy link
Contributor

Choose a reason for hiding this comment

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

TYPO: unifiy -> unify

@eriknelson
Copy link
Contributor

eriknelson commented Mar 9, 2018

@jmrodri it feels like the community's default. I don't think that's enough to warrant a blank pass, but there's a lot of precedence and value in using what everybody else is using. I don't have enough experience with it to assert an opinion. I'll give it a try this weekend and weigh-in.

@shawn-hurley
Copy link
Contributor

@jmrodri I would like to hear how it was intrusive?I agree with @eriknelson tt does seem to be the standard that most people are using.

@dymurray
Copy link
Contributor

@rthallisey do we want to merge this in and continue work on the google doc/second PR we have open?

@rthallisey
Copy link
Contributor Author

@dymurray I forgot about this PR. I'll merge the relevant bits with #279. Then we can continue updating the google doc and I'll pull it all together for one final product.

@rthallisey rthallisey closed this Jun 11, 2018
@rthallisey
Copy link
Contributor Author

work has already begun here: https://github.com/automationbroker/sbcli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants