Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 Export variable fields #505

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the best example, but I'm trying to find a nicier way to do these comparisons.

E.g. in #498 we do this:

	gocmpopts := []cmp.Option{
		cmpopts.IgnoreUnexported(sync.RWMutex{}),
		cmp.AllowUnexported(
			sync.RWMutex{},
			olmvariables.BundleVariable{},
			input.SimpleVariable{},
			constraint.DependencyConstraint{},
			catalogmetadata.Bundle{},
		),
		cmpopts.IgnoreFields(
			// Do not compare a func field
			catalogmetadata.PackageRequired{}, "SemverRange",
		),
	}
	require.Empty(t, cmp.Diff(bundles, expectedVariables, gocmpopts...))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't had enough time to review all of it - but you likely do not want to compare internals of sync.RWMutex - perhaps even of the others. For each, ask if it's possible or valid for the third-party package to change the implementation detail of unexported fields and if that would be a bona-fide concern for the caller here.

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