Skip to content

Commit 2b5313b

Browse files
committed
Rebase against master to use property converter interface
Signed-off-by: Vu Dinh <[email protected]>
1 parent eb8cfb7 commit 2b5313b

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

Diff for: pkg/controller/registry/resolver/resolver.go

+8-22
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func NewDefaultSatResolver(rcp cache.SourceProvider, catsrcLister v1alpha1lister
3535
return &SatResolver{
3636
cache: cache.New(rcp, cache.WithLogger(logger), cache.WithCatalogSourceLister(catsrcLister)),
3737
log: logger,
38-
pc: &predicateConverter{},
38+
pc: &predicateConverter{
39+
celEnv: constraints.NewCelEnvironment(),
40+
},
3941
}
4042
}
4143

@@ -346,26 +348,6 @@ func (r *SatResolver) getBundleInstallables(preferredNamespace string, bundleSta
346348
continue
347349
}
348350

349-
for _, prop := range bundle.Properties {
350-
if prop.Type != "olm.constraint" {
351-
continue
352-
}
353-
354-
var val constraints.Constraint
355-
if err := json.Unmarshal([]byte(prop.Value), &val); err != nil {
356-
errs = append(errs, err)
357-
continue
358-
}
359-
360-
pred, err := cache.CreateCelPredicate(r.celEnv, val.Cel.Rule, val.Message)
361-
if err != nil {
362-
errs = append(errs, err)
363-
continue
364-
}
365-
366-
dependencyPredicates = append(dependencyPredicates, pred)
367-
}
368-
369351
for _, d := range dependencyPredicates {
370352
sourcePredicate := cache.False()
371353
// Build a filter matching all (catalog,
@@ -757,7 +739,9 @@ func sortChannel(bundles []*cache.Entry) ([]*cache.Entry, error) {
757739
}
758740

759741
// predicateConverter configures olm.constraint value -> predicate conversion for the resolver.
760-
type predicateConverter struct{}
742+
type predicateConverter struct {
743+
celEnv *constraints.CelEnvironment
744+
}
761745

762746
// convertDependencyProperties converts all known constraint properties to predicates.
763747
func (pc *predicateConverter) convertDependencyProperties(properties []*api.Property) ([]cache.Predicate, error) {
@@ -834,6 +818,8 @@ func (pc *predicateConverter) convertConstraints(constraints ...constraints.Cons
834818
case constraint.None != nil:
835819
subs, perr := pc.convertConstraints(constraint.None.Constraints...)
836820
preds[i], err = cache.Not(subs...), perr
821+
case constraint.Cel != nil:
822+
preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.Message)
837823
default:
838824
// Unknown constraint types are handled by constraints.Parse(),
839825
// but parsed constraints may be empty.

Diff for: pkg/controller/registry/resolver/resolver_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -2482,8 +2482,10 @@ func TestSolveOperators_GenericConstraint(t *testing.T) {
24822482
cache: cache.New(cache.StaticSourceProvider{
24832483
catalog: tt.catalog,
24842484
}),
2485-
log: logrus.New(),
2486-
celEnv: constraints.NewCelEnvironment(),
2485+
log: logrus.New(),
2486+
pc: &predicateConverter{
2487+
celEnv: constraints.NewCelEnvironment(),
2488+
},
24872489
}
24882490

24892491
operators, err = satResolver.SolveOperators([]string{namespace}, nil, tt.subs)

0 commit comments

Comments
 (0)