@@ -19,19 +19,15 @@ import (
19
19
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
20
20
)
21
21
22
- type OperatorResolver interface {
23
- SolveOperators (csvs []* v1alpha1.ClusterServiceVersion , add map [cache.OperatorSourceInfo ]struct {}) (cache.OperatorSet , error )
24
- }
25
-
26
- type SatResolver struct {
22
+ type Resolver struct {
27
23
cache cache.OperatorCacheProvider
28
24
log logrus.FieldLogger
29
25
pc * predicateConverter
30
26
systemConstraintsProvider solver.ConstraintProvider
31
27
}
32
28
33
- func NewDefaultSatResolver (rcp cache.SourceProvider , sourcePriorityProvider cache.SourcePriorityProvider , logger logrus.FieldLogger ) * SatResolver {
34
- return & SatResolver {
29
+ func NewDefaultResolver (rcp cache.SourceProvider , sourcePriorityProvider cache.SourcePriorityProvider , logger logrus.FieldLogger ) * Resolver {
30
+ return & Resolver {
35
31
cache : cache .New (rcp , cache .WithLogger (logger ), cache .WithSourcePriorityProvider (sourcePriorityProvider )),
36
32
log : logger ,
37
33
pc : & predicateConverter {
@@ -50,7 +46,7 @@ func (w *debugWriter) Write(b []byte) (int, error) {
50
46
return n , nil
51
47
}
52
48
53
- func (r * SatResolver ) SolveOperators (namespaces []string , subs []* v1alpha1.Subscription ) (cache.OperatorSet , error ) {
49
+ func (r * Resolver ) Resolve (namespaces []string , subs []* v1alpha1.Subscription ) ([] * cache.Entry , error ) {
54
50
var errs []error
55
51
56
52
variables := make (map [solver.Identifier ]solver.Variable )
@@ -146,7 +142,7 @@ func (r *SatResolver) SolveOperators(namespaces []string, subs []*v1alpha1.Subsc
146
142
}
147
143
}
148
144
149
- operators := make ( map [ string ]* cache.Entry )
145
+ var operators [ ]* cache.Entry
150
146
for _ , variableOperator := range operatorVariables {
151
147
csvName , channel , catalog , err := variableOperator .BundleSourceInfo ()
152
148
if err != nil {
@@ -190,7 +186,7 @@ func (r *SatResolver) SolveOperators(namespaces []string, subs []*v1alpha1.Subsc
190
186
op .SourceInfo .StartingCSV = csvName
191
187
}
192
188
193
- operators [ csvName ] = op
189
+ operators = append ( operators , op )
194
190
}
195
191
196
192
if len (errs ) > 0 {
@@ -202,7 +198,7 @@ func (r *SatResolver) SolveOperators(namespaces []string, subs []*v1alpha1.Subsc
202
198
203
199
// newBundleVariableFromEntry converts an entry into a bundle variable with
204
200
// system constraints applied, if they are defined for the entry
205
- func (r * SatResolver ) newBundleVariableFromEntry (entry * cache.Entry ) (* BundleVariable , error ) {
201
+ func (r * Resolver ) newBundleVariableFromEntry (entry * cache.Entry ) (* BundleVariable , error ) {
206
202
bundleInstalleble , err := NewBundleVariableFromOperator (entry )
207
203
if err != nil {
208
204
return nil , err
@@ -219,7 +215,7 @@ func (r *SatResolver) newBundleVariableFromEntry(entry *cache.Entry) (*BundleVar
219
215
return & bundleInstalleble , nil
220
216
}
221
217
222
- func (r * SatResolver ) getSubscriptionVariables (sub * v1alpha1.Subscription , current * cache.Entry , namespacedCache cache.MultiCatalogOperatorFinder , visited map [* cache.Entry ]* BundleVariable ) (map [solver.Identifier ]solver.Variable , error ) {
218
+ func (r * Resolver ) getSubscriptionVariables (sub * v1alpha1.Subscription , current * cache.Entry , namespacedCache cache.MultiCatalogOperatorFinder , visited map [* cache.Entry ]* BundleVariable ) (map [solver.Identifier ]solver.Variable , error ) {
223
219
var cachePredicates , channelPredicates []cache.Predicate
224
220
variables := make (map [solver.Identifier ]solver.Variable )
225
221
@@ -353,7 +349,7 @@ func (r *SatResolver) getSubscriptionVariables(sub *v1alpha1.Subscription, curre
353
349
return variables , nil
354
350
}
355
351
356
- func (r * SatResolver ) getBundleVariables (preferredNamespace string , bundleStack []* cache.Entry , namespacedCache cache.MultiCatalogOperatorFinder , visited map [* cache.Entry ]* BundleVariable ) (map [solver.Identifier ]struct {}, map [solver.Identifier ]* BundleVariable , error ) {
352
+ func (r * Resolver ) getBundleVariables (preferredNamespace string , bundleStack []* cache.Entry , namespacedCache cache.MultiCatalogOperatorFinder , visited map [* cache.Entry ]* BundleVariable ) (map [solver.Identifier ]struct {}, map [solver.Identifier ]* BundleVariable , error ) {
357
353
errs := make ([]error , 0 )
358
354
variables := make (map [solver.Identifier ]* BundleVariable ) // all variables, including dependencies
359
355
@@ -461,7 +457,7 @@ func (r *SatResolver) getBundleVariables(preferredNamespace string, bundleStack
461
457
return ids , variables , nil
462
458
}
463
459
464
- func (r * SatResolver ) addInvariants (namespacedCache cache.MultiCatalogOperatorFinder , variables map [solver.Identifier ]solver.Variable ) {
460
+ func (r * Resolver ) addInvariants (namespacedCache cache.MultiCatalogOperatorFinder , variables map [solver.Identifier ]solver.Variable ) {
465
461
// no two operators may provide the same GVK or Package in a namespace
466
462
gvkConflictToVariable := make (map [opregistry.GVKProperty ][]solver.Identifier )
467
463
packageConflictToVariable := make (map [string ][]solver.Identifier )
@@ -518,7 +514,7 @@ func (r *SatResolver) addInvariants(namespacedCache cache.MultiCatalogOperatorFi
518
514
}
519
515
}
520
516
521
- func (r * SatResolver ) sortBundles (bundles []* cache.Entry ) ([]* cache.Entry , error ) {
517
+ func (r * Resolver ) sortBundles (bundles []* cache.Entry ) ([]* cache.Entry , error ) {
522
518
// assume bundles have been passed in sorted by catalog already
523
519
catalogOrder := make ([]cache.SourceKey , 0 )
524
520
@@ -814,8 +810,8 @@ func predicateForRequiredLabelProperty(value string) (cache.Predicate, error) {
814
810
return cache .LabelPredicate (label .Label ), nil
815
811
}
816
812
817
- func providedAPIsToProperties (apis cache.APISet ) (out []* api.Property , err error ) {
818
- out = make ( []* api.Property , 0 )
813
+ func providedAPIsToProperties (apis cache.APISet ) ([]* api.Property , error ) {
814
+ var out []* api.Property
819
815
for a := range apis {
820
816
val , err := json .Marshal (opregistry.GVKProperty {
821
817
Group : a .Group ,
@@ -830,17 +826,14 @@ func providedAPIsToProperties(apis cache.APISet) (out []*api.Property, err error
830
826
Value : string (val ),
831
827
})
832
828
}
833
- if len (out ) > 0 {
834
- return
835
- }
836
- return nil , nil
829
+ sort . Slice (out , func ( i , j int ) bool {
830
+ return out [ i ]. Value < out [ j ]. Value
831
+ })
832
+ return out , nil
837
833
}
838
834
839
- func requiredAPIsToProperties (apis cache.APISet ) (out []* api.Property , err error ) {
840
- if len (apis ) == 0 {
841
- return
842
- }
843
- out = make ([]* api.Property , 0 )
835
+ func requiredAPIsToProperties (apis cache.APISet ) ([]* api.Property , error ) {
836
+ var out []* api.Property
844
837
for a := range apis {
845
838
val , err := json .Marshal (struct {
846
839
Group string `json:"group"`
@@ -859,8 +852,8 @@ func requiredAPIsToProperties(apis cache.APISet) (out []*api.Property, err error
859
852
Value : string (val ),
860
853
})
861
854
}
862
- if len (out ) > 0 {
863
- return
864
- }
865
- return nil , nil
855
+ sort . Slice (out , func ( i , j int ) bool {
856
+ return out [ i ]. Value < out [ j ]. Value
857
+ })
858
+ return out , nil
866
859
}
0 commit comments