-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add optional schema migrations; default to olm.bundle.object instead …
…of olm.csv.metadata (#1384) * Allow disabling of migrations for bundles and sqlite DBs Signed-off-by: Joe Lanford <[email protected]> * intro new migrations package Signed-off-by: Joe Lanford <[email protected]> * schema migration optional; default to olm.bundle.object Signed-off-by: Jordan Keister <[email protected]> * review resolutions Signed-off-by: Jordan Keister <[email protected]> * use a type to protect migration interactions Signed-off-by: Jordan Keister <[email protected]> * review revisions Signed-off-by: Jordan Keister <[email protected]> --------- Signed-off-by: Joe Lanford <[email protected]> Signed-off-by: Jordan Keister <[email protected]> Co-authored-by: Joe Lanford <[email protected]>
- Loading branch information
1 parent
a758bd9
commit c80e875
Showing
20 changed files
with
847 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
alpha/action/migrations/000_bundle_object_to_csv_metadata.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package migrations | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/operator-framework/api/pkg/operators/v1alpha1" | ||
|
||
"github.com/operator-framework/operator-registry/alpha/declcfg" | ||
"github.com/operator-framework/operator-registry/alpha/property" | ||
) | ||
|
||
func bundleObjectToCSVMetadata(cfg *declcfg.DeclarativeConfig) error { | ||
convertBundleObjectToCSVMetadata := func(b *declcfg.Bundle) error { | ||
if b.Image == "" || b.CsvJSON == "" { | ||
return nil | ||
} | ||
|
||
var csv v1alpha1.ClusterServiceVersion | ||
if err := json.Unmarshal([]byte(b.CsvJSON), &csv); err != nil { | ||
return err | ||
} | ||
|
||
props := b.Properties[:0] | ||
for _, p := range b.Properties { | ||
switch p.Type { | ||
case property.TypeBundleObject: | ||
// Get rid of the bundle objects | ||
case property.TypeCSVMetadata: | ||
// If this bundle already has a CSV metadata | ||
// property, we won't mutate the bundle at all. | ||
return nil | ||
default: | ||
// Keep all of the other properties | ||
props = append(props, p) | ||
} | ||
} | ||
b.Properties = append(props, property.MustBuildCSVMetadata(csv)) | ||
return nil | ||
} | ||
|
||
for bi := range cfg.Bundles { | ||
if err := convertBundleObjectToCSVMetadata(&cfg.Bundles[bi]); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.