forked from operator-framework/operator-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.go
38 lines (32 loc) · 1.05 KB
/
bundle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package bundleutil
import (
"encoding/json"
"fmt"
bsemver "github.com/blang/semver/v4"
"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-registry/alpha/property"
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
)
func GetVersion(b declcfg.Bundle) (*bsemver.Version, error) {
for _, p := range b.Properties {
if p.Type == property.TypePackage {
var pkg property.Package
if err := json.Unmarshal(p.Value, &pkg); err != nil {
return nil, fmt.Errorf("error unmarshalling package property: %w", err)
}
vers, err := bsemver.Parse(pkg.Version)
if err != nil {
return nil, err
}
return &vers, nil
}
}
return nil, fmt.Errorf("no package property found in bundle %q", b.Name)
}
// MetadataFor returns a BundleMetadata for the given bundle name and version.
func MetadataFor(bundleName string, bundleVersion bsemver.Version) *ocv1alpha1.BundleMetadata {
return &ocv1alpha1.BundleMetadata{
Name: bundleName,
Version: bundleVersion.String(),
}
}