Adding OPM cli with registry add and rm commands#89
Conversation
kevinrizza
left a comment
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
I think this code should still live in the ./cmd folder. Why are we moving it to the ./pkg folder?
There was a problem hiding this comment.
And this comment goes for all the different sub commands
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
eb27824 to
a451f63
Compare
|
looks good to me |
| @@ -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")) | |||
There was a problem hiding this comment.
Nit: I think it'd be better to at least use "cmd/cli" here, but it's probably fine.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
let's start the bikeshed:
opreg?
There was a problem hiding this comment.
I liked what @njhale said at scrum:
opm
What does opm stand for?
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
It makes sense to me but didn't we want to combine all these into a single binary?
a451f63 to
0654051
Compare
|
@gallettilance This is looking good! I think we just need:
|
0654051 to
d83485b
Compare
ce583bf to
992c745
Compare
992c745 to
a04dc1b
Compare
82202a2 to
4ffe4bd
Compare
4ffe4bd to
de2dd43
Compare
| return utilerrors.NewAggregate(errs) | ||
| } | ||
|
|
||
| // LoadBundleFunc walks the directory. When it sees a `.clusterserviceversion.yaml` file, it |
| } | ||
|
|
||
| // Finally let's delete all the old bundles | ||
| if err = i.store.ClearNonDefaultBundles(packageManifest.PackageName); err != nil { |
There was a problem hiding this comment.
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...)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Is there anything in the csv that isn't in the db (as far as function is concerned)?
ee5339c to
5375767
Compare
|
|
||
| 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") |
There was a problem hiding this comment.
non-blocking: did we think about making these positional?
opm add -d bundles.db quay.io/my/manifests:1 quay.io/my/manifests:2
| AddBundlePackageChannels(manifest PackageManifest, bundle Bundle) error | ||
| AddPackageChannels(manifest PackageManifest) error | ||
| RmPackageName(packageName string) error | ||
| ClearNonDefaultBundles(packageName string) error |
There was a problem hiding this comment.
non-blocking: I think these should probably be separate interfaces. we can refactor later.
5375767 to
9f217f2
Compare
| @@ -135,8 +135,11 @@ func (s *SQLLoader) AddPackageChannels(manifest registry.PackageManifest) error | |||
| defer addReplaces.Close() | |||
|
|
|||
| if _, err := addPackage.Exec(manifest.PackageName); err != nil { | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
46975ed to
babc03c
Compare
| // migrate up to, but not including, this migration | ||
| db, migrator, cleanup := CreateTestDbAt(t, migrations.CascadeDeleteMigrationKey-1) | ||
| defer cleanup() | ||
|
|
There was a problem hiding this comment.
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() | ||
|
|
There was a problem hiding this comment.
again - you should validate the correct state here
| return err | ||
| err = s.updatePackageChannels(tx, manifest) | ||
| if err != nil { | ||
| return err |
There was a problem hiding this comment.
should add to the errlist and return the errorlist, right?
| if err != nil { | ||
| return err | ||
| } | ||
| return tx.Commit() |
| if err != nil { | ||
| return err | ||
| } | ||
| if !chanHeadRows.Next() { |
There was a problem hiding this comment.
you need to call chanHeadRows.Close() after you scan
| bundles[bundleToUpdate.String] = struct{}{} | ||
| } | ||
|
|
||
| if len(bundles) > 0 { |
There was a problem hiding this comment.
this is fine, but I think we can do this loop with one sql query
| } | ||
| csvNames = append(csvNames, csvName) | ||
| } | ||
|
|
| return fmt.Errorf("no default channel found for package %s", packageName) | ||
| } | ||
| var defaultChannel sql.NullString | ||
| if err := defaultChannelRows.Scan(&defaultChannel); err != nil { |
| return err | ||
| } | ||
| bundles := make(map[string]struct{}, 0) | ||
| for chanBundleRows.Next() { |
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).
babc03c to
d9c97cd
Compare
|
/lgtm |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/refresh |
|
/test e2e-aws |
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
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
Remove operators from an existing db using
Serve the db using (can optionally specify a host and port)
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
/docs