Skip to content

Commit 5cf7f1f

Browse files
authored
Remove ConstraintProvider from the exported solver package API. (#2675)
This interface is a resolver package concern, so its definition can live beside the code that accepts it. Removing it from solver also removes the only solver->cache package dependency. As I understand it, the only way to inject an implementation of this interface today is by having access to unexported fields of resolver.Resolver, so for now I've also made the interface unexported. In the context of the ongoing desire to support resolution as a separate library module, this will allow more time to evaluate the shape of a stable library API. Signed-off-by: Ben Luddy <[email protected]>
1 parent 75504b9 commit 5cf7f1f

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

pkg/controller/registry/resolver/resolver.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@ import (
1919
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
2020
)
2121

22+
// constraintProvider knows how to provide solver constraints for a given cache entry.
23+
// For instance, it could be used to surface additional constraints against an entry given some
24+
// properties it may expose. E.g. olm.maxOpenShiftVersion could be checked against the cluster version
25+
// and prohibit any entry that doesn't meet the requirement
26+
type constraintProvider interface {
27+
// Constraints returns a set of solver constraints for a cache entry.
28+
Constraints(e *cache.Entry) ([]solver.Constraint, error)
29+
}
30+
2231
type Resolver struct {
2332
cache cache.OperatorCacheProvider
2433
log logrus.FieldLogger
2534
pc *predicateConverter
26-
systemConstraintsProvider solver.ConstraintProvider
35+
systemConstraintsProvider constraintProvider
2736
}
2837

2938
func NewDefaultResolver(rcp cache.SourceProvider, sourcePriorityProvider cache.SourcePriorityProvider, logger logrus.FieldLogger) *Resolver {

pkg/controller/registry/resolver/resolver_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ func TestSolveOperators(t *testing.T) {
8080
require.ElementsMatch(t, expected, operators)
8181
}
8282

83+
// ConstraintProviderFunc is a simple implementation of ConstraintProvider
84+
type ConstraintProviderFunc func(e *cache.Entry) ([]solver.Constraint, error)
85+
86+
func (c ConstraintProviderFunc) Constraints(e *cache.Entry) ([]solver.Constraint, error) {
87+
return c(e)
88+
}
89+
8390
func TestSolveOperators_WithSystemConstraints(t *testing.T) {
8491
const namespace = "test-namespace"
8592
catalog := cache.SourceKey{Name: "test-catalog", Namespace: namespace}
@@ -99,7 +106,7 @@ func TestSolveOperators_WithSystemConstraints(t *testing.T) {
99106
existingPackageD := existingOperator(namespace, "packageD.v1", "packageD", "alpha", "", nil, nil, nil, nil)
100107
existingPackageD.Annotations = map[string]string{"operatorframework.io/properties": `{"properties":[{"type":"olm.package","value":{"packageName":"packageD","version":"1.0.0"}}]}`}
101108

102-
whiteListConstraintProvider := func(whiteList ...*cache.Entry) solver.ConstraintProviderFunc {
109+
whiteListConstraintProvider := func(whiteList ...*cache.Entry) ConstraintProviderFunc {
103110
return func(entry *cache.Entry) ([]solver.Constraint, error) {
104111
for _, whiteListedEntry := range whiteList {
105112
if whiteListedEntry.Package() == entry.Package() &&
@@ -117,7 +124,7 @@ func TestSolveOperators_WithSystemConstraints(t *testing.T) {
117124

118125
testCases := []struct {
119126
title string
120-
systemConstraintsProvider solver.ConstraintProvider
127+
systemConstraintsProvider constraintProvider
121128
expectedOperators []*cache.Entry
122129
csvs []*v1alpha1.ClusterServiceVersion
123130
subs []*v1alpha1.Subscription

pkg/controller/registry/resolver/solver/constraint_provider.go

-19
This file was deleted.

0 commit comments

Comments
 (0)