@@ -11,6 +11,12 @@ import (
1111 "github.com/operator-framework/operator-registry/alpha/property"
1212)
1313
14+ const (
15+ MediaTypePlain = "plain+v0"
16+ MediaTypeRegistry = "registry+v1"
17+ PropertyBundleMediaType = "olm.bundle.mediatype"
18+ )
19+
1420type Schemas interface {
1521 Package | Bundle | Channel
1622}
@@ -23,20 +29,9 @@ type Channel struct {
2329 declcfg.Channel
2430}
2531
26- type GVK property.GVK
27-
28- func (g GVK ) String () string {
29- return fmt .Sprintf (`group:"%s" version:"%s" kind:"%s"` , g .Group , g .Version , g .Kind )
30- }
31-
32- type GVKRequired property.GVKRequired
33-
34- func (g GVKRequired ) String () string {
35- return fmt .Sprintf (`group:"%s" version:"%s" kind:"%s"` , g .Group , g .Version , g .Kind )
36- }
37-
38- func (g GVKRequired ) AsGVK () GVK {
39- return GVK (g )
32+ type PackageRequired struct {
33+ property.PackageRequired
34+ SemverRange * bsemver.Range `json:"-"`
4035}
4136
4237type Bundle struct {
@@ -46,11 +41,11 @@ type Bundle struct {
4641
4742 mu sync.RWMutex
4843 // these properties are lazy loaded as they are requested
49- propertiesMap map [string ]property.Property
50- bundlePackage * property.Package
51- semVersion * bsemver.Version
52- providedGVKs [] GVK
53- requiredGVKs [] GVKRequired
44+ propertiesMap map [string ]property.Property
45+ bundlePackage * property.Package
46+ semVersion * bsemver.Version
47+ requiredPackages [] PackageRequired
48+ mediaType string
5449}
5550
5651func (b * Bundle ) Version () (* bsemver.Version , error ) {
@@ -60,18 +55,19 @@ func (b *Bundle) Version() (*bsemver.Version, error) {
6055 return b .semVersion , nil
6156}
6257
63- func (b * Bundle ) ProvidedGVKs () ([]GVK , error ) {
64- if err := b .loadProvidedGVKs (); err != nil {
58+ func (b * Bundle ) RequiredPackages () ([]PackageRequired , error ) {
59+ if err := b .loadRequiredPackages (); err != nil {
6560 return nil , err
6661 }
67- return b .providedGVKs , nil
62+ return b .requiredPackages , nil
6863}
6964
70- func (b * Bundle ) RequiredGVKs () ([] GVKRequired , error ) {
71- if err := b .loadRequiredGVKs (); err != nil {
72- return nil , err
65+ func (b * Bundle ) MediaType () (string , error ) {
66+ if err := b .loadMediaType (); err != nil {
67+ return "" , err
7368 }
74- return b .requiredGVKs , nil
69+
70+ return b .mediaType , nil
7571}
7672
7773func (b * Bundle ) loadPackage () error {
@@ -94,28 +90,40 @@ func (b *Bundle) loadPackage() error {
9490 return nil
9591}
9692
97- func (b * Bundle ) loadProvidedGVKs () error {
93+ func (b * Bundle ) loadRequiredPackages () error {
9894 b .mu .Lock ()
9995 defer b .mu .Unlock ()
100- if b .providedGVKs == nil {
101- providedGVKs , err := loadFromProps [[]GVK ](b , property .TypeGVK , false )
96+ if b .requiredPackages == nil {
97+ requiredPackages , err := loadFromProps [[]PackageRequired ](b , property .TypePackageRequired , false )
10298 if err != nil {
103- return fmt .Errorf ("error determining provided GVKs for bundle %q: %s" , b .Name , err )
99+ return fmt .Errorf ("error determining bundle required packages for bundle %q: %s" , b .Name , err )
100+ }
101+ for _ , requiredPackage := range requiredPackages {
102+ semverRange , err := bsemver .ParseRange (requiredPackage .VersionRange )
103+ if err != nil {
104+ return fmt .Errorf (
105+ "error parsing bundle required package semver range for bundle %q (required package %q): %s" ,
106+ b .Name ,
107+ requiredPackage .PackageName ,
108+ err ,
109+ )
110+ }
111+ requiredPackage .SemverRange = & semverRange
104112 }
105- b .providedGVKs = providedGVKs
113+ b .requiredPackages = requiredPackages
106114 }
107115 return nil
108116}
109117
110- func (b * Bundle ) loadRequiredGVKs () error {
118+ func (b * Bundle ) loadMediaType () error {
111119 b .mu .Lock ()
112120 defer b .mu .Unlock ()
113- if b .requiredGVKs == nil {
114- requiredGVKs , err := loadFromProps [[] GVKRequired ] (b , property . TypeGVKRequired , false )
121+ if b .mediaType == "" {
122+ mediaType , err := loadFromProps [string ] (b , PropertyBundleMediaType , false )
115123 if err != nil {
116- return fmt .Errorf ("error determining required GVKs for bundle %q: %s" , b .Name , err )
124+ return fmt .Errorf ("error determining bundle mediatype for bundle %q: %s" , b .Name , err )
117125 }
118- b .requiredGVKs = requiredGVKs
126+ b .mediaType = mediaType
119127 }
120128 return nil
121129}
0 commit comments