Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 61 additions & 44 deletions pkg/api/registry.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/api/registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ message Bundle{
string bundlePath = 6;
repeated GroupVersionKind providedApis = 7;
repeated GroupVersionKind requiredApis = 8;
string version = 9;
string skipRange = 10;
}

message ChannelEntry{
Expand Down
5 changes: 2 additions & 3 deletions pkg/mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ func (b *IndexImageMirrorer) Mirror() (map[string]string, error) {

var errs []error
for _, img := range images {
ref, err := reference.ParseNamed(img)
ref, err := reference.ParseNormalizedNamed(img)
if err != nil {
errs = append(errs, fmt.Errorf("couldn't parse image for mirroring (%s), skipping mirror: %s", img, err.Error()))
continue
}

domain := reference.Domain(ref)
mapping[img] = b.Dest + strings.TrimPrefix(img, domain)
mapping[ref.String()] = b.Dest + strings.TrimPrefix(ref.String(), domain)
}

if err := b.ImageMirrorer.Mirror(mapping); err != nil {
Expand Down
10 changes: 7 additions & 3 deletions pkg/mirror/mirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ func TestIndexImageMirrorer_Mirror(t *testing.T) {
"quay.io/coreos/prometheus-operator@sha256:0e92dd9b5789c4b13d53e1319d0a6375bcca4caaf0d698af61198061222a576d":"localhost/coreos/prometheus-operator@sha256:0e92dd9b5789c4b13d53e1319d0a6375bcca4caaf0d698af61198061222a576d",
"quay.io/coreos/prometheus-operator@sha256:3daa69a8c6c2f1d35dcf1fe48a7cd8b230e55f5229a1ded438f687debade5bcf":"localhost/coreos/prometheus-operator@sha256:3daa69a8c6c2f1d35dcf1fe48a7cd8b230e55f5229a1ded438f687debade5bcf",
"quay.io/coreos/prometheus-operator@sha256:5037b4e90dbb03ebdefaa547ddf6a1f748c8eeebeedf6b9d9f0913ad662b5731":"localhost/coreos/prometheus-operator@sha256:5037b4e90dbb03ebdefaa547ddf6a1f748c8eeebeedf6b9d9f0913ad662b5731",
"docker.io/strimzi/cluster-operator:0.11.0": "localhost/strimzi/cluster-operator:0.11.0",
"docker.io/strimzi/cluster-operator:0.11.1": "localhost/strimzi/cluster-operator:0.11.1",
"docker.io/strimzi/operator:0.12.1": "localhost/strimzi/operator:0.12.1",
"docker.io/strimzi/operator:0.12.2": "localhost/strimzi/operator:0.12.2",
},
// strimzi has invalid images in its manifests, so we both return a list of maps and an error
wantErr: fmt.Errorf("[couldn't parse image for mirroring (strimzi/cluster-operator:0.11.0), skipping mirror: repository name must be canonical, couldn't parse image for mirroring (strimzi/cluster-operator:0.11.1), skipping mirror: repository name must be canonical, couldn't parse image for mirroring (strimzi/operator:0.12.1), skipping mirror: repository name must be canonical, couldn't parse image for mirroring (strimzi/operator:0.12.2), skipping mirror: repository name must be canonical]"),
},
}
for _, tt := range tests {
Expand All @@ -95,7 +97,9 @@ func TestIndexImageMirrorer_Mirror(t *testing.T) {
Dest: tt.fields.Dest,
}
got, err := b.Mirror()
require.Equal(t, tt.wantErr.Error(), err.Error())
if err != nil {
require.Equal(t, tt.wantErr.Error(), err.Error())
}
require.Equal(t, tt.want, got)
})
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/sqlite/migrations/000_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (

var InitMigrationKey = 0

func init() {
registerMigration(InitMigrationKey, initMigration)
}

var initMigration = &Migration{
Id: InitMigrationKey,
Up: func(ctx context.Context, tx *sql.Tx) error {
Expand Down Expand Up @@ -72,7 +76,3 @@ var initMigration = &Migration{
return err
},
}

func init() {
migrations[InitMigrationKey] = initMigration
}
2 changes: 1 addition & 1 deletion pkg/sqlite/migrations/001_related_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const RelatedImagesMigrationKey = 1

func init() {
migrations[RelatedImagesMigrationKey] = relatedImagesMigration
registerMigration(RelatedImagesMigrationKey, relatedImagesMigration)
}

// listBundles returns a list of operatorbundles as strings
Expand Down
10 changes: 5 additions & 5 deletions pkg/sqlite/migrations/002_bundle_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const BundlePathMigrationKey = 2

// Register this migration
func init() {
migrations[BundlePathMigrationKey] = bundlePathMigration
registerMigration(BundlePathMigrationKey, bundlePathMigration)
}

var bundlePathMigration = &Migration{
Expand All @@ -23,13 +23,13 @@ var bundlePathMigration = &Migration{
return err
},
Down: func(ctx context.Context, tx *sql.Tx) error {
foreingKeyOff := `PRAGMA foreign_keys = 0`
foreignKeyOff := `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)
foreignKeyOn := `PRAGMA foreign_keys = 1`
_, err := tx.ExecContext(ctx, foreignKeyOff)
if err != nil {
return err
}
Expand All @@ -49,7 +49,7 @@ var bundlePathMigration = &Migration{
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, foreingKeyOn)
_, err = tx.ExecContext(ctx, foreignKeyOn)
return err
},
}
2 changes: 1 addition & 1 deletion pkg/sqlite/migrations/003_required_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const RequiredApiMigrationKey = 3

// Register this migration
func init() {
migrations[RequiredApiMigrationKey] = requiredApiMigration
registerMigration(RequiredApiMigrationKey, requiredApiMigration)
}

var requiredApiMigration = &Migration{
Expand Down
50 changes: 35 additions & 15 deletions pkg/sqlite/migrations/003_required_apis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package migrations_test

import (
"context"
"database/sql"
"testing"

"github.com/stretchr/testify/require"

"github.com/operator-framework/operator-registry/pkg/api"
"github.com/operator-framework/operator-registry/pkg/sqlite"
"github.com/operator-framework/operator-registry/pkg/sqlite/migrations"
)

Expand Down Expand Up @@ -35,20 +34,31 @@ func TestRequiredApisUp(t *testing.T) {
require.NoError(t, tx.Commit())

// check that no required apis were extracted.
querier := sqlite.NewSQLLiteQuerierFromDb(db)
provided, required, err := querier.GetApisForEntry(context.TODO(), 1)
requiredQuery := `SELECT DISTINCT api.group_name, api.version, api.kind, api.plural FROM api
INNER JOIN api_requirer ON (api.group_name=api_requirer.group_name AND api.version=api_requirer.version AND api.kind=api_requirer.kind)
WHERE api_requirer.channel_entry_id=?`
// check that no required apis were extracted.
_, err = db.Query(requiredQuery, 1)
require.Error(t, err)
require.Nil(t, provided)
require.Nil(t, required)

// Up the migration with backfill
err = migrator.Up(context.TODO(), migrations.Only(migrations.RequiredApiMigrationKey))
require.NoError(t, err)

// check that required apis were extracted
bundle, err := querier.GetBundleForChannel(context.TODO(), "etcd", "alpha")
rows, err := db.Query(requiredQuery, 1)
require.NoError(t, err)
require.Equal(t, []*api.GroupVersionKind{{Group:"etcd.database.coreos.com", Version: "v1beta2", Kind:"EtcdCluster", Plural:"etcdclusters"}}, bundle.RequiredApis)
var group sql.NullString
var version sql.NullString
var kind sql.NullString
var plural sql.NullString
rows.Next()
require.NoError(t, rows.Scan(&group, &version, &kind, &plural))
require.Equal(t, group.String, "etcd.database.coreos.com")
require.Equal(t, version.String, "v1beta2")
require.Equal(t, kind.String, "EtcdCluster")
require.Equal(t, plural.String, "etcdclusters")
require.NoError(t, rows.Close())
}

func TestRequiredApisDown(t *testing.T) {
Expand All @@ -64,19 +74,29 @@ func TestRequiredApisDown(t *testing.T) {
require.NoError(t, err)

// check that required apis were extracted from existing bundles
querier := sqlite.NewSQLLiteQuerierFromDb(db)
provided, required, err := querier.GetApisForEntry(context.TODO(), 1)
requiredQuery := `SELECT DISTINCT api.group_name, api.version, api.kind, api.plural FROM api
INNER JOIN api_requirer ON (api.group_name=api_requirer.group_name AND api.version=api_requirer.version AND api.kind=api_requirer.kind)
WHERE api_requirer.channel_entry_id=?`

rows, err := db.Query(requiredQuery, 1)
require.NoError(t, err)
require.Equal(t, provided, []*api.GroupVersionKind{})
require.Equal(t, []*api.GroupVersionKind{{Group:"etcd.database.coreos.com", Version: "v1beta2", Kind:"EtcdCluster", Plural:"etcdclusters"}}, required)
var group sql.NullString
var version sql.NullString
var kind sql.NullString
var plural sql.NullString
rows.Next()
require.NoError(t, rows.Scan(&group, &version, &kind, &plural))
require.Equal(t, group.String, "etcd.database.coreos.com")
require.Equal(t, version.String, "v1beta2")
require.Equal(t, kind.String, "EtcdCluster")
require.Equal(t, plural.String, "etcdclusters")
require.NoError(t, rows.Close())

// run down migration
err = migrator.Down(context.TODO(), migrations.Only(migrations.RequiredApiMigrationKey))
require.NoError(t, err)

// check that no required apis were extracted.
provided, required, err = querier.GetApisForEntry(context.TODO(), 1)
_, err = db.Query(requiredQuery, 1)
require.Error(t, err)
require.Nil(t, provided)
require.Nil(t, required)
}
2 changes: 1 addition & 1 deletion pkg/sqlite/migrations/004_cascade_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var CascadeDeleteMigrationKey = 4

// Register this migration
func init() {
migrations[CascadeDeleteMigrationKey] = cascadeDeleteMigration
registerMigration(CascadeDeleteMigrationKey, cascadeDeleteMigration)
}

var cascadeDeleteMigration = &Migration{
Expand Down
Loading