Skip to content

Commit

Permalink
feat(migrate): migrate from current version up
Browse files Browse the repository at this point in the history
to the latest
  • Loading branch information
ecordell committed Oct 24, 2019
1 parent 8415c18 commit addcd23
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 145 deletions.
3 changes: 1 addition & 2 deletions cmd/opm/registry/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/operator-framework/operator-registry/pkg/lib/log"
"github.com/operator-framework/operator-registry/pkg/server"
"github.com/operator-framework/operator-registry/pkg/sqlite"
"github.com/operator-framework/operator-registry/pkg/sqlite/migrations"
)

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

return migrator.Up(context.TODO(), migrations.From(migrations.InitMigrationKey))
return migrator.Migrate(context.TODO())
}
8 changes: 3 additions & 5 deletions cmd/registry-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import (
"fmt"
"net"

"github.com/operator-framework/operator-registry/pkg/lib/log"
"github.com/operator-framework/operator-registry/pkg/sqlite/migrations"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"

"github.com/operator-framework/operator-registry/pkg/lib/log"

"github.com/operator-framework/operator-registry/pkg/api"
health "github.com/operator-framework/operator-registry/pkg/api/grpc_health_v1"
"github.com/operator-framework/operator-registry/pkg/server"
Expand Down Expand Up @@ -111,7 +110,6 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
return nil
}


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

return migrator.Up(context.TODO(), migrations.From(migrations.InitMigrationKey))
return migrator.Migrate(context.TODO())
}
6 changes: 3 additions & 3 deletions pkg/appregistry/dbloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func NewDbLoader(dbName string, logger *logrus.Entry) (*dbLoader, error) {
return &dbLoader{
loader: sqlLoader,
logger: logger,
db: db,
db: db,
}, nil
}

type dbLoader struct {
db *sql.DB
db *sql.DB
loader *sqlite.SQLLoader
logger *logrus.Entry
}
Expand All @@ -59,7 +59,7 @@ func (l *dbLoader) LoadFlattenedToSQLite(manifest *RawOperatorManifestData) erro
return err
}

s:= sqlite.NewSQLLiteQuerierFromDb(l.db)
s := sqlite.NewSQLLiteQuerierFromDb(l.db)

// sanity check that the db is available.
tables, err := s.ListTables(context.TODO())
Expand Down
4 changes: 2 additions & 2 deletions pkg/appregistry/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (d *downloadItem) String() string {
}

type downloader struct {
logger *logrus.Entry
kubeClient kubernetes.Clientset
logger *logrus.Entry
kubeClient kubernetes.Clientset
}

// Download downloads manifest(s) associated with the specified package(s) from
Expand Down
1 change: 0 additions & 1 deletion pkg/appregistry/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ func (*manifestYAMLParser) Marshal(bundle *StructuredOperatorManifestData) (*Raw
return data, nil
}


func (*manifestYAMLParser) MarshalCSV(csv *ClusterServiceVersion) (string, error) {
csvRaw, err := yaml.Marshal(csv)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (csv *ClusterServiceVersion) GetRelatedImages() (imageSet map[string]struct

type relatedImage struct {
Name string `json:"name"`
Ref string `json:"image"`
Ref string `json:"image"`
}
var relatedImages []relatedImage
if err = json.Unmarshal(*rawValue, &relatedImages); err != nil {
Expand All @@ -233,7 +233,7 @@ func (csv *ClusterServiceVersion) GetOperatorImages() (map[string]struct{}, erro
Deployments []dep
}
type strategy struct {
Name string `json:"strategy"`
Name string `json:"strategy"`
Spec strategySpec `json:"spec"`
}
type csvSpec struct {
Expand All @@ -246,7 +246,7 @@ func (csv *ClusterServiceVersion) GetOperatorImages() (map[string]struct{}, erro
}

// this is the only install strategy we know about
if spec.Install.Name != "deployment" {
if spec.Install.Name != "deployment" {
return nil, nil
}

Expand Down
90 changes: 44 additions & 46 deletions pkg/registry/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`
Spec: json.RawMessage(`
{
"apiservicedefinitions": {
"owned": [
Expand All @@ -41,18 +41,18 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
},
wantOwned: []*DefinitionKey{
{
Group: "g",
Kind: "K",
Group: "g",
Kind: "K",
Version: "v1",
Name: "Ks.g",
Name: "Ks.g",
},
},
wantRequired: []*DefinitionKey{
{
Group: "g2",
Kind: "K2",
Group: "g2",
Kind: "K2",
Version: "v1",
Name: "K2s.g",
Name: "K2s.g",
},
},
},
Expand All @@ -61,7 +61,7 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`
Spec: json.RawMessage(`
{
"apiservicedefinitions": {
"owned": [
Expand All @@ -72,10 +72,10 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
},
wantOwned: []*DefinitionKey{
{
Group: "g",
Kind: "K",
Group: "g",
Kind: "K",
Version: "v1",
Name: "Ks.g",
Name: "Ks.g",
},
},
},
Expand All @@ -84,7 +84,7 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`
Spec: json.RawMessage(`
{
"apiservicedefinitions": {
"required": [
Expand All @@ -95,10 +95,10 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
},
wantRequired: []*DefinitionKey{
{
Group: "g2",
Kind: "K2",
Group: "g2",
Kind: "K2",
Version: "v1",
Name: "K2s.g",
Name: "K2s.g",
},
},
},
Expand All @@ -115,18 +115,17 @@ func TestClusterServiceVersion_GetApiServiceDefinitions(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`
Spec: json.RawMessage(`
{
"apiservicedefinitions": {
splat: [
{"glarp": "g2", "version": "v1", "kind": "K2", "name": "K2s.g"}
]
}
}`),

},
wantErr:true,
}, }
wantErr: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
csv := &ClusterServiceVersion{
Expand Down Expand Up @@ -167,7 +166,7 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`
Spec: json.RawMessage(`
{
"customresourcedefinitions": {
"owned": [
Expand All @@ -181,18 +180,18 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
},
wantOwned: []*DefinitionKey{
{
Group: "g",
Kind: "K",
Group: "g",
Kind: "K",
Version: "v1",
Name: "Ks.g",
Name: "Ks.g",
},
},
wantRequired: []*DefinitionKey{
{
Group: "g2",
Kind: "K2",
Group: "g2",
Kind: "K2",
Version: "v1",
Name: "K2s.g",
Name: "K2s.g",
},
},
},
Expand All @@ -201,7 +200,7 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`
Spec: json.RawMessage(`
{
"customresourcedefinitions": {
"owned": [
Expand All @@ -212,10 +211,10 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
},
wantOwned: []*DefinitionKey{
{
Group: "g",
Kind: "K",
Group: "g",
Kind: "K",
Version: "v1",
Name: "Ks.g",
Name: "Ks.g",
},
},
},
Expand All @@ -224,7 +223,7 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`
Spec: json.RawMessage(`
{
"customresourcedefinitions": {
"required": [
Expand All @@ -235,10 +234,10 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
},
wantRequired: []*DefinitionKey{
{
Group: "g2",
Kind: "K2",
Group: "g2",
Kind: "K2",
Version: "v1",
Name: "K2s.g",
Name: "K2s.g",
},
},
},
Expand All @@ -255,17 +254,16 @@ func TestClusterServiceVersion_GetCustomResourceDefintions(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`
Spec: json.RawMessage(`
{
"customresourcedefinitions": {
splat: [
{"glarp": "g2", "version": "v1", "kind": "K2", "name": "K2s.g"}
]
}
}`),

},
wantErr:true,
wantErr: true,
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -387,7 +385,7 @@ func TestClusterServiceVersion_GetSkips(t *testing.T) {
Spec: json.RawMessage(`{"skips": 5}`),
},
wantErr: true,
}, }
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
csv := &ClusterServiceVersion{
Expand Down Expand Up @@ -492,7 +490,7 @@ func TestClusterServiceVersion_GetRelatedImages(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`{"relatedImages": [
Spec: json.RawMessage(`{"relatedImages": [
{"name": "test", "image": "quay.io/etcd/etcd-operator@sha256:123"}
]}`),
},
Expand All @@ -503,7 +501,7 @@ func TestClusterServiceVersion_GetRelatedImages(t *testing.T) {
fields: fields{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
Spec: json.RawMessage(`{"relatedImages": [
Spec: json.RawMessage(`{"relatedImages": [
{"name": "test", "image": "quay.io/etcd/etcd-operator@sha256:123"},
{"name": "operand", "image": "quay.io/etcd/etcd@sha256:123"}
]}`),
Expand Down Expand Up @@ -563,7 +561,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
"containers":[]
}}}}]}}}`),
},
want: nil,
want: nil,
wantErr: true,
},
{
Expand All @@ -588,7 +586,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
}
}}]}}}`),
},
want: map[string]struct{}{"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
want: map[string]struct{}{"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
},
{
name: "two container images",
Expand Down Expand Up @@ -617,7 +615,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
}
}}]}}}`),
},
want: map[string]struct{}{"quay.io/coreos/etcd-operator-2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
want: map[string]struct{}{"quay.io/coreos/etcd-operator-2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
},
{
name: "init container image",
Expand Down Expand Up @@ -651,7 +649,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
}
}`),
},
want: map[string]struct{}{"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
want: map[string]struct{}{"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
},
{
name: "two init container images",
Expand Down Expand Up @@ -690,7 +688,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
}
}`),
},
want: map[string]struct{}{"quay.io/coreos/etcd-operator2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2":{}},
want: map[string]struct{}{"quay.io/coreos/etcd-operator2@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}, "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": {}},
},
{
name: "container and init container",
Expand Down Expand Up @@ -741,7 +739,7 @@ func TestClusterServiceVersion_GetOperatorImages(t *testing.T) {
}
}`),
},
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":{}},
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": {}},
},
}
for _, tt := range tests {
Expand Down
Loading

0 comments on commit addcd23

Please sign in to comment.