Skip to content

Commit 50a37f9

Browse files
Merge pull request operator-framework#113 from ecordell/rest-of-it
feat(api): return version and skiprange in bundle
2 parents 0a888bc + a0dd63f commit 50a37f9

15 files changed

+371
-99
lines changed

pkg/api/registry.pb.go

Lines changed: 61 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/registry.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ message Bundle{
4646
string bundlePath = 6;
4747
repeated GroupVersionKind providedApis = 7;
4848
repeated GroupVersionKind requiredApis = 8;
49+
string version = 9;
50+
string skipRange = 10;
4951
}
5052

5153
message ChannelEntry{

pkg/mirror/mirror.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,13 @@ func (b *IndexImageMirrorer) Mirror() (map[string]string, error) {
9595

9696
var errs []error
9797
for _, img := range images {
98-
ref, err := reference.ParseNamed(img)
98+
ref, err := reference.ParseNormalizedNamed(img)
9999
if err != nil {
100100
errs = append(errs, fmt.Errorf("couldn't parse image for mirroring (%s), skipping mirror: %s", img, err.Error()))
101101
continue
102102
}
103-
104103
domain := reference.Domain(ref)
105-
mapping[img] = b.Dest + strings.TrimPrefix(img, domain)
104+
mapping[ref.String()] = b.Dest + strings.TrimPrefix(ref.String(), domain)
106105
}
107106

108107
if err := b.ImageMirrorer.Mirror(mapping); err != nil {

pkg/mirror/mirror_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ func TestIndexImageMirrorer_Mirror(t *testing.T) {
7474
"quay.io/coreos/prometheus-operator@sha256:0e92dd9b5789c4b13d53e1319d0a6375bcca4caaf0d698af61198061222a576d":"localhost/coreos/prometheus-operator@sha256:0e92dd9b5789c4b13d53e1319d0a6375bcca4caaf0d698af61198061222a576d",
7575
"quay.io/coreos/prometheus-operator@sha256:3daa69a8c6c2f1d35dcf1fe48a7cd8b230e55f5229a1ded438f687debade5bcf":"localhost/coreos/prometheus-operator@sha256:3daa69a8c6c2f1d35dcf1fe48a7cd8b230e55f5229a1ded438f687debade5bcf",
7676
"quay.io/coreos/prometheus-operator@sha256:5037b4e90dbb03ebdefaa547ddf6a1f748c8eeebeedf6b9d9f0913ad662b5731":"localhost/coreos/prometheus-operator@sha256:5037b4e90dbb03ebdefaa547ddf6a1f748c8eeebeedf6b9d9f0913ad662b5731",
77+
"docker.io/strimzi/cluster-operator:0.11.0": "localhost/strimzi/cluster-operator:0.11.0",
78+
"docker.io/strimzi/cluster-operator:0.11.1": "localhost/strimzi/cluster-operator:0.11.1",
79+
"docker.io/strimzi/operator:0.12.1": "localhost/strimzi/operator:0.12.1",
80+
"docker.io/strimzi/operator:0.12.2": "localhost/strimzi/operator:0.12.2",
7781
},
78-
// strimzi has invalid images in its manifests, so we both return a list of maps and an error
79-
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]"),
8082
},
8183
}
8284
for _, tt := range tests {
@@ -95,7 +97,9 @@ func TestIndexImageMirrorer_Mirror(t *testing.T) {
9597
Dest: tt.fields.Dest,
9698
}
9799
got, err := b.Mirror()
98-
require.Equal(t, tt.wantErr.Error(), err.Error())
100+
if err != nil {
101+
require.Equal(t, tt.wantErr.Error(), err.Error())
102+
}
99103
require.Equal(t, tt.want, got)
100104
})
101105
}

pkg/sqlite/migrations/000_init.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77

88
var InitMigrationKey = 0
99

