Skip to content

Commit d568b20

Browse files
address newer review comments to preserve build metadata when using pkg.Release field
Signed-off-by: Rashmi Gottipati <rgottipa@redhat.com>
1 parent 19ccfa7 commit d568b20

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

internal/operator-controller/bundleutil/bundle.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ func parseVersionRelease(pkgData json.RawMessage) (*bundle.VersionRelease, error
2929
return nil, fmt.Errorf("error unmarshalling package property: %w", err)
3030
}
3131

32-
// When BundleReleaseSupport is enabled and bundle has explicit release field, use it
32+
// When BundleReleaseSupport is enabled and bundle has explicit release field, use it.
33+
// Note: Build metadata is preserved here because with an explicit release field,
34+
// build metadata serves its proper semver purpose (e.g., git commit, build number).
35+
// In contrast, NewLegacyRegistryV1VersionRelease clears build metadata because it
36+
// interprets build metadata AS the release value for registry+v1 bundles.
3337
if features.OperatorControllerFeatureGate.Enabled(features.BundleReleaseSupport) && pkg.Release != "" {
3438
vers, err := bsemver.Parse(pkg.Version)
3539
if err != nil {
3640
return nil, fmt.Errorf("error parsing version %q: %w", pkg.Version, err)
3741
}
38-
// Strip build metadata when using explicit release field to maintain consistency
39-
// with NewLegacyRegistryV1VersionRelease(), which also clears build metadata.
40-
vers.Build = nil
4142
rel, err := bundle.NewRelease(pkg.Release)
4243
if err != nil {
4344
return nil, fmt.Errorf("error parsing release %q: %w", pkg.Release, err)

internal/operator-controller/bundleutil/bundle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestGetVersionAndRelease_WithBundleReleaseSupport(t *testing.T) {
120120
Value: json.RawMessage(`{"version": "1.0.0+ignored", "release": "2"}`),
121121
},
122122
wantVersionRelease: &bundle.VersionRelease{
123-
Version: bsemver.MustParse("1.0.0"), // Build metadata stripped when using explicit release
123+
Version: bsemver.MustParse("1.0.0+ignored"), // Build metadata preserved - serves its proper semver purpose
124124
Release: bundle.Release([]bsemver.PRVersion{
125125
{VersionNum: 2, IsNum: true},
126126
}),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ func InAnyChannel(channels ...declcfg.Channel) filter.Predicate[declcfg.Bundle]
5454
// This is used to identify re-released bundles (e.g., 2.0.0+2 when 2.0.0+1 is installed).
5555
//
5656
// Note: The expect parameter (from installed bundle) originates from NewLegacyRegistryV1VersionRelease,
57-
// which clears build metadata. The actual parameter (from candidate bundle) comes from
58-
// GetVersionAndRelease, which may preserve build metadata when parsing explicit pkg.Release.
57+
// which clears build metadata because it interprets build metadata AS the release value. The actual
58+
// parameter (from candidate bundle) comes from GetVersionAndRelease, which preserves build metadata
59+
// when parsing explicit pkg.Release (since build metadata serves its proper semver purpose there).
5960
// This structural difference is safe: Version.Compare() ignores build metadata per semver spec,
6061
// so mixed-source comparison works correctly.
6162
func SameVersionHigherRelease(expect bundle.VersionRelease) filter.Predicate[declcfg.Bundle] {

0 commit comments

Comments
 (0)