@@ -3,10 +3,14 @@ package resolver
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "errors"
6
7
"fmt"
8
+ "os"
7
9
"sort"
8
10
"strings"
9
11
12
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/runtime_constraints"
13
+
10
14
"github.com/blang/semver/v4"
11
15
"github.com/sirupsen/logrus"
12
16
utilerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -20,25 +24,42 @@ import (
20
24
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
21
25
)
22
26
27
+ const (
28
+ runtimeConstraintsFilePath = "runtime_constraints.yaml"
29
+ )
30
+
23
31
type OperatorResolver interface {
24
32
SolveOperators (csvs []* v1alpha1.ClusterServiceVersion , subs []* v1alpha1.Subscription , add map [cache.OperatorSourceInfo ]struct {}) (cache.OperatorSet , error )
25
33
}
26
34
27
35
type SatResolver struct {
28
- cache cache.OperatorCacheProvider
29
- log logrus.FieldLogger
36
+ cache cache.OperatorCacheProvider
37
+ log logrus.FieldLogger
38
+ runtimeConstraintsProvider * runtime_constraints.RuntimeConstraintsProvider
30
39
}
31
40
32
41
func NewDefaultSatResolver (rcp cache.SourceProvider , catsrcLister v1alpha1listers.CatalogSourceLister , logger logrus.FieldLogger ) * SatResolver {
33
- // Get runtime constraints somehow
34
- runtimeConstraints := []cache.Predicate {
35
- // Only etcd can be installed on this system!
36
- cache .PkgPredicate ("etcd" ),
42
+
43
+ runtimeConstraintProvider , err := runtime_constraints .NewFromFile (runtimeConstraintsFilePath )
44
+ if err != nil && ! errors .Is (err , os .ErrNotExist ) {
45
+ if errors .Is (err , os .ErrNotExist ) {
46
+ logger .Warning ("No cluster runtime constraints file found" )
47
+ } else {
48
+ logger .Errorf ("Error creating runtime constraints from file: %s" , err )
49
+ panic (err )
50
+ }
37
51
}
38
52
53
+ // Two solutions:
54
+ // #1: Global cache filters
55
+ // globalFilters := cache.WithGlobalFilters(runtimeConstraintProvider.GetRuntimeConstraints()...)
56
+
39
57
return & SatResolver {
40
- cache : cache .New (rcp , cache .WithLogger (logger ), cache .WithCatalogSourceLister (catsrcLister ), cache . WithGlobalFilters ( runtimeConstraints ... ) ),
58
+ cache : cache .New (rcp , cache .WithLogger (logger ), cache .WithCatalogSourceLister (catsrcLister ) /*, globalFilters*/ ),
41
59
log : logger ,
60
+ // #2: apply constraints in addInvariants
61
+ runtimeConstraintsProvider : runtimeConstraintProvider , // uncomment when using option #2
62
+ // runtimeConstraintsProvider: nil // uncomment when using option #1
42
63
}
43
64
}
44
65
@@ -574,6 +595,16 @@ func (r *SatResolver) addInvariants(namespacedCache cache.MultiCatalogOperatorFi
574
595
}
575
596
packageConflictToInstallable [prop .PackageName ] = append (packageConflictToInstallable [prop .PackageName ], installable .Identifier ())
576
597
}
598
+
599
+ // apply runtime constraints to packages that aren't already installed
600
+ if ! catalog .Virtual () && r .runtimeConstraintsProvider != nil {
601
+ for _ , predicate := range r .runtimeConstraintsProvider .GetRuntimeConstraints () {
602
+ if ! predicate .Test (op ) {
603
+ bundleInstallable .AddRuntimeConstraintFailure (predicate .String ())
604
+ break
605
+ }
606
+ }
607
+ }
577
608
}
578
609
579
610
for gvk , is := range gvkConflictToInstallable {
0 commit comments