From 93ebbc94795ba47efbb9b5951b482f9fcd7253a8 Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Thu, 2 Nov 2023 16:49:11 +0000 Subject: [PATCH] Export variable fields Signed-off-by: Mikalai Radchuk --- internal/resolution/variables/bundle.go | 23 ++++++++++------ .../variablesources/bundle_uniqueness_test.go | 26 ++++++++----------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/internal/resolution/variables/bundle.go b/internal/resolution/variables/bundle.go index 8c238cb1c..5359ad4e5 100644 --- a/internal/resolution/variables/bundle.go +++ b/internal/resolution/variables/bundle.go @@ -45,17 +45,24 @@ func NewBundleVariable(bundle *catalogmetadata.Bundle, dependencies []*catalogme var _ deppy.Variable = &BundleUniquenessVariable{} type BundleUniquenessVariable struct { - *input.SimpleVariable + ID deppy.Identifier + UniquenessConstraints []deppy.Constraint +} + +func (s *BundleUniquenessVariable) Identifier() deppy.Identifier { + return s.ID +} + +func (s *BundleUniquenessVariable) Constraints() []deppy.Constraint { + return s.UniquenessConstraints } -// NewBundleUniquenessVariable creates a new variable that instructs the resolver to choose at most a single bundle -// from the input 'atMostID'. Examples: -// 1. restrict the solution to at most a single bundle per package -// 2. restrict the solution to at most a single bundler per provided gvk -// this guarantees that no two operators provide the same gvk and no two version of the same operator are running at the same time -func NewBundleUniquenessVariable(id deppy.Identifier, atMostIDs ...deppy.Identifier) *BundleUniquenessVariable { +// NewBundleUniquenessVariable creates a new variable that instructs +// the resolver to choose at most a single bundle from the input 'bundleVarIDs' +func NewBundleUniquenessVariable(id deppy.Identifier, bundleVarIDs ...deppy.Identifier) *BundleUniquenessVariable { return &BundleUniquenessVariable{ - SimpleVariable: input.NewSimpleVariable(id, constraint.AtMost(1, atMostIDs...)), + ID: id, + UniquenessConstraints: []deppy.Constraint{constraint.AtMost(1, bundleVarIDs...)}, } } diff --git a/internal/resolution/variablesources/bundle_uniqueness_test.go b/internal/resolution/variablesources/bundle_uniqueness_test.go index 6b63f50b1..7b48b22a0 100644 --- a/internal/resolution/variablesources/bundle_uniqueness_test.go +++ b/internal/resolution/variablesources/bundle_uniqueness_test.go @@ -92,23 +92,19 @@ func TestMakeBundleUniquenessVariables(t *testing.T) { // of the involved bundles to be allowed in the solution expectedVariables := []*olmvariables.BundleUniquenessVariable{ { - SimpleVariable: input.NewSimpleVariable( - "test-package package uniqueness", - constraint.AtMost( - 1, - deppy.Identifier("fake-catalog-test-package-test-package.v1.0.0"), - deppy.Identifier("fake-catalog-test-package-test-package.v1.0.1"), - ), - ), + ID: "test-package package uniqueness", + UniquenessConstraints: []deppy.Constraint{constraint.AtMost( + 1, + deppy.Identifier("fake-catalog-test-package-test-package.v1.0.0"), + deppy.Identifier("fake-catalog-test-package-test-package.v1.0.1"), + )}, }, { - SimpleVariable: input.NewSimpleVariable( - "some-package package uniqueness", - constraint.AtMost( - 1, - deppy.Identifier("fake-catalog-some-package-some-package.v1.0.0"), - ), - ), + ID: "some-package package uniqueness", + UniquenessConstraints: []deppy.Constraint{constraint.AtMost( + 1, + deppy.Identifier("fake-catalog-some-package-some-package.v1.0.0"), + )}, }, } require.Empty(t, cmp.Diff(variables, expectedVariables, cmp.AllowUnexported(input.SimpleVariable{}, constraint.AtMostConstraint{})))