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 with registry add and rm commands #89

Conversation

gallettilance
Copy link
Member

@gallettilance gallettilance commented Sep 26, 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 -b="quay.io/username/imagename,quay.io/username/otherimagename"

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

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

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 26, 2019
@openshift-ci-robot openshift-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 26, 2019
@gallettilance gallettilance changed the title [WIP] Adding top level CLI that combines all others Adding top level CLI that combines all others Sep 26, 2019
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 26, 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.

Just had a comment about the location of the code, otherwise this is pretty much what I was imagining.

@@ -0,0 +1,127 @@
package cli
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 code should still live in the ./cmd folder. Why are we moving it to the ./pkg folder?

Copy link
Member

Choose a reason for hiding this comment

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

And this comment goes for all the different sub commands

Copy link
Member Author

@gallettilance gallettilance Sep 26, 2019

Choose a reason for hiding this comment

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

So for example have a folder cmd/commands where the code that is now in pkg/cli lives? I don't see why that wouldn't work. We would just have to change the Makefile a bit I think. I don't have a good argument why it should live in pkg :)

Copy link
Member

Choose a reason for hiding this comment

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

I'm actually suggesting that you can just leave 95% of this code exactly where it is. You can create your operator-registry command as a file in the root of the existing ./cmd/ folder called main.go that just imports those sub packages. Then just refactor the existing main() functions in each command slightly so that they do exactly what you have done to update them. Right now this PR has a ton of noise that makes it hard to read and I'm just suggesting that we can make this more readable without creating any extraneous files in the ./pkg/ folder.

@kevinrizza
Copy link
Member

looks good to me

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/... | xargs -I{} basename {} | grep -Fv "cli"))
Copy link

Choose a reason for hiding this comment

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

Nit: I think it'd be better to at least use "cmd/cli" here, but it's probably fine.

Copy link

@jpeeler jpeeler Sep 27, 2019

Choose a reason for hiding this comment

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

Oops, I didn't think about the xargs here. A simpler addition would be just to add -w to grep so there's some whole word matching.


func main() {
rootCmd := &cobra.Command{
Use: "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.

let's start the bikeshed:

opreg?

Copy link
Member Author

Choose a reason for hiding this comment

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

I liked what @njhale said at scrum: opm

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member

Choose a reason for hiding this comment

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

krab 🦀

Copy link

Choose a reason for hiding this comment

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

I liked what @njhale said at scrum: opm

What does opm stand for?

Copy link
Contributor

Choose a reason for hiding this comment

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

operator matters :)

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 it was operator package manager

What about opreg for the server stuff (configmap, appregistry, registry-server today), opm for bundle / index stuff (initializer today)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It makes sense to me but didn't we want to combine all these into a single binary?

@ecordell
Copy link
Member

ecordell commented Oct 3, 2019

@gallettilance This is looking good!

I think we just need:

  • the result of the bikeshedding discussion recorded (opm serve, opm build, etc)
  • an update to the readme to acknowledge these new commands
  • a scaffold of a man page / doc that we can update as we add functionality to the root command

@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 10, 2019
@gallettilance gallettilance changed the title Adding top level CLI that combines all others [WIP] Adding top level OPM cli with registry commands Oct 10, 2019
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 10, 2019
@gallettilance gallettilance force-pushed the operator-registry-cli branch 3 times, most recently from ce583bf to 992c745 Compare October 28, 2019 13:21
@kevinrizza kevinrizza mentioned this pull request Oct 28, 2019
5 tasks
@gallettilance gallettilance changed the title [WIP] Adding top level OPM cli with registry commands [WIP] Adding OPM cli with registry add and rm commands Oct 31, 2019
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 31, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 31, 2019
return utilerrors.NewAggregate(errs)
}

// LoadBundleFunc walks the directory. When it sees a `.clusterserviceversion.yaml` file, it
Copy link
Member

Choose a reason for hiding this comment

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

nit: description is wrong

}

// Finally let's delete all the old bundles
if err = i.store.ClearNonDefaultBundles(packageManifest.PackageName); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

this should be behind a flag at least - it limits our options for transitioning (i.e. if I add an image bundle to an existing database, I lose all of my operator history...)

Copy link
Member

Choose a reason for hiding this comment

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

Are you imagining that we want to support a workflow like that? imo if you are using opm it means you are just getting the new stuff that version of opm provides. otherwise it will start getting really hard about reasoning about migrations, for example.

