Skip to content

Commit

Permalink
review resolutions
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
  • Loading branch information
grokspawn committed Aug 2, 2024
1 parent 85a012c commit 9e68d1c
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/operator-framework/operator-registry/alpha/property"
)

var BundleObjectToCSVMetadata = newMigration(
var bundleObjectToCSVMetadata = newMigration(
"bundle-object-to-csv-metadata",
"migrates bundles' `olm.bundle.object` to `olm.csv.metadata`",
func(cfg *declcfg.DeclarativeConfig) error {
Expand Down
15 changes: 13 additions & 2 deletions alpha/action/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"slices"
"strings"
"text/tabwriter"

"github.com/operator-framework/operator-registry/alpha/declcfg"
)
Expand Down Expand Up @@ -40,10 +41,17 @@ type Migrations struct {
Migrations []Migration
}

func GetLastMigrationName() string {
if len(allMigrations) == 0 {
return ""
}
return allMigrations[len(allMigrations)-1].Name()
}

// allMigrations represents the migration catalog
// the order of these migrations is important
var allMigrations = []Migration{
BundleObjectToCSVMetadata,
bundleObjectToCSVMetadata,
}

func NewMigrations(level string) (*Migrations, error) {
Expand Down Expand Up @@ -75,9 +83,12 @@ func HelpText() string {
if len(allMigrations) == 0 {
help.WriteString(" (no migrations available in this version)\n")
}

tabber := tabwriter.NewWriter(&help, 20, 30, 1, '\t', tabwriter.AlignRight)
for _, migration := range allMigrations {
help.WriteString(fmt.Sprintf(" - %s\n", migration.Name()))
fmt.Fprintf(tabber, " - %s\t%s\n", migration.Name(), migration.Help())
}
tabber.Flush()
return help.String()
}

Expand Down
8 changes: 4 additions & 4 deletions alpha/action/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ func migrate(cfg *declcfg.DeclarativeConfig, migrateLevel string) error {
return err
}

for _, m := range (*mobj).Migrations {
if err := m.Migrate(cfg); err != nil {
return err
}
err = mobj.Migrate(cfg)
if err != nil {
return err
}

return nil
}

Expand Down
3 changes: 0 additions & 3 deletions alpha/property/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ func MustBuildGVKRequired(group, version, kind string) Property {
func MustBuildBundleObject(data []byte) Property {
return MustBuild(&BundleObject{Data: data})
}
func MustBuildBundleObjectData(data []byte) Property {
return MustBuild(&BundleObject{Data: data})
}

func MustBuildCSVMetadata(csv v1alpha1.ClusterServiceVersion) Property {
return MustBuild(&CSVMetadata{
Expand Down
6 changes: 3 additions & 3 deletions alpha/template/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
const schema string = "olm.template.basic"

type Template struct {
Registry image.Registry
MigrateLevel string
Registry image.Registry
MigrationLevel string
}

type BasicTemplate struct {
Expand Down Expand Up @@ -60,7 +60,7 @@ func (t Template) Render(ctx context.Context, reader io.Reader) (*declcfg.Declar
r := action.Render{
Registry: t.Registry,
AllowedRefMask: action.RefBundleImage,
MigrationLevel: t.MigrateLevel,
MigrationLevel: t.MigrationLevel,
}

for _, b := range cfg.Bundles {
Expand Down
2 changes: 1 addition & 1 deletion alpha/template/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (t Template) Render(ctx context.Context) (*declcfg.DeclarativeConfig, error
AllowedRefMask: action.RefBundleImage,
Refs: []string{b},
Registry: t.Registry,
MigrationLevel: t.MigrateLevel,
MigrationLevel: t.MigrationLevel,
}
c, err := r.Run(ctx)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions alpha/template/semver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

// data passed into this module externally
type Template struct {
Data io.Reader
Registry image.Registry
MigrateLevel string
Data io.Reader
Registry image.Registry
MigrationLevel string
}

// IO structs -- BEGIN
Expand Down
3 changes: 0 additions & 3 deletions cmd/opm/alpha/render-graph/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ $ opm alpha render-graph quay.io/operatorhubio/catalog:latest | \
render.AllowedRefMask = action.RefDCImage | action.RefDCDir | action.RefSqliteImage | action.RefSqliteFile
render.Registry = registry

// Run all migrations
render.MigrationLevel = ""

cfg, err := render.Run(cmd.Context())
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/opm/alpha/template/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ When FILE is '-' or not provided, the template is read from standard input`,
},
}

cmd.Flags().StringVar(&template.MigrateLevel, "migrate-level", "", "Name of the last migration to run (default: none)\n"+migrations.HelpText())
cmd.Flags().StringVar(&template.MigrationLevel, "migrate-level", "", "Name of the last migration to run (default: none)\n"+migrations.HelpText())

return cmd
}
3 changes: 0 additions & 3 deletions cmd/opm/migrate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ parsers that assume that a file contains exactly one valid JSON object.
}
cmd.Flags().StringVarP(&output, "output", "o", "json", "Output format (json|yaml)")
cmd.Flags().StringVar(&migrate.Level, "migrate-level", "", "Name of the last migration to run (default: none)\n"+migrations.HelpText())
_ = cmd.RegisterFlagCompletionFunc("migrate-level", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{migrations.HelpText()}, cobra.ShellCompDirectiveDefault
})

return cmd
}
4 changes: 2 additions & 2 deletions cmd/opm/render/cmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package render

import (
"fmt"
"io"
"log"
"os"
Expand Down Expand Up @@ -67,8 +66,9 @@ database files.
render.ImageRefTemplate = tmpl
}

// if the deprecated flag was used, set the level explicitly to the last migration to perform all migrations
if deprecatedMigrateFlag {
log.Fatal(fmt.Errorf("flag --migrate is deprecated, use --migrate-level instead"))
render.MigrationLevel = migrations.GetLastMigrationName()
}

cfg, err := render.Run(cmd.Context())
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func testModelBundle(t *testing.T) model.Bundle {
property.MustBuildPackageRequired("test", ">=1.2.3 <2.0.0-0"),
property.MustBuildGVKRequired("testapi.coreos.com", "v1", "Testapi"),
property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdBackup"),
property.MustBuildBundleObjectData([]byte(crdbackups)),
property.MustBuildBundleObjectData([]byte(crdclusters)),
property.MustBuildBundleObjectData([]byte(csvJson)),
property.MustBuildBundleObjectData([]byte(crdrestores)),
property.MustBuildBundleObject([]byte(crdbackups)),
property.MustBuildBundleObject([]byte(crdclusters)),
property.MustBuildBundleObject([]byte(csvJson)),
property.MustBuildBundleObject([]byte(crdrestores)),
},
CsvJSON: csvJson,
Objects: []string{
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/registry_to_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func testExpectedProperties(t *testing.T) []property.Property {

}
for _, obj := range testExpectedObjects() {
props = append(props, property.MustBuildBundleObjectData([]byte(obj)))
props = append(props, property.MustBuildBundleObject([]byte(obj)))
}
return props
}

0 comments on commit 9e68d1c

Please sign in to comment.