Skip to content

Commit

Permalink
fixup! Makes OLMVariableSource responsible for fetching
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola committed Jun 2, 2023
1 parent 631110f commit c4523a6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 51 deletions.
20 changes: 13 additions & 7 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions internal/controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand Down
7 changes: 3 additions & 4 deletions internal/controllers/operator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand All @@ -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,
Expand Down
27 changes: 0 additions & 27 deletions internal/resolution/resolver.go

This file was deleted.

24 changes: 14 additions & 10 deletions internal/resolution/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
Expand All @@ -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))
})
Expand All @@ -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())
})
Expand All @@ -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())
})
})

Expand Down

0 comments on commit c4523a6

Please sign in to comment.