if they want an old catalog, they are still able to use initialize

Copy link
Member Author

@gallettilance gallettilance Oct 31, 2019

Choose a reason for hiding this comment

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

Is there anything in the csv that isn't in the db (as far as function is concerned)?

@gallettilance gallettilance force-pushed the operator-registry-cli branch 2 times, most recently from ee5339c to 5375767 Compare November 1, 2019 01:03

rootCmd.Flags().Bool("debug", false, "enable debug logging")
rootCmd.Flags().StringP("database", "d", "bundles.db", "relative path to database file")
rootCmd.Flags().StringSliceP("bundle-images", "b", []string{}, "comma separated list of links to bundle image")
Copy link
Member

Choose a reason for hiding this comment

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

non-blocking: did we think about making these positional?

opm add -d bundles.db quay.io/my/manifests:1 quay.io/my/manifests:2 

Copy link
Member Author

Choose a reason for hiding this comment

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

That looks cool

AddPackageChannels(manifest PackageManifest) error
RmPackageName(packageName string) error
ClearNonDefaultBundles(packageName string) error
Copy link
Member

Choose a reason for hiding this comment

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

non-blocking: I think these should probably be separate interfaces. we can refactor later.

@@ -135,8 +135,11 @@ func (s *SQLLoader) AddPackageChannels(manifest registry.PackageManifest) error
defer addReplaces.Close()

if _, err := addPackage.Exec(manifest.PackageName); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

instead of this, can we just always "update" package channels, so that it creates if it's not there? (rather than trying to write data and falling back to update on failure?)

non-blocking, we can follow up.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the old format, it was not allowed to have packagename collisions and that's exactly the case in the new format where we are trying to update the db to contain a new version of some operator. I tried to take advantage of that such that when there are no previous versions of an operator in the db it defaults to the old format behavior

@gallettilance gallettilance force-pushed the operator-registry-cli branch 2 times, most recently from 46975ed to babc03c Compare November 1, 2019 14:43
// migrate up to, but not including, this migration
db, migrator, cleanup := CreateTestDbAt(t, migrations.CascadeDeleteMigrationKey-1)
defer cleanup()

Copy link
Member

Choose a reason for hiding this comment

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

you should validate that the table doesn't have the cascades here, before migrating up

func TestCascadeDeleteDown(t *testing.T) {
db, migrator, cleanup := CreateTestDbAt(t, migrations.CascadeDeleteMigrationKey)
defer cleanup()

Copy link
Member

Choose a reason for hiding this comment

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

again - you should validate the correct state here

return err
err = s.updatePackageChannels(tx, manifest)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

should add to the errlist and return the errorlist, right?

if err != nil {
return err
}
return tx.Commit()
Copy link
Member

Choose a reason for hiding this comment

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

same here

if err != nil {
return err
}
if !chanHeadRows.Next() {
Copy link
Member

@ecordell ecordell Nov 1, 2019

Choose a reason for hiding this comment

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

you need to call chanHeadRows.Close() after you scan

bundles[bundleToUpdate.String] = struct{}{}
}

if len(bundles) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

this is fine, but I think we can do this loop with one sql query

}
csvNames = append(csvNames, csvName)
}

Copy link
Member

Choose a reason for hiding this comment

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

close rows

return fmt.Errorf("no default channel found for package %s", packageName)
}
var defaultChannel sql.NullString
if err := defaultChannelRows.Scan(&defaultChannel); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

close defaultChannelRows

return err
}
bundles := make(map[string]struct{}, 0)
for chanBundleRows.Next() {
Copy link
Member

Choose a reason for hiding this comment

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

close rows

Adds opm registry command to add bundle content from images to the
database. For non-default bundles, once the database has been
updated, the bundle and csv field are deleted from all bundles that
are not the tip of the default channel of the package being updated.

Adds opm registry command to rm a package from the database (removing
all owned APIs).
@ecordell
Copy link
Member

ecordell commented Nov 1, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 1, 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 Nov 1, 2019
@ecordell
Copy link
Member

ecordell commented Nov 1, 2019

/refresh

@ecordell
Copy link
Member

ecordell commented Nov 1, 2019

/test e2e-aws

@openshift-merge-robot openshift-merge-robot merged commit 0a888bc into operator-framework:master Nov 1, 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants