From c4523a6d96483e84c384d8b951c747a54f6d68ac Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Fri, 2 Jun 2023 11:26:36 +0100 Subject: [PATCH] fixup! Makes `OLMVariableSource` responsible for fetching Signed-off-by: Mikalai Radchuk --- cmd/manager/main.go | 20 +++++++++----- internal/controllers/operator_controller.go | 5 ++-- .../controllers/operator_controller_test.go | 7 +++-- internal/resolution/resolver.go | 27 ------------------- internal/resolution/resolver_test.go | 24 ++++++++++------- 5 files changed, 32 insertions(+), 51 deletions(-) delete mode 100644 internal/resolution/resolver.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index b8a0be279..86246adc2 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -20,6 +20,7 @@ import ( "flag" "os" + "github.com/operator-framework/deppy/pkg/deppy/solver" rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1" "go.uber.org/zap/zapcore" "k8s.io/apimachinery/pkg/runtime" @@ -33,7 +34,6 @@ import ( catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1" operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" "github.com/operator-framework/operator-controller/internal/controllers" - "github.com/operator-framework/operator-controller/internal/resolution" "github.com/operator-framework/operator-controller/internal/resolution/entitysources" "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm" ) @@ -94,13 +94,19 @@ func main() { os.Exit(1) } + solver, err := solver.NewDeppySolver( + entitysources.NewCatalogdEntitySource(mgr.GetClient()), + olm.NewOLMVariableSource(mgr.GetClient()), + ) + if err != nil { + setupLog.Error(err, "unable create a solver") + os.Exit(1) + } + if err = (&controllers.OperatorReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - Resolver: resolution.NewOperatorResolver( - entitysources.NewCatalogdEntitySource(mgr.GetClient()), - olm.NewOLMVariableSource(mgr.GetClient()), - ), + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + Resolver: solver, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Operator") os.Exit(1) diff --git a/internal/controllers/operator_controller.go b/internal/controllers/operator_controller.go index a6cce9ecf..c1cb5f595 100644 --- a/internal/controllers/operator_controller.go +++ b/internal/controllers/operator_controller.go @@ -36,7 +36,6 @@ import ( operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" "github.com/operator-framework/operator-controller/internal/controllers/validators" - "github.com/operator-framework/operator-controller/internal/resolution" "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundles_and_dependencies" "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity" ) @@ -45,7 +44,7 @@ import ( type OperatorReconciler struct { client.Client Scheme *runtime.Scheme - Resolver *resolution.OperatorResolver + Resolver *solver.DeppySolver } //+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 return ctrl.Result{}, nil } // run resolution - solution, err := r.Resolver.Resolve(ctx) + solution, err := r.Resolver.Solve(ctx) if err != nil { op.Status.InstalledBundleResource = "" setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted as resolution failed", op.GetGeneration()) diff --git a/internal/controllers/operator_controller_test.go b/internal/controllers/operator_controller_test.go index 2db42c20f..67fdd615c 100644 --- a/internal/controllers/operator_controller_test.go +++ b/internal/controllers/operator_controller_test.go @@ -8,6 +8,7 @@ import ( . "github.com/onsi/gomega" "github.com/operator-framework/deppy/pkg/deppy" "github.com/operator-framework/deppy/pkg/deppy/input" + "github.com/operator-framework/deppy/pkg/deppy/solver" rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1" apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -21,7 +22,6 @@ import ( operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" "github.com/operator-framework/operator-controller/internal/conditionsets" "github.com/operator-framework/operator-controller/internal/controllers" - "github.com/operator-framework/operator-controller/internal/resolution" "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm" ) @@ -32,9 +32,8 @@ var _ = Describe("Operator Controller Test", func() { ) BeforeEach(func() { ctx = context.Background() - variableSource := olm.NewOLMVariableSource(cl) - solver := resolution.NewOperatorResolver(testEntitySource, variableSource) - + solver, err := solver.NewDeppySolver(testEntitySource, olm.NewOLMVariableSource(cl)) + Expect(err).NotTo(HaveOccurred()) reconciler = &controllers.OperatorReconciler{ Client: cl, Scheme: sch, diff --git a/internal/resolution/resolver.go b/internal/resolution/resolver.go deleted file mode 100644 index e69d42ec0..000000000 --- a/internal/resolution/resolver.go +++ /dev/null @@ -1,27 +0,0 @@ -package resolution - -import ( - "context" - - "github.com/operator-framework/deppy/pkg/deppy/input" - "github.com/operator-framework/deppy/pkg/deppy/solver" -) - -type OperatorResolver struct { - solver *solver.DeppySolver -} - -func NewOperatorResolver(entitySource input.EntitySource, variableSource input.VariableSource) *OperatorResolver { - deppySolver, err := solver.NewDeppySolver(entitySource, variableSource) - if err != nil { - // TODO: Clean up - // NewDeppySolver never returns an error: https://github.com/operator-framework/deppy/pull/98 - panic(err) - } - - return &OperatorResolver{solver: deppySolver} -} - -func (o *OperatorResolver) Resolve(ctx context.Context) (*solver.Solution, error) { - return o.solver.Solve(ctx) -} diff --git a/internal/resolution/resolver_test.go b/internal/resolution/resolver_test.go index 0126d8185..166eff777 100644 --- a/internal/resolution/resolver_test.go +++ b/internal/resolution/resolver_test.go @@ -9,13 +9,13 @@ import ( . "github.com/onsi/gomega" "github.com/operator-framework/deppy/pkg/deppy" "github.com/operator-framework/deppy/pkg/deppy/input" + "github.com/operator-framework/deppy/pkg/deppy/solver" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" "github.com/operator-framework/operator-controller/api/v1alpha1" - "github.com/operator-framework/operator-controller/internal/resolution" "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm" ) @@ -76,8 +76,9 @@ var _ = Describe("OperatorResolver", func() { client := FakeClient(resources...) entitySource := input.NewCacheQuerier(testEntityCache) variableSource := olm.NewOLMVariableSource(client) - resolver := resolution.NewOperatorResolver(entitySource, variableSource) - solution, err := resolver.Resolve(context.Background()) + resolver, err := solver.NewDeppySolver(entitySource, variableSource) + Expect(err).ToNot(HaveOccurred()) + solution, err := resolver.Solve(context.Background()) Expect(err).ToNot(HaveOccurred()) // 2 * required package variables + 2 * bundle variables Expect(solution.SelectedVariables()).To(HaveLen(4)) @@ -96,8 +97,9 @@ var _ = Describe("OperatorResolver", func() { client := FakeClient(resources...) entitySource := input.NewCacheQuerier(testEntityCache) variableSource := olm.NewOLMVariableSource(client) - resolver := resolution.NewOperatorResolver(entitySource, variableSource) - solution, err := resolver.Resolve(context.Background()) + resolver, err := solver.NewDeppySolver(entitySource, variableSource) + Expect(err).ToNot(HaveOccurred()) + solution, err := resolver.Solve(context.Background()) Expect(err).ToNot(HaveOccurred()) Expect(solution.SelectedVariables()).To(HaveLen(0)) }) @@ -114,8 +116,9 @@ var _ = Describe("OperatorResolver", func() { client := FakeClient(resource) entitySource := FailEntitySource{} variableSource := olm.NewOLMVariableSource(client) - resolver := resolution.NewOperatorResolver(entitySource, variableSource) - solution, err := resolver.Resolve(context.Background()) + resolver, err := solver.NewDeppySolver(entitySource, variableSource) + Expect(err).ToNot(HaveOccurred()) + solution, err := resolver.Solve(context.Background()) Expect(solution).To(BeNil()) Expect(err).To(HaveOccurred()) }) @@ -124,10 +127,11 @@ var _ = Describe("OperatorResolver", func() { client := NewFailClientWithError(fmt.Errorf("something bad happened")) entitySource := input.NewCacheQuerier(testEntityCache) variableSource := olm.NewOLMVariableSource(client) - resolver := resolution.NewOperatorResolver(entitySource, variableSource) - solution, err := resolver.Resolve(context.Background()) + resolver, err := solver.NewDeppySolver(entitySource, variableSource) + Expect(err).ToNot(HaveOccurred()) + solution, err := resolver.Solve(context.Background()) Expect(solution).To(BeNil()) - Expect(err).To(Equal(fmt.Errorf("something bad happened"))) + Expect(err).To(HaveOccurred()) }) })