@@ -5,59 +5,32 @@ import (
5
5
"fmt"
6
6
"sort"
7
7
8
+ "k8s.io/apimachinery/pkg/util/sets"
9
+
8
10
"github.com/operator-framework/deppy/pkg/deppy"
9
11
"github.com/operator-framework/deppy/pkg/deppy/input"
10
- "k8s.io/apimachinery/pkg/util/sets"
11
12
12
13
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
13
14
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
14
15
catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
15
16
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
16
17
)
17
18
18
- var _ input.VariableSource = & BundlesAndDepsVariableSource {}
19
-
20
- type BundlesAndDepsVariableSource struct {
21
- catalogClient BundleProvider
22
- variableSources []input.VariableSource
23
- }
24
-
25
- func NewBundlesAndDepsVariableSource (catalogClient BundleProvider , inputVariableSources ... input.VariableSource ) * BundlesAndDepsVariableSource {
26
- return & BundlesAndDepsVariableSource {
27
- catalogClient : catalogClient ,
28
- variableSources : inputVariableSources ,
29
- }
30
- }
31
-
32
- func (b * BundlesAndDepsVariableSource ) GetVariables (ctx context.Context ) ([]deppy.Variable , error ) {
33
- var variables []deppy.Variable
34
-
35
- // extract required package variables
36
- for _ , variableSource := range b .variableSources {
37
- inputVariables , err := variableSource .GetVariables (ctx )
38
- if err != nil {
39
- return nil , err
40
- }
41
- variables = append (variables , inputVariables ... )
42
- }
43
-
44
- // create bundle queue for dependency resolution
19
+ func MakeBundleVariables (
20
+ allBundles []* catalogmetadata.Bundle ,
21
+ requiredPackages []* olmvariables.RequiredPackageVariable ,
22
+ installedPackages []* olmvariables.InstalledPackageVariable ,
23
+ ) ([]* olmvariables.BundleVariable , error ) {
45
24
var bundleQueue []* catalogmetadata.Bundle
46
- for _ , variable := range variables {
47
- switch v := variable .(type ) {
48
- case * olmvariables.RequiredPackageVariable :
49
- bundleQueue = append (bundleQueue , v .Bundles ()... )
50
- case * olmvariables.InstalledPackageVariable :
51
- bundleQueue = append (bundleQueue , v .Bundles ()... )
52
- }
25
+ for _ , variable := range requiredPackages {
26
+ bundleQueue = append (bundleQueue , variable .Bundles ()... )
53
27
}
54
-
55
- allBundles , err := b .catalogClient .Bundles (ctx )
56
- if err != nil {
57
- return nil , err
28
+ for _ , variable := range installedPackages {
29
+ bundleQueue = append (bundleQueue , variable .Bundles ()... )
58
30
}
59
31
60
32
// build bundle and dependency variables
33
+ var result []* olmvariables.BundleVariable
61
34
visited := sets.Set [deppy.Identifier ]{}
62
35
for len (bundleQueue ) > 0 {
63
36
// pop head of queue
@@ -73,7 +46,7 @@ func (b *BundlesAndDepsVariableSource) GetVariables(ctx context.Context) ([]depp
73
46
visited .Insert (id )
74
47
75
48
// get bundle dependencies
76
- dependencies , err := b . filterBundleDependencies (allBundles , head )
49
+ dependencies , err := filterBundleDependencies (allBundles , head )
77
50
if err != nil {
78
51
return nil , fmt .Errorf ("could not determine dependencies for bundle with id '%s': %w" , id , err )
79
52
}
@@ -82,21 +55,23 @@ func (b *BundlesAndDepsVariableSource) GetVariables(ctx context.Context) ([]depp
82
55
bundleQueue = append (bundleQueue , dependencies ... )
83
56
84
57
// create variable
85
- variables = append (variables , olmvariables .NewBundleVariable (head , dependencies ))
58
+ result = append (result , olmvariables .NewBundleVariable (head , dependencies ))
86
59
}
87
60
88
- return variables , nil
61
+ return result , nil
89
62
}
90
63
91
- func ( b * BundlesAndDepsVariableSource ) filterBundleDependencies (allBundles []* catalogmetadata.Bundle , bundle * catalogmetadata.Bundle ) ([]* catalogmetadata.Bundle , error ) {
64
+ func filterBundleDependencies (allBundles []* catalogmetadata.Bundle , bundle * catalogmetadata.Bundle ) ([]* catalogmetadata.Bundle , error ) {
92
65
var dependencies []* catalogmetadata.Bundle
93
66
added := sets.Set [deppy.Identifier ]{}
94
67
95
68
// gather required package dependencies
96
- // todo(perdasilva): disambiguate between not found and actual errors
97
69
requiredPackages , _ := bundle .RequiredPackages ()
98
70
for _ , requiredPackage := range requiredPackages {
99
- packageDependencyBundles := catalogfilter .Filter (allBundles , catalogfilter .And (catalogfilter .WithPackageName (requiredPackage .PackageName ), catalogfilter .InBlangSemverRange (requiredPackage .SemverRange )))
71
+ packageDependencyBundles := catalogfilter .Filter (allBundles , catalogfilter .And (
72
+ catalogfilter .WithPackageName (requiredPackage .PackageName ),
73
+ catalogfilter .InBlangSemverRange (requiredPackage .SemverRange ),
74
+ ))
100
75
if len (packageDependencyBundles ) == 0 {
101
76
return nil , fmt .Errorf ("could not find package dependencies for bundle '%s'" , bundle .Name )
102
77
}
@@ -117,3 +92,53 @@ func (b *BundlesAndDepsVariableSource) filterBundleDependencies(allBundles []*ca
117
92
118
93
return dependencies , nil
119
94
}
95
+
96
+ type BundlesAndDepsVariableSource struct {
97
+ catalogClient BundleProvider
98
+ variableSources []input.VariableSource
99
+ }
100
+
101
+ func NewBundlesAndDepsVariableSource (catalogClient BundleProvider , inputVariableSources ... input.VariableSource ) * BundlesAndDepsVariableSource {
102
+ return & BundlesAndDepsVariableSource {
103
+ catalogClient : catalogClient ,
104
+ variableSources : inputVariableSources ,
105
+ }
106
+ }
107
+
108
+ func (b * BundlesAndDepsVariableSource ) GetVariables (ctx context.Context ) ([]deppy.Variable , error ) {
109
+ variables := []deppy.Variable {}
110
+
111
+ for _ , variableSource := range b .variableSources {
112
+ inputVariables , err := variableSource .GetVariables (ctx )
113
+ if err != nil {
114
+ return nil , err
115
+ }
116
+ variables = append (variables , inputVariables ... )
117
+ }
118
+
119
+ allBundles , err := b .catalogClient .Bundles (ctx )
120
+ if err != nil {
121
+ return nil , err
122
+ }
123
+
124
+ requiredPackages := []* olmvariables.RequiredPackageVariable {}
125
+ installedPackages := []* olmvariables.InstalledPackageVariable {}
126
+ for _ , variable := range variables {
127
+ switch v := variable .(type ) {
128
+ case * olmvariables.RequiredPackageVariable :
129
+ requiredPackages = append (requiredPackages , v )
130
+ case * olmvariables.InstalledPackageVariable :
131
+ installedPackages = append (installedPackages , v )
132
+ }
133
+ }
134
+
135
+ bundles , err := MakeBundleVariables (allBundles , requiredPackages , installedPackages )
136
+ if err != nil {
137
+ return nil , err
138
+ }
139
+
140
+ for _ , v := range bundles {
141
+ variables = append (variables , v )
142
+ }
143
+ return variables , nil
144
+ }
0 commit comments