Skip to content

Commit e0fe939

Browse files
address review comments
Signed-off-by: Rashmi Gottipati <rgottipa@redhat.com>
1 parent 1d1b7d6 commit e0fe939

3 files changed

Lines changed: 12 additions & 36 deletions

File tree

internal/operator-controller/bundleutil/bundle.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ func GetVersionAndRelease(b declcfg.Bundle) (*declcfg.VersionRelease, error) {
2222
return nil, fmt.Errorf("no package property found in bundle %q", b.Name)
2323
}
2424

25-
// newLegacyRegistryV1VersionRelease parses a registry+v1 bundle version string and returns a
25+
// ParseLegacyVersionRelease parses a registry+v1 bundle version string and returns a
2626
// VersionRelease. Some registry+v1 bundles utilize the build metadata field of the semver version
2727
// as release information (a semver spec violation maintained for backward compatibility). When the
2828
// bundle version includes build metadata that is parsable as a release, the returned
2929
// VersionRelease has the build metadata extracted into the Release field, and the Version field
3030
// has its Build metadata cleared. When the bundle version includes build metadata that is NOT
3131
// parseable as a release, the returned VersionRelease has its Version set to the full semver
3232
// version (with build metadata) and its Release left empty.
33-
func newLegacyRegistryV1VersionRelease(vStr string) (*declcfg.VersionRelease, error) {
33+
func ParseLegacyVersionRelease(vStr string) (*declcfg.VersionRelease, error) {
3434
vers, err := bsemver.Parse(vStr)
3535
if err != nil {
3636
return nil, err
@@ -93,13 +93,13 @@ func parseVersionRelease(pkgData json.RawMessage) (*declcfg.VersionRelease, erro
9393
// In the future, for supporting other bundle formats, we should not
9494
// use the legacy registry+v1 mechanism (i.e. using build metadata in
9595
// the version) to determine the bundle's release.
96-
return newLegacyRegistryV1VersionRelease(pkg.Version)
96+
return ParseLegacyVersionRelease(pkg.Version)
9797
}
9898

9999
// parseExplicitRelease parses version and release from separate fields.
100100
// Build metadata is preserved in the version because with an explicit release field,
101101
// build metadata serves its proper semver purpose (e.g., git commit, build number).
102-
// In contrast, newLegacyRegistryV1VersionRelease clears build metadata because it
102+
// In contrast, ParseLegacyVersionRelease clears build metadata because it
103103
// interprets build metadata AS the release value for registry+v1 bundles.
104104
func parseExplicitRelease(version, releaseStr string) (*declcfg.VersionRelease, error) {
105105
vers, err := bsemver.Parse(version)

internal/operator-controller/catalogmetadata/filter/successors.go

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/operator-framework/operator-registry/alpha/declcfg"
99

1010
ocv1 "github.com/operator-framework/operator-controller/api/v1"
11+
"github.com/operator-framework/operator-controller/internal/operator-controller/bundleutil"
1112
"github.com/operator-framework/operator-controller/internal/shared/util/filter"
1213
)
1314

@@ -17,11 +18,15 @@ import (
1718
func parseInstalledBundleVersionRelease(installedBundle ocv1.BundleMetadata) (*declcfg.VersionRelease, error) {
1819
// Handle legacy registry+v1 format: release embedded in version's build metadata
1920
if installedBundle.Release == nil {
20-
return newLegacyRegistryV1VersionRelease(installedBundle.Version)
21+
vr, err := bundleutil.ParseLegacyVersionRelease(installedBundle.Version)
22+
if err != nil {
23+
return nil, fmt.Errorf("failed to get version and release of installed bundle: %w", err)
24+
}
25+
return vr, nil
2126
}
2227

2328
// Bundle has explicit release field (or explicitly empty) - parse version and release from separate fields.
24-
// Note: We can't use newLegacyRegistryV1VersionRelease here because the version might
29+
// Note: We can't use ParseLegacyVersionRelease here because the version might
2530
// already contain build metadata (e.g., "1.0.0+git.abc"), which serves its proper
2631
// semver purpose when using explicit pkg.Release. Concatenating would create invalid
2732
// semver like "1.0.0+git.abc+2".
@@ -48,35 +53,6 @@ func parseInstalledBundleVersionRelease(installedBundle ocv1.BundleMetadata) (*d
4853
}, nil
4954
}
5055

51-
// newLegacyRegistryV1VersionRelease parses a registry+v1 bundle version string and returns a
52-
// VersionRelease. Some registry+v1 bundles utilize the build metadata field of the semver version
53-
// as release information (a semver spec violation maintained for backward compatibility).
54-
func newLegacyRegistryV1VersionRelease(vStr string) (*declcfg.VersionRelease, error) {
55-
vers, err := bsemver.Parse(vStr)
56-
if err != nil {
57-
return nil, fmt.Errorf("failed to get version and release of installed bundle: %w", err)
58-
}
59-
60-
vr := &declcfg.VersionRelease{
61-
Version: vers,
62-
}
63-
64-
buildMetadata := ""
65-
if len(vr.Version.Build) > 0 {
66-
buildMetadata = vr.Version.Build[0]
67-
for i := 1; i < len(vr.Version.Build); i++ {
68-
buildMetadata += "." + vr.Version.Build[i]
69-
}
70-
}
71-
72-
rel, err := declcfg.NewRelease(buildMetadata)
73-
if err == nil && len(rel) > 0 {
74-
vr.Release = rel
75-
vr.Version.Build = nil
76-
}
77-
return vr, nil
78-
}
79-
8056
func SuccessorsOf(installedBundle ocv1.BundleMetadata, channels ...declcfg.Channel) (filter.Predicate[declcfg.Bundle], error) {
8157
installedVersionRelease, err := parseInstalledBundleVersionRelease(installedBundle)
8258
if err != nil {

internal/operator-controller/catalogmetadata/filter/successors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// mustVersionRelease is a test helper that parses a version string into a VersionRelease.
2222
// For registry+v1 bundles, build metadata is interpreted as release (e.g., "1.0.0+2" -> Version: 1.0.0, Release: 2).
2323
func mustVersionRelease(versionStr string) declcfg.VersionRelease {
24-
vr, err := newLegacyRegistryV1VersionRelease(versionStr)
24+
vr, err := bundleutil.ParseLegacyVersionRelease(versionStr)
2525
if err != nil {
2626
panic(err)
2727
}

0 commit comments

Comments
 (0)