Skip to content

Commit e9733c5

Browse files
authored
Fix filtering of successors bundles (#480)
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 <[email protected]>
1 parent 3fc434d commit e9733c5

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

internal/resolution/variablesources/installed_package.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ type successorsFunc func(allBundles []*catalogmetadata.Bundle, installedBundle *
8383
func legacySemanticsSuccessors(allBundles []*catalogmetadata.Bundle, installedBundle *catalogmetadata.Bundle) ([]*catalogmetadata.Bundle, error) {
8484
// find the bundles that replace the bundle provided
8585
// TODO: this algorithm does not yet consider skips and skipRange
86-
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.Replaces(installedBundle.Name))
86+
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.And(
87+
catalogfilter.WithPackageName(installedBundle.Package),
88+
catalogfilter.Replaces(installedBundle.Name),
89+
))
8790
sort.SliceStable(upgradeEdges, func(i, j int) bool {
8891
return catalogsort.ByVersion(upgradeEdges[i], upgradeEdges[j])
8992
})
@@ -108,7 +111,10 @@ func semverSuccessors(allBundles []*catalogmetadata.Bundle, installedBundle *cat
108111
return nil, err
109112
}
110113

111-
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.InMastermindsSemverRange(wantedVersionRangeConstraint))
114+
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.And(
115+
catalogfilter.WithPackageName(installedBundle.Package),
116+
catalogfilter.InMastermindsSemverRange(wantedVersionRangeConstraint),
117+
))
112118
sort.SliceStable(upgradeEdges, func(i, j int) bool {
113119
return catalogsort.ByVersion(upgradeEdges[i], upgradeEdges[j])
114120
})

internal/resolution/variablesources/installed_package_test.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ import (
2020
)
2121

2222
func TestInstalledPackageVariableSource(t *testing.T) {
23-
channel := catalogmetadata.Channel{Channel: declcfg.Channel{
24-
Name: "stable",
23+
someOtherPackageChannel := catalogmetadata.Channel{Channel: declcfg.Channel{
24+
Name: "stable",
25+
Package: "some-other-package",
26+
Entries: []declcfg.ChannelEntry{
27+
{
28+
Name: "some-other-package.v2.3.0",
29+
},
30+
},
31+
}}
32+
testPackageChannel := catalogmetadata.Channel{Channel: declcfg.Channel{
33+
Name: "stable",
34+
Package: "test-package",
2535
Entries: []declcfg.ChannelEntry{
2636
{
2737
Name: "test-package.v0.0.1",
@@ -80,7 +90,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
8090
Properties: []property.Property{
8191
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.0.1"}`)},
8292
}},
83-
InChannels: []*catalogmetadata.Channel{&channel},
93+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
8494
},
8595
{Bundle: declcfg.Bundle{
8696
Name: "test-package.v0.0.2",
@@ -89,7 +99,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
8999
Properties: []property.Property{
90100
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.0.2"}`)},
91101
}},
92-
InChannels: []*catalogmetadata.Channel{&channel},
102+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
93103
},
94104
{Bundle: declcfg.Bundle{
95105
Name: "test-package.v0.1.0",
@@ -98,7 +108,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
98108
Properties: []property.Property{
99109
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.1.0"}`)},
100110
}},
101-
InChannels: []*catalogmetadata.Channel{&channel},
111+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
102112
},
103113
{Bundle: declcfg.Bundle{
104114
Name: "test-package.v0.1.1",
@@ -107,7 +117,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
107117
Properties: []property.Property{
108118
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.1.1"}`)},
109119
}},
110-
InChannels: []*catalogmetadata.Channel{&channel},
120+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
111121
},
112122
{Bundle: declcfg.Bundle{
113123
Name: "test-package.v0.2.0",
@@ -116,7 +126,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
116126
Properties: []property.Property{
117127
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.2.0"}`)},
118128
}},
119-
InChannels: []*catalogmetadata.Channel{&channel},
129+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
120130
},
121131
{Bundle: declcfg.Bundle{
122132
Name: "test-package.v1.0.0",
@@ -125,7 +135,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
125135
Properties: []property.Property{
126136
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "1.0.0"}`)},
127137
}},
128-
InChannels: []*catalogmetadata.Channel{&channel},
138+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
129139
},
130140
{Bundle: declcfg.Bundle{
131141
Name: "test-package.v3.0.0",
@@ -134,7 +144,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
134144
Properties: []property.Property{
135145
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "3.0.0"}`)},
136146
}},
137-
InChannels: []*catalogmetadata.Channel{&channel},
147+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
138148
},
139149
{Bundle: declcfg.Bundle{
140150
Name: "test-package.v2.0.0",
@@ -143,7 +153,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
143153
Properties: []property.Property{
144154
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.0.0"}`)},
145155
}},
146-
InChannels: []*catalogmetadata.Channel{&channel},
156+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
147157
},
148158
{Bundle: declcfg.Bundle{
149159
Name: "test-package.v2.1.0",
@@ -152,7 +162,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
152162
Properties: []property.Property{
153163
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.1.0"}`)},
154164
}},
155-
InChannels: []*catalogmetadata.Channel{&channel},
165+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
156166
},
157167
{Bundle: declcfg.Bundle{
158168
Name: "test-package.v2.2.0",
@@ -161,7 +171,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
161171
Properties: []property.Property{
162172
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.2.0"}`)},
163173
}},
164-
InChannels: []*catalogmetadata.Channel{&channel},
174+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
165175
},
166176
{Bundle: declcfg.Bundle{
167177
Name: "test-package.v4.0.0",
@@ -170,16 +180,25 @@ func TestInstalledPackageVariableSource(t *testing.T) {
170180
Properties: []property.Property{
171181
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "4.0.0"}`)},
172182
}},
173-
InChannels: []*catalogmetadata.Channel{&channel},
183+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
174184
},
175185
{Bundle: declcfg.Bundle{
176186
Name: "test-package.v5.0.0",
177187
Package: "test-package",
178188
Image: "registry.io/repo/[email protected]",
179189
Properties: []property.Property{
180-
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "5-0.0"}`)},
190+
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "5.0.0"}`)},
191+
}},
192+
InChannels: []*catalogmetadata.Channel{&testPackageChannel},
193+
},
194+
{Bundle: declcfg.Bundle{
195+
Name: "some-other-package.v2.3.0",
196+
Package: "some-other-package",
197+
Image: "registry.io/repo/[email protected]",
198+
Properties: []property.Property{
199+
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "some-other-package", "version": "2.3.0"}`)},
181200
}},
182-
InChannels: []*catalogmetadata.Channel{&channel},
201+
InChannels: []*catalogmetadata.Channel{&someOtherPackageChannel},
183202
},
184203
}
185204

0 commit comments

Comments
 (0)