-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathoperator.go
55 lines (45 loc) · 1.53 KB
/
operator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package variablesources
import (
"context"
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/deppy/pkg/deppy"
"github.com/operator-framework/deppy/pkg/deppy/input"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var _ input.VariableSource = &OperatorVariableSource{}
type OperatorVariableSource struct {
client client.Client
catalogClient BundleProvider
inputVariableSource input.VariableSource
}
func NewOperatorVariableSource(cl client.Client, catalogClient BundleProvider, inputVariableSource input.VariableSource) *OperatorVariableSource {
return &OperatorVariableSource{
client: cl,
catalogClient: catalogClient,
inputVariableSource: inputVariableSource,
}
}
func (o *OperatorVariableSource) GetVariables(ctx context.Context) ([]deppy.Variable, error) {
variableSources := SliceVariableSource{}
if o.inputVariableSource != nil {
variableSources = append(variableSources, o.inputVariableSource)
}
operatorList := operatorsv1alpha1.OperatorList{}
if err := o.client.List(ctx, &operatorList); err != nil {
return nil, err
}
// build required package variable sources
for _, operator := range operatorList.Items {
rps, err := NewRequiredPackageVariableSource(
o.catalogClient,
operator.Spec.PackageName,
InVersionRange(operator.Spec.Version),
InChannel(operator.Spec.Channel),
)
if err != nil {
return nil, err
}
variableSources = append(variableSources, rps)
}
return variableSources.GetVariables(ctx)
}