-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image digests for referencing bundles
- Change schema of OperatorBundle to include field 'bundlepath' - Extend GetBundle API to return bundle image path - Modify GetBundle API to return struct with avaiable fields instead of error while querrying empty bundles
- Loading branch information
Showing
13 changed files
with
335 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
) | ||
|
||
const BundlePathMigrationKey = 2 | ||
|
||
var bundlePathMigration = &Migration{ | ||
Id: BundlePathMigrationKey, | ||
Up: func(ctx context.Context, tx *sql.Tx) error { | ||
sql := ` | ||
ALTER TABLE operatorbundle | ||
ADD COLUMN bundlepath TEXT; | ||
` | ||
_, err := tx.ExecContext(ctx, sql) | ||
return err | ||
}, | ||
Down: func(ctx context.Context, tx *sql.Tx) error { | ||
foreingKeyOff := `PRAGMA foreign_keys = 0` | ||
createTempTable := `CREATE TABLE operatorbundle_backup (name TEXT,csv TEXT,bundle TEXT)` | ||
backupTargetTable := `INSERT INTO operatorbundle_backup SELECT name,csv,bundle FROM operatorbundle` | ||
dropTargetTable := `DROP TABLE operatorbundle` | ||
renameBackUpTable := `ALTER TABLE operatorbundle_backup RENAME TO operatorbundle;` | ||
foreingKeyOn := `PRAGMA foreign_keys = 1` | ||
_, err := tx.ExecContext(ctx, foreingKeyOff) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = tx.ExecContext(ctx, createTempTable) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = tx.ExecContext(ctx, backupTargetTable) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = tx.ExecContext(ctx, dropTargetTable) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = tx.ExecContext(ctx, renameBackUpTable) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = tx.ExecContext(ctx, foreingKeyOn) | ||
return err | ||
}, | ||
} | ||
|
||
// Register this migration | ||
func init() { | ||
migrations[BundlePathMigrationKey] = bundlePathMigration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package migrations_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/operator-framework/operator-registry/pkg/sqlite" | ||
"github.com/operator-framework/operator-registry/pkg/sqlite/migrations" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBundlePathUp(t *testing.T) { | ||
db, migrator, cleanup := CreateTestDbAt(t, migrations.BundlePathMigrationKey-1) | ||
defer cleanup() | ||
|
||
err := migrator.Up(context.TODO(), migrations.Only(migrations.BundlePathMigrationKey)) | ||
require.NoError(t, err) | ||
|
||
// Adding row with bundlepath colum should not fail after migrating up | ||
tx, err := db.Begin() | ||
stmt, err := tx.Prepare("insert into operatorbundle(name, csv, bundle, bundlepath) values(?, ?, ?, ?)") | ||
require.NoError(t, err) | ||
defer stmt.Close() | ||
|
||
_, err = stmt.Exec("testName", "testCSV", "testBundle", "quay.io/test") | ||
require.NoError(t, err) | ||
|
||
} | ||
|
||
func TestBundlePathDown(t *testing.T) { | ||
db, migrator, cleanup := CreateTestDbAt(t, migrations.BundlePathMigrationKey) | ||
defer cleanup() | ||
|
||
querier := sqlite.NewSQLLiteQuerierFromDb(db) | ||
imagesBeforeMigration, err := querier.GetImagesForBundle(context.TODO(), "etcdoperator.v0.6.1") | ||
|
||
err = migrator.Down(context.TODO(), migrations.Only(migrations.BundlePathMigrationKey)) | ||
require.NoError(t, err) | ||
|
||
imagesAfterMigration, err := querier.GetImagesForBundle(context.TODO(), "etcdoperator.v0.6.1") | ||
|
||
// Migrating down entails sensitive operations. Ensure data is preserved accross down migration | ||
require.Equal(t, len(imagesBeforeMigration), len(imagesAfterMigration)) | ||
} |
Oops, something went wrong.