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

Adding opm CLI #96

Merged

Conversation

gallettilance
Copy link
Member

@gallettilance gallettilance commented Oct 10, 2019

Description of the change:

Adding a new cli to operator-registry called opm. It can add bundles to a database, delete packages from that db and serve its contents at a specified host and port.

Having built the binaries, a user can run the old binaries

./bin/initializer ...
./bin/appregistry-server ...
./bin/registry-server ...
./bin/configmap-server ...

or can use the new cli that supports (and will support) our new operator bundle format. Here is an example flow:

Build the database (or add to an existing one) using

./bin/opm registry add -d=bundles.db -m=quay.io/username/imagename

Remove operators from an existing db using

./bin/opm registry rm -d=bundles.db -o="operator-package-name"

Serve the db using (can optionally specify a host and port)

./bin/opm registry serve -t=path/to/file.log -d=bundles.db

Implemented here

In this PR we are adding the opm cli and a sub-command registry. The registry command itself has a subcommand called serve which serves the contents of an operator-registry database (created from an index image, using bundles in the new format, etc - note that how to create and modify that database will be in a follow up PR)

Motivation for the change:

This is a first step toward creating new commands to interface with operator-registry as part of its corresponding epic.

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

Sorry, something went wrong.

@openshift-ci-robot openshift-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 10, 2019
Copy link
Member

@njhale njhale left a comment

Choose a reason for hiding this comment

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

Wow, looking really great! I jotted down some thoughts I had:

return nil
},

RunE: runRegistryServerCmdFunc,
Copy link
Member

Choose a reason for hiding this comment

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

Another option is to call runOpmRegistryServeCmdFunc instead and drop the definition of runRegistryServerCmdFunc.

)

// NewOpmRegistryCmd returns the appregistry-server command
func NewOpmRegistryCmd() *cobra.Command {
Copy link
Member

Choose a reason for hiding this comment

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

What about NewRegistryCmd instead?

Makefile Outdated
MOD_FLAGS := $(shell (go version | grep -q -E "1\.(11|12)") && echo -mod=vendor)
CMDS := $(addprefix bin/, $(shell go list $(MOD_FLAGS) ./cmd/... | xargs -I{} basename {}))
CMDS := $(addprefix bin/, $(shell go list $(MOD_FLAGS) ./cmd/... | grep -Fv "github.com/operator-framework/operator-registry/cmd/cli" |xargs -I{} basename {}))
Copy link
Member

Choose a reason for hiding this comment

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

If we keep the command declarations in separate top level packages, we don't need to do this right?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean put this in pkg instead of cmd?

Copy link
Member

Choose a reason for hiding this comment

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

I mean cmd/initializer, cmd/registry, cmd/opm, and forgo extracting the commands out to cmd/cli -- but it seems like everyone has a different opinion on this, so feel free to ignore.


func main() {
rootCmd := &cobra.Command{
Use: "opm",
Copy link
Member

Choose a reason for hiding this comment

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

😄

@ecordell
Copy link
Member

ecordell commented Oct 12, 2019

@gallettilance I made a separate PR (#98) to address the foreign key issues; can you remove it from this one so that tests are passing?

@gallettilance gallettilance force-pushed the opm-cli branch 2 times, most recently from c9357f3 to 49d80f5 Compare October 15, 2019 13:29
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 15, 2019
Copy link
Member

@kevinrizza kevinrizza left a comment

Choose a reason for hiding this comment

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

Had a few nits, otherwise this is looking good.

Makefile Outdated
@@ -1,5 +1,5 @@
MOD_FLAGS := $(shell (go version | grep -q -E "1\.(11|12)") && echo -mod=vendor)
CMDS := $(addprefix bin/, $(shell go list $(MOD_FLAGS) ./cmd/... | xargs -I{} basename {}))
CMDS := $(addprefix bin/, $(shell go list $(MOD_FLAGS) ./cmd/... | grep -v opm/... | xargs -I{} basename {}))
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to continue to use go list like this? Maybe we should just explicitly list the things we build rather than rely on using this command and ignoring part of the result? Or at least should we have a heuristic for determining it (like only look at the packages in the root of ./cmd/?

@dinhxuanvu Any thoughts on this? I know you most likely have a similar problem with the bundle build command you are adding.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Curious to see what @dinhxuanvu 's opinion is

Copy link
Member

Choose a reason for hiding this comment

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

So the plan for me is to separate the functional code of my bundle PR to have it as a package living under /pkg and the cobra command code (the rest) will live under /opm/bundle/... and it will consume the bundle package.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we want to omit opm from the build?

Copy link
Member

Choose a reason for hiding this comment

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

@dinhxuanvu I thought we wanted to expose the bundle build as a command that wasn't built as part of any of our existing utilities? and then we create another pr against operator-sdk that consumed that cobra thing? We can create our own test utility that can also use that cobra thing but we won't publish it, just use it to test. but I was expecting it to NOT be part of opm.

@ecordell I think he just meant that he doesn't want the subcommand packages to be part of the list of things that should be called by go build. Those packages don't have main.go files so the command that's in the makefile now will throw an error.

Copy link
Member

Choose a reason for hiding this comment

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

I think this will do what we want:

CMDS  := $(addprefix bin/, $(shell ls ./cmd))

Copy link
Member

Choose a reason for hiding this comment

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

@kevinrizza You are correct. The ultimate usage for bundle library would be on SDK side. The users won't use bundle commands as a part of opm binary. I'm planning to add bundle commands with hidden flag on cobra. So we know they are there and available for internal use but they won't show up in the list of available commands.

cmd/opm/main.go Outdated
rootCmd := &cobra.Command{
Use: "opm",
Short: "operator package manager",
Long: "Top level CLI for operator-registry",
Copy link
Member

Choose a reason for hiding this comment

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

Is this long description accurate anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

func NewOpmRegistryCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "registry",
Short: "registry",
Copy link
Member

Choose a reason for hiding this comment

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

I think you want Short to have a slightly longer description that defines what it actually does. Otherwise --help won't really tell you anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

func newRegistryServeCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "serve",
Short: "serve",
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above about Short

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

@gallettilance gallettilance force-pushed the opm-cli branch 2 times, most recently from 1501048 to 8bf56ad Compare October 17, 2019 13:54
@openshift-ci-robot openshift-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 17, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 17, 2019
@ecordell
Copy link
Member

/lgtm

/retest

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 17, 2019
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ecordell, gallettilance

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 17, 2019
@openshift-merge-robot openshift-merge-robot merged commit b81f428 into operator-framework:master Oct 17, 2019
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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants