Skip to content

Commit

Permalink
Fix filtering of successors bundles (#480)
Browse files Browse the repository at this point in the history
Previously we were not filtering bundles by package name.
This could cause the code to select incorrect successors
becuase we were only filtering all bundle by versions.

With this change we make sure that we are selecting bundles
from the same package.

Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola authored Oct 23, 2023
1 parent 3fc434d commit e9733c5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
10 changes: 8 additions & 2 deletions internal/resolution/variablesources/installed_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ type successorsFunc func(allBundles []*catalogmetadata.Bundle, installedBundle *
func legacySemanticsSuccessors(allBundles []*catalogmetadata.Bundle, installedBundle *catalogmetadata.Bundle) ([]*catalogmetadata.Bundle, error) {
// find the bundles that replace the bundle provided
// TODO: this algorithm does not yet consider skips and skipRange
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.Replaces(installedBundle.Name))
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.And(
catalogfilter.WithPackageName(installedBundle.Package),
catalogfilter.Replaces(installedBundle.Name),
))
sort.SliceStable(upgradeEdges, func(i, j int) bool {
return catalogsort.ByVersion(upgradeEdges[i], upgradeEdges[j])
})
Expand All @@ -108,7 +111,10 @@ func semverSuccessors(allBundles []*catalogmetadata.Bundle, installedBundle *cat
return nil, err
}

upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.InMastermindsSemverRange(wantedVersionRangeConstraint))
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.And(
catalogfilter.WithPackageName(installedBundle.Package),
catalogfilter.InMastermindsSemverRange(wantedVersionRangeConstraint),
))
sort.SliceStable(upgradeEdges, func(i, j int) bool {
return catalogsort.ByVersion(upgradeEdges[i], upgradeEdges[j])
})
Expand Down
49 changes: 34 additions & 15 deletions internal/resolution/variablesources/installed_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ import (
)

func TestInstalledPackageVariableSource(t *testing.T) {
channel := catalogmetadata.Channel{Channel: declcfg.Channel{
Name: "stable",
someOtherPackageChannel := catalogmetadata.Channel{Channel: declcfg.Channel{
Name: "stable",
Package: "some-other-package",
Entries: []declcfg.ChannelEntry{
{
Name: "some-other-package.v2.3.0",
},
},
}}
testPackageChannel := catalogmetadata.Channel{Channel: declcfg.Channel{
Name: "stable",
Package: "test-package",
Entries: []declcfg.ChannelEntry{
{
Name: "test-package.v0.0.1",
Expand Down Expand Up @@ -80,7 +90,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.0.1"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v0.0.2",
Expand All @@ -89,7 +99,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.0.2"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v0.1.0",
Expand All @@ -98,7 +108,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.1.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v0.1.1",
Expand All @@ -107,7 +117,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.1.1"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v0.2.0",
Expand All @@ -116,7 +126,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.2.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v1.0.0",
Expand All @@ -125,7 +135,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "1.0.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v3.0.0",
Expand All @@ -134,7 +144,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "3.0.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v2.0.0",
Expand All @@ -143,7 +153,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.0.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v2.1.0",
Expand All @@ -152,7 +162,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.1.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v2.2.0",
Expand All @@ -161,7 +171,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.2.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v4.0.0",
Expand All @@ -170,16 +180,25 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "4.0.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v5.0.0",
Package: "test-package",
Image: "registry.io/repo/test-package@v5.0.0",
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "5-0.0"}`)},
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "5.0.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
},
{Bundle: declcfg.Bundle{
Name: "some-other-package.v2.3.0",
Package: "some-other-package",
Image: "registry.io/repo/some-other-package@v2.3.0",
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "some-other-package", "version": "2.3.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
InChannels: []*catalogmetadata.Channel{&someOtherPackageChannel},
},
}

Expand Down

0 comments on commit e9733c5

Please sign in to comment.