Skip to content

Commit

Permalink
Add extra bundle filtering (#532)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
m1kola committed Nov 10, 2023
1 parent f95ef47 commit f147e61
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/resolution/variablesources/bundle_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var _ = Describe("BundleDeploymentVariableSource", func() {
})

It("should produce RequiredPackage variables", func() {
fakeOperator := fakeOperator("test-operator", "test-prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
fakeOperator := fakeOperator("test-operator", "prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
operators := []operatorsv1alpha1.Operator{fakeOperator}
bundleDeployments := []rukpakv1alpha1.BundleDeployment{
bundleDeployment("prometheus", "quay.io/operatorhubio/prometheus@sha256:3e281e587de3d03011440685fc4fb782672beab044c1ebadc42788ce05a21c35", &fakeOperator),
Expand All @@ -161,14 +161,14 @@ var _ = Describe("BundleDeploymentVariableSource", func() {
})))
})
It("should return an error if the bundleDeployment image doesn't match any operator resource", func() {
fakeOperator := fakeOperator("test-operator", "test-prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
fakeOperator := fakeOperator("test-operator", "prometheus", operatorsv1alpha1.UpgradeConstraintPolicyEnforce)
operators := []operatorsv1alpha1.Operator{fakeOperator}
bundleDeployments := []rukpakv1alpha1.BundleDeployment{
bundleDeployment("prometheus", "quay.io/operatorhubio/prometheus@sha256:nonexistent", &fakeOperator),
}

bdVariableSource := variablesources.NewBundleDeploymentVariableSource(operators, bundleDeployments, testBundleList, &MockRequiredPackageSource{})
_, err := bdVariableSource.GetVariables(context.Background())
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"`))
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"`))
})
})
7 changes: 5 additions & 2 deletions internal/resolution/variablesources/installed_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ func MakeInstalledPackageVariables(
bundleImage := sourceImage.Ref

// find corresponding bundle for the installed content
resultSet := catalogfilter.Filter(allBundles, catalogfilter.WithBundleImage(bundleImage))
resultSet := catalogfilter.Filter(allBundles, catalogfilter.And(
catalogfilter.WithPackageName(operator.Spec.PackageName),
catalogfilter.WithBundleImage(bundleImage),
))
if len(resultSet) == 0 {
return nil, fmt.Errorf("bundle with image %q not found in available catalogs but is currently installed via BundleDeployment %q", bundleImage, bundleDeployment.Name)
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)
}

sort.SliceStable(resultSet, func(i, j int) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,6 @@ func TestMakeInstalledPackageVariables(t *testing.T) {
},
)
assert.Nil(t, installedPackages)
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"`)
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"`)
})
}

0 comments on commit f147e61

Please sign in to comment.