forked from operator-framework/operator-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: olm.package.v2, olm.bundle.v2, olm.package.icon
Signed-off-by: Joe Lanford <[email protected]>
- Loading branch information
1 parent
c8307ca
commit 1c1b37c
Showing
4 changed files
with
264 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package migrations | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/operator-framework/operator-registry/alpha/declcfg" | ||
"github.com/operator-framework/operator-registry/alpha/model" | ||
"github.com/operator-framework/operator-registry/alpha/property" | ||
) | ||
|
||
func v2(cfg *declcfg.DeclarativeConfig) error { | ||
uniqueBundles := map[string]*model.Bundle{} | ||
m, err := declcfg.ConvertToModel(*cfg) | ||
if err != nil { | ||
return err | ||
} | ||
cfg.Packages = nil | ||
cfg.Bundles = nil | ||
|
||
for _, pkg := range m { | ||
head, err := pkg.DefaultChannel.Head() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if head.PropertiesP == nil || len(head.PropertiesP.CSVMetadatas) == 0 { | ||
return fmt.Errorf("no CSV metadata defined for package %s", pkg.Name) | ||
} | ||
csvMetadata := head.PropertiesP.CSVMetadatas[0] | ||
|
||
packageAnnotations := map[string]string{ | ||
"operators.openshift.io/capabilities": csvMetadata.Annotations["capabilities"], | ||
"operators.openshift.io/categories": csvMetadata.Annotations["categories"], | ||
"operators.openshift.io/infrastructure-features": csvMetadata.Annotations["operators.openshift.io/infrastructure-features"], | ||
"operators.openshift.io/valid-subscription": csvMetadata.Annotations["operators.openshift.io/valid-subscription"], | ||
} | ||
|
||
v2p := declcfg.PackageV2{ | ||
Schema: "olm.package.v2", | ||
Package: pkg.Name, | ||
DisplayName: csvMetadata.DisplayName, | ||
ShortDescription: csvMetadata.Annotations["description"], | ||
LongDescription: csvMetadata.Description, | ||
Keywords: csvMetadata.Keywords, | ||
Links: csvMetadata.Links, | ||
Provider: csvMetadata.Provider, | ||
Maintainers: csvMetadata.Maintainers, | ||
Annotations: packageAnnotations, | ||
} | ||
cfg.PackageV2s = append(cfg.PackageV2s, v2p) | ||
|
||
if pkg.Icon != nil { | ||
v2i := declcfg.PackageIcon{ | ||
Schema: "olm.package.icon", | ||
Package: pkg.Name, | ||
Data: pkg.Icon.Data, | ||
MediaType: pkg.Icon.MediaType, | ||
} | ||
cfg.PackageIcons = append(cfg.PackageIcons, v2i) | ||
} | ||
for _, ch := range pkg.Channels { | ||
for _, b := range ch.Bundles { | ||
uniqueBundles[b.Name] = b | ||
} | ||
} | ||
} | ||
|
||
for _, b := range uniqueBundles { | ||
v2b := declcfg.BundleV2{ | ||
Schema: "olm.bundle.v2", | ||
Package: b.Package.Name, | ||
Name: b.Name, | ||
|
||
Version: b.Version.String(), | ||
Release: 0, | ||
Reference: fmt.Sprintf("docker://%s", b.Image), | ||
RelatedReferences: make([]string, 0, len(b.RelatedImages)), | ||
|
||
Constraints: map[string][]json.RawMessage{}, | ||
Properties: map[string][]json.RawMessage{}, | ||
} | ||
|
||
for _, ri := range b.RelatedImages { | ||
v2b.RelatedReferences = append(v2b.RelatedReferences, fmt.Sprintf("docker://%s", ri.Image)) | ||
} | ||
|
||
for _, p := range b.Properties { | ||
if p.Type == property.TypePackage || p.Type == property.TypeCSVMetadata || p.Type == property.TypeBundleObject { | ||
continue | ||
} | ||
if isContraint(p) { | ||
v2b.Constraints[p.Type] = append(v2b.Constraints[p.Type], p.Value) | ||
} else { | ||
v2b.Properties[p.Type] = append(v2b.Properties[p.Type], p.Value) | ||
} | ||
} | ||
|
||
if b.PropertiesP != nil && len(b.PropertiesP.CSVMetadatas) > 0 { | ||
csvMetadata := b.PropertiesP.CSVMetadatas[0] | ||
|
||
desiredAnnotations := map[string]string{ | ||
"createdAt": "operators.openshift.io/creationTimestamp", | ||
"repository": "operators.openshift.io/repository", | ||
"support": "operators.openshift.io/support", | ||
"containerImage": "operators.openshift.io/image", | ||
} | ||
|
||
bundleAnnotations := map[string]string{} | ||
for fromKey, toKey := range desiredAnnotations { | ||
if value, ok := csvMetadata.Annotations[fromKey]; ok { | ||
bundleAnnotations[toKey] = value | ||
} | ||
} | ||
v2b.Annotations = bundleAnnotations | ||
} | ||
cfg.BundleV2s = append(cfg.BundleV2s, v2b) | ||
} | ||
|
||
for depIdx := range cfg.Deprecations { | ||
for entryIdx := range cfg.Deprecations[depIdx].Entries { | ||
e := &cfg.Deprecations[depIdx].Entries[entryIdx] | ||
switch e.Reference.Schema { | ||
case declcfg.SchemaPackage: | ||
e.Reference.Schema = declcfg.SchemaPackageV2 | ||
case declcfg.SchemaBundle: | ||
e.Reference.Schema = declcfg.SchemaBundleV2 | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func isContraint(p property.Property) bool { | ||
switch p.Type { | ||
case property.TypeConstraint, property.TypeGVKRequired, property.TypePackageRequired: | ||
return true | ||
} | ||
return false | ||
} |
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
Oops, something went wrong.