Skip to content

Commit addcd23

Browse files
committed
feat(migrate): migrate from current version up
to the latest
1 parent 8415c18 commit addcd23

File tree

16 files changed

+283
-145
lines changed

16 files changed

+283
-145
lines changed

cmd/opm/registry/serve.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/operator-framework/operator-registry/pkg/lib/log"
1717
"github.com/operator-framework/operator-registry/pkg/server"
1818
"github.com/operator-framework/operator-registry/pkg/sqlite"
19-
"github.com/operator-framework/operator-registry/pkg/sqlite/migrations"
2019
)
2120

2221
func newRegistryServeCmd() *cobra.Command {
@@ -121,5 +120,5 @@ func migrate(cmd *cobra.Command, db *sql.DB) error {
121120
return fmt.Errorf("failed to load migrator")
122121
}
123122

124-
return migrator.Up(context.TODO(), migrations.From(migrations.InitMigrationKey))
123+
return migrator.Migrate(context.TODO())
125124
}

cmd/registry-server/main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import (
66
"fmt"
77
"net"
88

9-
"github.com/operator-framework/operator-registry/pkg/lib/log"
10-
"github.com/operator-framework/operator-registry/pkg/sqlite/migrations"
11-
129
"github.com/sirupsen/logrus"
1310
"github.com/spf13/cobra"
1411
"google.golang.org/grpc"
1512
"google.golang.org/grpc/reflection"
1613

14+
"github.com/operator-framework/operator-registry/pkg/lib/log"
15+
1716
"github.com/operator-framework/operator-registry/pkg/api"
1817
health "github.com/operator-framework/operator-registry/pkg/api/grpc_health_v1"
1918
"github.com/operator-framework/operator-registry/pkg/server"
@@ -111,7 +110,6 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
111110
return nil
112111
}
113112

114-
115113
func migrate(cmd *cobra.Command, db *sql.DB) error {
116114
shouldSkipMigrate, err := cmd.Flags().GetBool("skip-migrate")
117115
if err != nil {
@@ -129,5 +127,5 @@ func migrate(cmd *cobra.Command, db *sql.DB) error {
129127
return fmt.Errorf("failed to load migrator")
130128
}
131129

132-
return migrator.Up(context.TODO(), migrations.From(migrations.InitMigrationKey))
130+
return migrator.Migrate(context.TODO())
133131
}

pkg/appregistry/dbloader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func NewDbLoader(dbName string, logger *logrus.Entry) (*dbLoader, error) {
2929
return &dbLoader{
3030
loader: sqlLoader,
3131
logger: logger,
32-
db: db,
32+
db: db,
3333
}, nil
3434
}
3535

3636
type dbLoader struct {
37-
db *sql.DB
37+
db *sql.DB
3838
loader *sqlite.SQLLoader
3939
logger *logrus.Entry
4040
}
@@ -59,7 +59,7 @@ func (l *dbLoader) LoadFlattenedToSQLite(manifest *RawOperatorManifestData) erro
5959
return err
6060
}
6161

62-
s:= sqlite.NewSQLLiteQuerierFromDb(l.db)
62+
s := sqlite.NewSQLLiteQuerierFromDb(l.db)
6363

6464
// sanity check that the db is available.
6565
tables, err := s.ListTables(context.TODO())

pkg/appregistry/downloader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func (d *downloadItem) String() string {
2727
}
2828

2929
type downloader struct {
30-
logger *logrus.Entry
31-
kubeClient kubernetes.Clientset
30+
logger *logrus.Entry
31+
kubeClient kubernetes.Clientset
3232
}
3333

3434
// Download downloads manifest(s) associated with the specified package(s) from

pkg/appregistry/parser.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ func (*manifestYAMLParser) Marshal(bundle *StructuredOperatorManifestData) (*Raw
186186
return data, nil
187187
}
188188

