-
Notifications
You must be signed in to change notification settings - Fork 249
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
Add support for storing and retrieving related images #101
Conversation
a9c2b74
to
91e63e7
Compare
f0d89c4
to
77b1ce2
Compare
@@ -98,3 +103,23 @@ func runRegistryServeCmdFunc(cmd *cobra.Command, args []string) error { | |||
|
|||
return nil | |||
} | |||
|
|||
func migrate(cmd *cobra.Command, db *sql.DB) error { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
77b1ce2
to
d172330
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
d172330
to
808bb02
Compare
@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.
808bb02
to
8415c18
Compare
to the latest
1edebcc
to
addcd23
Compare
/lgtm |
[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 |
/retest |
Description of the change:
This is based on #100, which should merge first.
This adds two new
Query
methods:The bundle abstraction now also understands the images in the
containers
andinitContainers
fields of a CSV, and therelatedImages
field:Motivation for the change:
See the proposal, this is primarily to support disconnected mirroring of a catalog.
Reviewer Checklist
/docs
Replaces #62