Skip to content

Commit f147e61

Browse files
authored
Add extra bundle filtering (#532)
This commit adds extra bundle filtering when looking for a currently installed bundle. This prevents updates from one package to another in case when currently installed bundle shares bundle image with a bundle from another package. Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
1 parent f95ef47 commit f147e61

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

internal/resolution/variablesources/bundle_deployment_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ var _ = Describe("BundleDeploymentVariableSource", func() {
136136
})
137137

138138
It("should produce RequiredPackage variables", func() {
139-
fakeOperator := fakeOperator("test-operator", "test-prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
139+
fakeOperator := fakeOperator("test-operator", "prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
140140
operators := []operatorsv1alpha1.Operator{fakeOperator}
141141
bundleDeployments := []rukpakv1alpha1.BundleDeployment{
142142
bundleDeployment("prometheus", "quay.io/operatorhubio/prometheus@sha256:3e281e587de3d03011440685fc4fb782672beab044c1ebadc42788ce05a21c35", &fakeOperator),
@@ -161,14 +161,14 @@ var _ = Describe("BundleDeploymentVariableSource", func() {
161161
})))
162162
})
163163
It("should return an error if the bundleDeployment image doesn't match any operator resource", func() {
164-
fakeOperator := fakeOperator("test-operator", "test-prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
164+
fakeOperator := fakeOperator("test-operator", "prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
165165
operators := []operatorsv1alpha1.Operator{fakeOperator}
166166
bundleDeployments := []rukpakv1alpha1.BundleDeployment{
167167
bundleDeployment("prometheus", "quay.io/operatorhubio/prometheus@sha256:nonexistent", &fakeOperator),
168168
}
169169

170170
bdVariableSource := variablesources.NewBundleDeploymentVariableSource(operators, bundleDeployments, testBundleList, &MockRequiredPackageSource{})
171171
_, err := bdVariableSource.GetVariables(context.Background())
172-
Expect(err.Error()).To(Equal(`bundle with image "quay.io/operatorhubio/prometheus@sha256:nonexistent" not found in available catalogs but is currently installed via BundleDeployment "prometheus"`))
172+
Expect(err.Error()).To(Equal(`bundle with image "quay.io/operatorhubio/prometheus@sha256:nonexistent" for package "prometheus" not found in available catalogs but is currently installed via BundleDeployment "prometheus"`))
173173
})
174174
})

internal/resolution/variablesources/installed_package.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ func MakeInstalledPackageVariables(
6464
bundleImage := sourceImage.Ref
6565

6666
// find corresponding bundle for the installed content
67-
resultSet := catalogfilter.Filter(allBundles, catalogfilter.WithBundleImage(bundleImage))
67+
resultSet := catalogfilter.Filter(allBundles, catalogfilter.And(
68+
catalogfilter.WithPackageName(operator.Spec.PackageName),
69+
catalogfilter.WithBundleImage(bundleImage),
70+
))
6871
if len(resultSet) == 0 {
69-
return nil, fmt.Errorf("bundle with image %q not found in available catalogs but is currently installed via BundleDeployment %q", bundleImage, bundleDeployment.Name)
72+
return nil, fmt.Errorf("bundle with image %q for package %q not found in available catalogs but is currently installed via BundleDeployment %q", bundleImage, operator.Spec.PackageName, bundleDeployment.Name)
7073
}
7174

7275
sort.SliceStable(resultSet, func(i, j int) bool {

internal/resolution/variablesources/installed_package_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,6 @@ func TestMakeInstalledPackageVariables(t *testing.T) {
390390
},
391391
)
392392
assert.Nil(t, installedPackages)
393-
assert.ErrorContains(t, err, `bundle with image "registry.io/repo/test-package@v9.0.0" not found in available catalogs but is currently installed via BundleDeployment "test-package-bd"`)
393+
assert.ErrorContains(t, err, `bundle with image "registry.io/repo/test-package@v9.0.0" for package "test-package" not found in available catalogs but is currently installed via BundleDeployment "test-package-bd"`)
394394
})
395395
}

0 commit comments

Comments
 (0)