10+
func init() {
11+
registerMigration(InitMigrationKey, initMigration)
12+
}
13+
1014
var initMigration = &Migration{
1115
Id: InitMigrationKey,
1216
Up: func(ctx context.Context, tx *sql.Tx) error {
@@ -72,7 +76,3 @@ var initMigration = &Migration{
7276
return err
7377
},
7478
}
75-
76-
func init() {
77-
migrations[InitMigrationKey] = initMigration
78-
}

pkg/sqlite/migrations/001_related_images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
const RelatedImagesMigrationKey = 1
1515

1616
func init() {
17-
migrations[RelatedImagesMigrationKey] = relatedImagesMigration
17+
registerMigration(RelatedImagesMigrationKey, relatedImagesMigration)
1818
}
1919

2020
// listBundles returns a list of operatorbundles as strings

pkg/sqlite/migrations/002_bundle_path.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const BundlePathMigrationKey = 2
99

1010
// Register this migration
1111
func init() {
12-
migrations[BundlePathMigrationKey] = bundlePathMigration
12+
registerMigration(BundlePathMigrationKey, bundlePathMigration)
1313
}
1414

1515
var bundlePathMigration = &Migration{
@@ -23,13 +23,13 @@ var bundlePathMigration = &Migration{
2323
return err
2424
},
2525
Down: func(ctx context.Context, tx *sql.Tx) error {
26-
foreingKeyOff := `PRAGMA foreign_keys = 0`
26+
foreignKeyOff := `PRAGMA foreign_keys = 0`
2727
createTempTable := `CREATE TABLE operatorbundle_backup (name TEXT,csv TEXT,bundle TEXT)`
2828
backupTargetTable := `INSERT INTO operatorbundle_backup SELECT name,csv,bundle FROM operatorbundle`
2929
dropTargetTable := `DROP TABLE operatorbundle`
3030
renameBackUpTable := `ALTER TABLE operatorbundle_backup RENAME TO operatorbundle;`
31-
foreingKeyOn := `PRAGMA foreign_keys = 1`
32-
_, err := tx.ExecContext(ctx, foreingKeyOff)
31+
foreignKeyOn := `PRAGMA foreign_keys = 1`
32+
_, err := tx.ExecContext(ctx, foreignKeyOff)
3333
if err != nil {
3434
return err
3535
}
@@ -49,7 +49,7 @@ var bundlePathMigration = &Migration{
4949
if err != nil {
5050
return err
5151
}
52-
_, err = tx.ExecContext(ctx, foreingKeyOn)
52+
_, err = tx.ExecContext(ctx, foreignKeyOn)
5353
return err
5454
},
5555
}

pkg/sqlite/migrations/003_required_apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const RequiredApiMigrationKey = 3
1313

1414
// Register this migration
1515
func init() {
16-
migrations[RequiredApiMigrationKey] = requiredApiMigration
16+
registerMigration(RequiredApiMigrationKey, requiredApiMigration)
1717
}
1818

1919
var requiredApiMigration = &Migration{

pkg/sqlite/migrations/003_required_apis_test.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package migrations_test
22

33
import (
44
"context"
5+
"database/sql"
56
"testing"
67

78
"github.com/stretchr/testify/require"
89

9-
"github.com/operator-framework/operator-registry/pkg/api"
10-
"github.com/operator-framework/operator-registry/pkg/sqlite"
1110
"github.com/operator-framework/operator-registry/pkg/sqlite/migrations"
1211
)
1312

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

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

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

4848
// check that required apis were extracted
49-
bundle, err := querier.GetBundleForChannel(context.TODO(), "etcd", "alpha")
49+
rows, err := db.Query(requiredQuery, 1)
5050
require.NoError(t, err)
51-
require.Equal(t, []*api.GroupVersionKind{{Group:"etcd.database.coreos.com", Version: "v1beta2", Kind:"EtcdCluster", Plural:"etcdclusters"}}, bundle.RequiredApis)
51+
var group sql.NullString
52+
var version sql.NullString
53+
var kind sql.NullString
54+
var plural sql.NullString
55+
rows.Next()
56+
require.NoError(t, rows.Scan(&group, &version, &kind, &plural))
57+
require.Equal(t, group.String, "etcd.database.coreos.com")
58+
require.Equal(t, version.String, "v1beta2")
59+
require.Equal(t, kind.String, "EtcdCluster")
60+
require.Equal(t, plural.String, "etcdclusters")
61+
require.NoError(t, rows.Close())
5262
}
5363

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

6676
// check that required apis were extracted from existing bundles
67-
querier := sqlite.NewSQLLiteQuerierFromDb(db)
68-
provided, required, err := querier.GetApisForEntry(context.TODO(), 1)
77+
requiredQuery := `SELECT DISTINCT api.group_name, api.version, api.kind, api.plural FROM api
78+
INNER JOIN api_requirer ON (api.group_name=api_requirer.group_name AND api.version=api_requirer.version AND api.kind=api_requirer.kind)
79+
WHERE api_requirer.channel_entry_id=?`
80+
81+
rows, err := db.Query(requiredQuery, 1)
6982
require.NoError(t, err)
70-
require.Equal(t, provided, []*api.GroupVersionKind{})
71-
require.Equal(t, []*api.GroupVersionKind{{Group:"etcd.database.coreos.com", Version: "v1beta2", Kind:"EtcdCluster", Plural:"etcdclusters"}}, required)
83+
var group sql.NullString
84+
var version sql.NullString
85+
var kind sql.NullString
86+
var plural sql.NullString
87+
rows.Next()
88+
require.NoError(t, rows.Scan(&group, &version, &kind, &plural))
89+
require.Equal(t, group.String, "etcd.database.coreos.com")
90+
require.Equal(t, version.String, "v1beta2")
91+
require.Equal(t, kind.String, "EtcdCluster")
92+
require.Equal(t, plural.String, "etcdclusters")
93+
require.NoError(t, rows.Close())
7294

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

7799
// check that no required apis were extracted.
78-
provided, required, err = querier.GetApisForEntry(context.TODO(), 1)
100+
_, err = db.Query(requiredQuery, 1)
79101
require.Error(t, err)
80-
require.Nil(t, provided)
81-
require.Nil(t, required)
82102
}

pkg/sqlite/migrations/004_cascade_delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var CascadeDeleteMigrationKey = 4
99

1010
// Register this migration
1111
func init() {
12-
migrations[CascadeDeleteMigrationKey] = cascadeDeleteMigration
12+
registerMigration(CascadeDeleteMigrationKey, cascadeDeleteMigration)
1313
}
1414

1515
var cascadeDeleteMigration = &Migration{

0 commit comments

Comments
 (0)