-
Notifications
You must be signed in to change notification settings - Fork 67
✨remove ForceSemverUpgradeConstraints feature gate and implementation #1638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joelanford
merged 1 commit into
operator-framework:main
from
joelanford:rm-force-semver-upgrade-graph
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -9,190 +9,16 @@ import ( | |
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
featuregatetesting "k8s.io/component-base/featuregate/testing" | ||
|
||
"github.com/operator-framework/operator-registry/alpha/declcfg" | ||
"github.com/operator-framework/operator-registry/alpha/property" | ||
|
||
ocv1 "github.com/operator-framework/operator-controller/api/v1" | ||
"github.com/operator-framework/operator-controller/internal/bundleutil" | ||
"github.com/operator-framework/operator-controller/internal/catalogmetadata/compare" | ||
"github.com/operator-framework/operator-controller/internal/features" | ||
) | ||
|
||
func TestSuccessorsPredicateWithForceSemverUpgradeConstraintsEnabled(t *testing.T) { | ||
featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, true) | ||
|
||
const testPackageName = "test-package" | ||
channelSet := map[string]declcfg.Channel{ | ||
testPackageName: { | ||
Package: testPackageName, | ||
Name: "stable", | ||
}, | ||
} | ||
|
||
bundleSet := map[string]declcfg.Bundle{ | ||
// Major version zero is for initial development and | ||
// has different update behaviour than versions >= 1.0.0: | ||
// - In versions 0.0.y updates are not allowed when using semver constraints | ||
// - In versions 0.x.y only patch updates are allowed (>= 0.x.y and < 0.x+1.0) | ||
// This means that we need in test data bundles that cover these three version ranges. | ||
"test-package.v0.0.1": { | ||
Name: "test-package.v0.0.1", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "0.0.1"), | ||
}, | ||
}, | ||
"test-package.v0.0.2": { | ||
Name: "test-package.v0.0.2", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "0.0.2"), | ||
}, | ||
}, | ||
"test-package.v0.1.0": { | ||
Name: "test-package.v0.1.0", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "0.1.0"), | ||
}, | ||
}, | ||
"test-package.v0.1.1": { | ||
Name: "test-package.v0.1.1", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "0.1.1"), | ||
}, | ||
}, | ||
"test-package.v0.1.2": { | ||
Name: "test-package.v0.1.2", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "0.1.2"), | ||
}, | ||
}, | ||
"test-package.v0.2.0": { | ||
Name: "test-package.v0.2.0", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "0.2.0"), | ||
}, | ||
}, | ||
"test-package.v2.0.0": { | ||
Name: "test-package.v2.0.0", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "2.0.0"), | ||
}, | ||
}, | ||
"test-package.v2.1.0": { | ||
Name: "test-package.v2.1.0", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "2.1.0"), | ||
}, | ||
}, | ||
"test-package.v2.2.0": { | ||
Name: "test-package.v2.2.0", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "2.2.0"), | ||
}, | ||
}, | ||
// We need a bundle with a different major version to ensure | ||
// that we do not allow upgrades from one major version to another | ||
"test-package.v3.0.0": { | ||
Name: "test-package.v3.0.0", | ||
Package: testPackageName, | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
property.MustBuildPackage(testPackageName, "3.0.0"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, b := range bundleSet { | ||
ch := channelSet[b.Package] | ||
ch.Entries = append(ch.Entries, declcfg.ChannelEntry{Name: b.Name}) | ||
channelSet[b.Package] = ch | ||
} | ||
|
||
for _, tt := range []struct { | ||
name string | ||
installedBundle ocv1.BundleMetadata | ||
expectedResult []declcfg.Bundle | ||
}{ | ||
{ | ||
name: "with non-zero major version", | ||
installedBundle: bundleutil.MetadataFor("test-package.v2.0.0", bsemver.MustParse("2.0.0")), | ||
expectedResult: []declcfg.Bundle{ | ||
// Updates are allowed within the major version | ||
bundleSet["test-package.v2.2.0"], | ||
bundleSet["test-package.v2.1.0"], | ||
bundleSet["test-package.v2.0.0"], | ||
}, | ||
}, | ||
{ | ||
name: "with zero major and zero minor version", | ||
installedBundle: bundleutil.MetadataFor("test-package.v0.0.1", bsemver.MustParse("0.0.1")), | ||
expectedResult: []declcfg.Bundle{ | ||
// No updates are allowed in major version zero when minor version is also zero | ||
bundleSet["test-package.v0.0.1"], | ||
}, | ||
}, | ||
{ | ||
name: "with zero major and non-zero minor version", | ||
installedBundle: bundleutil.MetadataFor("test-package.v0.1.0", bsemver.MustParse("0.1.0")), | ||
expectedResult: []declcfg.Bundle{ | ||
// Patch version updates are allowed within the minor version | ||
bundleSet["test-package.v0.1.2"], | ||
bundleSet["test-package.v0.1.1"], | ||
bundleSet["test-package.v0.1.0"], | ||
}, | ||
}, | ||
{ | ||
name: "installed bundle not found", | ||
installedBundle: ocv1.BundleMetadata{ | ||
Name: "test-package.v9.0.0", | ||
Version: "9.0.0", | ||
}, | ||
expectedResult: []declcfg.Bundle{}, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
successors, err := SuccessorsOf(tt.installedBundle, channelSet[testPackageName]) | ||
require.NoError(t, err) | ||
|
||
allBundles := make([]declcfg.Bundle, 0, len(bundleSet)) | ||
for _, bundle := range bundleSet { | ||
allBundles = append(allBundles, bundle) | ||
} | ||
result := Filter(allBundles, successors) | ||
|
||
// sort before comparison for stable order | ||
slices.SortFunc(result, compare.ByVersion) | ||
|
||
gocmpopts := []cmp.Option{ | ||
cmpopts.IgnoreUnexported(declcfg.Bundle{}), | ||
} | ||
require.Empty(t, cmp.Diff(result, tt.expectedResult, gocmpopts...)) | ||
}) | ||
} | ||
} | ||
|
||
func TestSuccessorsPredicateWithForceSemverUpgradeConstraintsDisabled(t *testing.T) { | ||
featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, false) | ||
|
||
func TestSuccessorsPredicate(t *testing.T) { | ||
const testPackageName = "test-package" | ||
channelSet := map[string]declcfg.Channel{ | ||
testPackageName: { | ||
|
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @joelanford
Any reason why we should not remove the unused funcs raised by the lint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! Pushed an amended commit to fix.