Skip to content

Commit

Permalink
Export variable fields
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola committed Nov 2, 2023
1 parent 9c7291d commit 93ebbc9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
23 changes: 15 additions & 8 deletions internal/resolution/variables/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)},
}
}

Expand Down
26 changes: 11 additions & 15 deletions internal/resolution/variablesources/bundle_uniqueness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})))
Expand Down

0 comments on commit 93ebbc9

Please sign in to comment.