189-
190189
func (*manifestYAMLParser) MarshalCSV(csv *ClusterServiceVersion) (string, error) {
191190
csvRaw, err := yaml.Marshal(csv)
192191
if err != nil {

pkg/registry/csv.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (csv *ClusterServiceVersion) GetRelatedImages() (imageSet map[string]struct
208208

209209
type relatedImage struct {
210210
Name string `json:"name"`
211-
Ref string `json:"image"`
211+
Ref string `json:"image"`
212212
}
213213
var relatedImages []relatedImage
214214
if err = json.Unmarshal(*rawValue, &relatedImages); err != nil {
@@ -233,7 +233,7 @@ func (csv *ClusterServiceVersion) GetOperatorImages() (map[string]struct{}, erro
233233
Deployments []dep
234234
}
235235
type strategy struct {
236-
Name string `json:"strategy"`
236+
Name string `json:"strategy"`
237237
Spec strategySpec `json:"spec"`
238238
}
239239
type csvSpec struct {
@@ -246,7 +246,7 @@ func (csv *ClusterServiceVersion) GetOperatorImages() (map[string]struct{}, erro
246246
}
247247

248248
// this is the only install strategy we know about
249-
if spec.Install.Name != "deployment" {
249+
if spec.Install.Name != "deployment" {
250250
return nil, nil
251251
}
252252

pkg/registry/csv_test.go

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
2727
fields: fields{
2828
TypeMeta: v1.TypeMeta{},
2929
ObjectMeta: v1.ObjectMeta{},
30-
Spec: json.RawMessage(`
30+
Spec: json.RawMessage(`
3131
{
3232
"apiservicedefinitions": {
3333
"owned": [
@@ -41,18 +41,18 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
4141
},
4242
wantOwned: []*DefinitionKey{
4343
{
44-
Group: "g",
45-
Kind: "K",
44+
Group: "g",
45+
Kind: "K",
4646
Version: "v1",
47-
Name: "Ks.g",
47+
Name: "Ks.g",
4848
},
4949
},
5050
wantRequired: []*DefinitionKey{
5151
{
52-
Group: "g2",
53-
Kind: "K2",
52+
Group: "g2",
53+
Kind: "K2",
5454
Version: "v1",
55-
Name: "K2s.g",
55+
Name: "K2s.g",
5656
},
5757
},
5858
},
@@ -61,7 +61,7 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
6161
fields: fields{
6262
TypeMeta: v1.TypeMeta{},
6363
ObjectMeta: v1.ObjectMeta{},
64-
Spec: json.RawMessage(`
64+
Spec: json.RawMessage(`
6565
{
6666
"apiservicedefinitions": {
6767
"owned": [
@@ -72,10 +72,10 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
7272
},
7373
wantOwned: []*DefinitionKey{
7474
{
75-
Group: "g",
76-
Kind: "K",
75+
Group: "g",
76+
Kind: "K",
7777
Version: "v1",
78-
Name: "Ks.g",
78+
Name: "Ks.g",
7979
},
8080
},
8181
},
@@ -84,7 +84,7 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
8484
fields: fields{
8585
TypeMeta: v1.TypeMeta{},
8686
ObjectMeta: v1.ObjectMeta{},
87-
Spec: json.RawMessage(`
87+
Spec: json.RawMessage(`
8888
{
8989
"apiservicedefinitions": {
9090
"required": [
@@ -95,10 +95,10 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
9595
},
9696
wantRequired: []*DefinitionKey{
9797
{
98-
Group: "g2",
99-
Kind: "K2",
98+
Group: "g2",
99+
Kind: "K2",
100100
Version: "v1",
101-
Name: "K2s.g",
101+
Name: "K2s.g",
102102
},
103103
},
104104
},
@@ -115,18 +115,17 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
115115
fields: fields{
116116
TypeMeta: v1.TypeMeta{},
117117
ObjectMeta: v1.ObjectMeta{},
118-
Spec: json.RawMessage(`
118+
Spec: json.RawMessage(`
119119
{
120120
"apiservicedefinitions": {
121121
splat: [
122122
{"glarp": "g2", "version": "v1", "kind": "K2", "name": "K2s.g"}
123123
]
124124
}
125125
}`),
126-
127126
},
128-
wantErr:true,
129-
}, }
127+
wantErr: true,
128+
}}
130129
for _, tt := range tests {
131130
t.Run(tt.name, func(t *testing.T) {
132131
csv := &ClusterServiceVersion{
@@ -167,7 +166,7 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
167166
fields: fields{
168167
TypeMeta: v1.TypeMeta{},
169168
ObjectMeta: v1.ObjectMeta{},
170-
Spec: json.RawMessage(`
169+
Spec: json.RawMessage(`
171170
{
172171
"customresourcedefinitions": {
173172
"owned": [
@@ -181,18 +180,18 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
181180
},
182181
wantOwned: []*DefinitionKey{
183182
{
184-
Group: "g",
185-
Kind: "K",
183+
Group: "g",
184+
Kind: "K",
186185
Version: "v1",
187-
Name: "Ks.g",
186+
Name: "Ks.g",
188187
},
189188
},
190189
wantRequired: []*DefinitionKey{
191190
{
192-
Group: "g2",
193-
Kind: "K2",
191+
Group: "g2",
192+
Kind: "K2",
194193
Version: "v1",
195-
Name: "K2s.g",
194+
Name: "K2s.g",
196195
},
197196
},
198197
},
@@ -201,7 +200,7 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
201200
fields: fields{
202201
TypeMeta: v1.TypeMeta{},
203202
ObjectMeta: v1.ObjectMeta{},
204-
Spec: json.RawMessage(`
203+
Spec: json.RawMessage(`
205204
{
206205
"customresourcedefinitions": {
207206
"owned": [
@@ -212,10 +211,10 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
212211
},
213212
wantOwned: []*DefinitionKey{
214213
{
215-
Group: "g",
216-
Kind: "K",
214+
Group: "g",
215+
Kind: "K",
217216
Version: "v1",
218-
Name: "Ks.g",
217+
Name: "Ks.g",
219218
},
220219
},
221220
},
@@ -224,7 +223,7 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
224223
fields: fields{
225224
TypeMeta: v1.TypeMeta{},
226225
ObjectMeta: v1.ObjectMeta{},
227-
Spec: json.RawMessage(`
226+
Spec: json.RawMessage(`
228227
{
229228
"customresourcedefinitions": {
230229
"required": [
@@ -235,10 +234,10 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
235234
},
236235
wantRequired: []*DefinitionKey{
237236
{
238-
Group: "g2",
239-
Kind: "K2",
237+
Group: "g2",
238+
Kind: "K2",
240239
Version: "v1",
241-
Name: "K2s.g",
240+
Name: "K2s.g",
242241
},
243242
},
244243
},
@@ -255,17 +254,16 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
255254
fields: fields{
256255
TypeMeta: v1.TypeMeta{},
257256
ObjectMeta: v1.ObjectMeta{},
258-
Spec: json.RawMessage(`
257+
Spec: json.RawMessage(`
259258
{
260259
"customresourcedefinitions": {
261260
splat: [
262261
{"glarp": "g2", "version": "v1", "kind": "K2", "name": "K2s.g"}
263262
]
264263
}
265264
}`),
266-
267265
},
268-
wantErr:true,
266+
wantErr: true,
269267
},
270268
}
271269
for _, tt := range tests {
@@ -387,7 +385,7 @@ func TestClusterServiceVersion_GetSkips(t *testing.T) {
387385
Spec: json.RawMessage(`{"skips": 5}`),
388386
},
389387
wantErr: true,
390-
}, }
388+
}}
391389
for _, tt := range tests {
392390
t.Run(tt.name, func(t *testing.T) {
393391
csv := &ClusterServiceVersion{
@@ -492,7 +490,7 @@ func TestClusterServiceVersion_GetRelatedImages(t *testing.T) {
492490
fields: fields{
493491
TypeMeta: v1.TypeMeta{},
494492
ObjectMeta: v1.ObjectMeta{},
495-
Spec: json.RawMessage(`{"relatedImages": [
493+
Spec: json.RawMessage(`{"relatedImages": [
496494
{"name": "test", "image": "quay.io/etcd/etcd-operator@sha256:123"}
497495
]}`),
498496
},
@@ -503,7 +501,7 @@ func TestClusterServiceVersion_GetRelatedImages(t *testing.T) {
503501
fields: fields{
504502
TypeMeta: v1.TypeMeta{},
505503
ObjectMeta: v1.ObjectMeta{},
506-
Spec: json.RawMessage(`{"relatedImages": [
504+
Spec: json.RawMessage(`{"relatedImages": [
507505
{"name": "test", "image": "quay.io/etcd/etcd-operator@sha256:123"},
508506
{"name": "operand", "image": "quay.io/etcd/etcd@sha256:123"}
509507
]}`),
@@ -563,7 +561,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
563561
"containers":[]
564562
}}}}]}}}`),
565563
},
566-
want: nil,
564+
want: nil,
567565
wantErr: true,
568566
},
569567
{
@@ -588,7 +586,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
588586
}
589587
}}]}}}`),
590588
},
591-
want: map[string]struct{}{"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
589+
want: map[string]struct{}{"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
592590
},
593591
{
594592
name: "two container images",
@@ -617,7 +615,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
617615
}
618616
}}]}}}`),
619617
},
620-
want: map[string]struct{}{"quay.io/coreos/etcd-operator-2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
618+
want: map[string]struct{}{"quay.io/coreos/etcd-operator-2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
621619
},
622620
{
623621
name: "init container image",
@@ -651,7 +649,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
651649
}
652650
}`),
653651
},
654-
want: map[string]struct{}{"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
652+
want: map[string]struct{}{"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
655653
},
656654
{
657655
name: "two init container images",
@@ -690,7 +688,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
690688
}
691689
}`),
692690
},
693-
want: map[string]struct{}{"quay.io/coreos/etcd-operator2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
691+
want: map[string]struct{}{"quay.io/coreos/etcd-operator2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
694692
},
695693
{
696694
name: "container and init container",
@@ -741,7 +739,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
741739
}
742740
}`),
743741
},
744-
want: map[string]struct{}{"quay.io/coreos/etcd-operator2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":struct {}{}, "quay.io/coreos/init-etcd-operator2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}, "quay.io/coreos/init-etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
742+
want: map[string]struct{}{"quay.io/coreos/etcd-operator2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": struct{}{}, "quay.io/coreos/init-etcd-operator2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}, "quay.io/coreos/init-etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
745743
},
746744
}
747745
for _, tt := range tests {

0 commit comments

Comments
 (0)