Skip to content

Commit c4523a6

Browse files
author
Mikalai Radchuk
committed
fixup! Makes OLMVariableSource responsible for fetching
Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 631110f commit c4523a6

File tree

5 files changed

+32
-51
lines changed

5 files changed

+32
-51
lines changed

cmd/manager/main.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"flag"
2121
"os"
2222

23+
"github.com/operator-framework/deppy/pkg/deppy/solver"
2324
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
2425
"go.uber.org/zap/zapcore"
2526
"k8s.io/apimachinery/pkg/runtime"
@@ -33,7 +34,6 @@ import (
3334
catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1"
3435
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
3536
"github.com/operator-framework/operator-controller/internal/controllers"
36-
"github.com/operator-framework/operator-controller/internal/resolution"
3737
"github.com/operator-framework/operator-controller/internal/resolution/entitysources"
3838
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
3939
)
@@ -94,13 +94,19 @@ func main() {
9494
os.Exit(1)
9595
}
9696

97+
solver, err := solver.NewDeppySolver(
98+
entitysources.NewCatalogdEntitySource(mgr.GetClient()),
99+
olm.NewOLMVariableSource(mgr.GetClient()),
100+
)
101+
if err != nil {
102+
setupLog.Error(err, "unable create a solver")
103+
os.Exit(1)
104+
}
105+
97106
if err = (&controllers.OperatorReconciler{
98-
Client: mgr.GetClient(),
99-
Scheme: mgr.GetScheme(),
100-
Resolver: resolution.NewOperatorResolver(
101-
entitysources.NewCatalogdEntitySource(mgr.GetClient()),
102-
olm.NewOLMVariableSource(mgr.GetClient()),
103-
),
107+
Client: mgr.GetClient(),
108+
Scheme: mgr.GetScheme(),
109+
Resolver: solver,
104110
}).SetupWithManager(mgr); err != nil {
105111
setupLog.Error(err, "unable to create controller", "controller", "Operator")
106112
os.Exit(1)

internal/controllers/operator_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636

3737
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
3838
"github.com/operator-framework/operator-controller/internal/controllers/validators"
39-
"github.com/operator-framework/operator-controller/internal/resolution"
4039
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundles_and_dependencies"
4140
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
4241
)
@@ -45,7 +44,7 @@ import (
4544
type OperatorReconciler struct {
4645
client.Client
4746
Scheme *runtime.Scheme
48-
Resolver *resolution.OperatorResolver
47+
Resolver *solver.DeppySolver
4948
}
5049

5150
//+kubebuilder:rbac:groups=operators.operatorframework.io,resources=operators,verbs=get;list;watch
@@ -116,7 +115,7 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
116115
return ctrl.Result{}, nil
117116
}
118117
// run resolution
119-
solution, err := r.Resolver.Resolve(ctx)
118+
solution, err := r.Resolver.Solve(ctx)
120119
if err != nil {
121120
op.Status.InstalledBundleResource = ""
122121
setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted as resolution failed", op.GetGeneration())

internal/controllers/operator_controller_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
. "github.com/onsi/gomega"
99
"github.com/operator-framework/deppy/pkg/deppy"
1010
"github.com/operator-framework/deppy/pkg/deppy/input"
11+
"github.com/operator-framework/deppy/pkg/deppy/solver"
1112
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
1213
apimeta "k8s.io/apimachinery/pkg/api/meta"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -21,7 +22,6 @@ import (
2122
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
2223
"github.com/operator-framework/operator-controller/internal/conditionsets"
2324
"github.com/operator-framework/operator-controller/internal/controllers"
24-
"github.com/operator-framework/operator-controller/internal/resolution"
2525
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
2626
)
2727

@@ -32,9 +32,8 @@ var _ = Describe("Operator Controller Test", func() {
3232
)
3333
BeforeEach(func() {
3434
ctx = context.Background()
35-
variableSource := olm.NewOLMVariableSource(cl)
36-
solver := resolution.NewOperatorResolver(testEntitySource, variableSource)
37-
35+
solver, err := solver.NewDeppySolver(testEntitySource, olm.NewOLMVariableSource(cl))
36+
Expect(err).NotTo(HaveOccurred())
3837
reconciler = &controllers.OperatorReconciler{
3938
Client: cl,
4039
Scheme: sch,

internal/resolution/resolver.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

internal/resolution/resolver_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
. "github.com/onsi/gomega"
1010
"github.com/operator-framework/deppy/pkg/deppy"
1111
"github.com/operator-framework/deppy/pkg/deppy/input"
12+
"github.com/operator-framework/deppy/pkg/deppy/solver"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/apimachinery/pkg/runtime"
1415
"sigs.k8s.io/controller-runtime/pkg/client"
1516
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1617

1718
"github.com/operator-framework/operator-controller/api/v1alpha1"
18-
"github.com/operator-framework/operator-controller/internal/resolution"
1919
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
2020
)
2121

@@ -76,8 +76,9 @@ var _ = Describe("OperatorResolver", func() {
7676
client := FakeClient(resources...)
7777
entitySource := input.NewCacheQuerier(testEntityCache)
7878
variableSource := olm.NewOLMVariableSource(client)
79-
resolver := resolution.NewOperatorResolver(entitySource, variableSource)
80-
solution, err := resolver.Resolve(context.Background())
79+
resolver, err := solver.NewDeppySolver(entitySource, variableSource)
80+
Expect(err).ToNot(HaveOccurred())
81+
solution, err := resolver.Solve(context.Background())
8182
Expect(err).ToNot(HaveOccurred())
8283
// 2 * required package variables + 2 * bundle variables
8384
Expect(solution.SelectedVariables()).To(HaveLen(4))
@@ -96,8 +97,9 @@ var _ = Describe("OperatorResolver", func() {
9697
client := FakeClient(resources...)
9798
entitySource := input.NewCacheQuerier(testEntityCache)
9899
variableSource := olm.NewOLMVariableSource(client)
99-
resolver := resolution.NewOperatorResolver(entitySource, variableSource)
100-
solution, err := resolver.Resolve(context.Background())
100+
resolver, err := solver.NewDeppySolver(entitySource, variableSource)
101+
Expect(err).ToNot(HaveOccurred())
102+
solution, err := resolver.Solve(context.Background())
101103
Expect(err).ToNot(HaveOccurred())
102104
Expect(solution.SelectedVariables()).To(HaveLen(0))
103105
})
@@ -114,8 +116,9 @@ var _ = Describe("OperatorResolver", func() {
114116
client := FakeClient(resource)
115117
entitySource := FailEntitySource{}
116118
variableSource := olm.NewOLMVariableSource(client)
117-
resolver := resolution.NewOperatorResolver(entitySource, variableSource)
118-
solution, err := resolver.Resolve(context.Background())
119+
resolver, err := solver.NewDeppySolver(entitySource, variableSource)
120+
Expect(err).ToNot(HaveOccurred())
121+
solution, err := resolver.Solve(context.Background())
119122
Expect(solution).To(BeNil())
120123
Expect(err).To(HaveOccurred())
121124
})
@@ -124,10 +127,11 @@ var _ = Describe("OperatorResolver", func() {
124127
client := NewFailClientWithError(fmt.Errorf("something bad happened"))
125128
entitySource := input.NewCacheQuerier(testEntityCache)
126129
variableSource := olm.NewOLMVariableSource(client)
127-
resolver := resolution.NewOperatorResolver(entitySource, variableSource)
128-
solution, err := resolver.Resolve(context.Background())
130+
resolver, err := solver.NewDeppySolver(entitySource, variableSource)
131+
Expect(err).ToNot(HaveOccurred())
132+
solution, err := resolver.Solve(context.Background())
129133
Expect(solution).To(BeNil())
130-
Expect(err).To(Equal(fmt.Errorf("something bad happened")))
134+
Expect(err).To(HaveOccurred())
131135
})
132136
})
133137

0 commit comments

Comments
 (0)