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

Add support for storing and retrieving related images #101

Merged

Conversation

ecordell
Copy link
Member

Description of the change:

This is based on #100, which should merge first.

This adds two new Query methods:

type Query interface { 
  ListImages(ctx context.Context) ([]string, error)
  GetImagesForBundle(ctx context.Context, bundleName string) ([]string, error)
  // ...
}

The bundle abstraction now also understands the images in the containers and initContainers fields of a CSV, and the relatedImages field:

kind: ClusterServiceVersion 
spec:
  relatedImages:
  - name: default
    image: quay.io/coreos/etcd@sha256:12345 
  - name: etcd-2.1.5
    image: quay.io/coreos/etcd@sha256:12345 
  - name: etcd-3.1.1
    image: quay.io/coreos/etcd@sha256:12345 

Motivation for the change:

See the proposal, this is primarily to support disconnected mirroring of a catalog.

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

Replaces #62

@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 22, 2019
@ecordell ecordell force-pushed the relatedimages branch 2 times, most recently from a9c2b74 to 91e63e7 Compare October 22, 2019 23:21
@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 23, 2019
@ecordell ecordell force-pushed the relatedimages branch 3 times, most recently from f0d89c4 to 77b1ce2 Compare October 24, 2019 13:16
@@ -98,3 +103,23 @@ func runRegistryServeCmdFunc(cmd *cobra.Command, args []string) error {

return nil
}

func migrate(cmd *cobra.Command, db *sql.DB) error {
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 duplicated this for now; I didn't want to refactor the commands and make this PR bigger than it already is.

@@ -187,3 +191,74 @@ func (csv *ClusterServiceVersion) GetApiServiceDefinitions() (owned []*Definitio
required = definitions.Required
return
}

// GetRelatedImage returns the list of associated images for the operator
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the where related and operator images are extracted

return err
}
// TODO: bulk insert
for img := range imgs {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where related/operator images are stored


var initMigration = &Migration{
Id: InitMigrationKey,
Up: func(ctx context.Context, tx *sql.Tx) error {
Copy link
Member Author

Choose a reason for hiding this comment

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

This migration brings an empty DB up to where the schema from before we had migrations.

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 do this we lose the ability to run migrations on registry databases that were built before this migrator was added. I think that's fine, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching this - I had intended to go back and make another migrator method that migrates from the current version up to the latest version. Added and updated.

if err != nil {
return err
}
for _, bundle := range bundles {
Copy link
Member Author

Choose a reason for hiding this comment

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

This backfills the related_image table for existing stored bundles

if err != nil {
return err
}
for _, migration := range migrations {
Copy link
Member Author

Choose a reason for hiding this comment

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

The bulk of the migrator is here


type MigrationSet map[int]*Migration

var migrations MigrationSet = make(map[int]*Migration)
Copy link
Member Author

@ecordell ecordell Oct 24, 2019

Choose a reason for hiding this comment

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

this map is built up in init methods in the migration files

Copy link
Contributor

@anik120 anik120 left a comment

Choose a reason for hiding this comment

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

Looks good @ecordell.

Just had a question about a down migration, and also, do you think including a doc that documents how to use the migration (file format, generate bin data etc) with this PR is a good idea?

},
Down: func(ctx context.Context, tx *sql.Tx) error {
sql := `
DROP TABLE operatorbundle;
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't trying to drop tables without switching off foreign key constraints fail?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great note - this will succeed because it will also drop all of the tables with the foreign key refs.

I'll update to enable foreign keys on these tests so that we catch future issues like this.

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.

Looks great, just had very small comments. Otherwise it should be good to merge.


var initMigration = &Migration{
Id: InitMigrationKey,
Up: func(ctx context.Context, tx *sql.Tx) error {
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 do this we lose the ability to run migrations on registry databases that were built before this migrator was added. I think that's fine, though.

pkg/registry/csv.go Show resolved Hide resolved
@ecordell
Copy link
Member Author

@anik120 I enabled foreign keys for the tests and added a doc on adding migrations.

the migrations package we were using didn't allow for backfills
this uses the `relatedImages` field from the CSV and also extracts
operator images from the deployment specs of CSVs.
@kevinrizza
Copy link
Member

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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

@ecordell
Copy link
Member Author

/retest

@openshift-merge-robot openshift-merge-robot merged commit 161f66a into operator-framework:master Oct 24, 2019
@ecordell ecordell deleted the relatedimages branch October 24, 2019 21:55
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.

5 participants