Skip to content

Commit

Permalink
Bump Deppy to v0.3.0 (#566)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola authored Dec 13, 2023
1 parent 8d74ce8 commit 8d428a5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
8 changes: 7 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,17 @@ func main() {
cl := mgr.GetClient()
catalogClient := catalogclient.New(cl, cache.NewFilesystemCache(cachePath, &http.Client{Timeout: 10 * time.Second}))

resolver, err := solver.New()
if err != nil {
setupLog.Error(err, "unable to create a solver")
os.Exit(1)
}

if err = (&controllers.OperatorReconciler{
Client: cl,
BundleProvider: catalogClient,
Scheme: mgr.GetScheme(),
Resolver: solver.NewDeppySolver(),
Resolver: resolver,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Operator")
os.Exit(1)
Expand Down
11 changes: 7 additions & 4 deletions cmd/resolutioncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
},
})

resolver := solver.NewDeppySolver()
resolver, err := solver.New()
if err != nil {
return err
}

cl := clientBuilder.Build()
catalogClient := newIndexRefClient(indexRef)
Expand Down Expand Up @@ -174,7 +177,7 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
return nil
}

func resolve(resolver *solver.DeppySolver, variables []deppy.Variable, packageName string) (string, error) {
func resolve(resolver *solver.Solver, variables []deppy.Variable, packageName string) (string, error) {
solution, err := resolver.Solve(variables)
if err != nil {
return "", err
Expand All @@ -189,8 +192,8 @@ func resolve(resolver *solver.DeppySolver, variables []deppy.Variable, packageNa
return bundle.Image, nil
}

func bundleFromSolution(solution *solver.Solution, packageName string) (*catalogmetadata.Bundle, error) {
for _, variable := range solution.SelectedVariables() {
func bundleFromSolution(selection []deppy.Variable, packageName string) (*catalogmetadata.Bundle, error) {
for _, variable := range selection {
switch v := variable.(type) {
case *olmvariables.BundleVariable:
bundlePkgName := v.Bundle().Package
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-logr/logr v1.3.0
github.com/google/go-cmp v0.6.0
github.com/operator-framework/catalogd v0.10.0
github.com/operator-framework/deppy v0.2.0
github.com/operator-framework/deppy v0.3.0
github.com/operator-framework/operator-registry v1.33.0
github.com/operator-framework/rukpak v0.16.0
github.com/spf13/pflag v1.0.5
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo/v2 v2.13.1 h1:LNGfMbR2OVGBfXjvRZIZ2YCTQdGKtPLvuI1rMCCj3OU=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
Expand All @@ -273,8 +273,8 @@ github.com/operator-framework/api v0.19.0 h1:QU1CTJU+CufoeneA5rsNlP/uP96s8vDHWUY
github.com/operator-framework/api v0.19.0/go.mod h1:SCCslqke6AVOJ5JM+NqNE1CHuAgJLScsL66pnPaSMXs=
github.com/operator-framework/catalogd v0.10.0 h1:T207IQfQCcd3f31bDPCgfJcwEvmaPGV8BotqIzIvnRo=
github.com/operator-framework/catalogd v0.10.0/go.mod h1:xIeR5f/Spr5rHnLp0yOi0AYetWcHvBAx9n+K3S/va2A=
github.com/operator-framework/deppy v0.2.0 h1:BYdCAKli+ofFdnHPkpUKI9DygHL2A32CaDbEJk4jz6U=
github.com/operator-framework/deppy v0.2.0/go.mod h1:3blHej0Hj0M17Ru2q3QrhN9OwB5/MMmFkWUmiInqs6A=
github.com/operator-framework/deppy v0.3.0 h1:W8wpF0ehcTAdH2WfMyqMPI5Ja0Qv8M5FMO5cXgJvEQ8=
github.com/operator-framework/deppy v0.3.0/go.mod h1:EHDxZz8fKGvuymCng3G/Ou7wuX14GaLr0cmf2u29Oog=
github.com/operator-framework/operator-registry v1.33.0 h1:rFvYf6vLdXSUhoePhg8w1S5FHgyFraiNLXDwl47epck=
github.com/operator-framework/operator-registry v1.33.0/go.mod h1:1V/m2m7iH/o5ROEuMxWa/yhj4ExaPGT6V/ncGS+m6Js=
github.com/operator-framework/rukpak v0.16.0 h1:d6iI7lYJbR5fHqw3vnAudB5SevAQ2dnQI7C6iOZyXJU=
Expand Down
18 changes: 5 additions & 13 deletions internal/controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type OperatorReconciler struct {
client.Client
BundleProvider BundleProvider
Scheme *runtime.Scheme
Resolver *solver.DeppySolver
Resolver *solver.Solver
}

//+kubebuilder:rbac:groups=operators.operatorframework.io,resources=operators,verbs=get;list;watch
Expand Down Expand Up @@ -144,7 +144,7 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
}

// run resolution
solution, err := r.Resolver.Solve(vars)
selection, err := r.Resolver.Solve(vars)
if err != nil {
op.Status.InstalledBundleResource = ""
setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted as resolution failed", op.GetGeneration())
Expand All @@ -153,17 +153,9 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
return ctrl.Result{}, err
}

if err := solution.Error(); err != nil {
op.Status.InstalledBundleResource = ""
setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted as resolution is unsatisfiable", op.GetGeneration())
op.Status.ResolvedBundleResource = ""
setResolvedStatusConditionFailed(&op.Status.Conditions, err.Error(), op.GetGeneration())
return ctrl.Result{}, err
}

// lookup the bundle in the solution that corresponds to the
// Operator's desired package name.
bundle, err := r.bundleFromSolution(solution, op.Spec.PackageName)
bundle, err := r.bundleFromSolution(selection, op.Spec.PackageName)
if err != nil {
op.Status.InstalledBundleResource = ""
setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted as resolution failed", op.GetGeneration())
Expand Down Expand Up @@ -275,8 +267,8 @@ func mapBDStatusToInstalledCondition(existingTypedBundleDeployment *rukpakv1alph
}
}

func (r *OperatorReconciler) bundleFromSolution(solution *solver.Solution, packageName string) (*catalogmetadata.Bundle, error) {
for _, variable := range solution.SelectedVariables() {
func (r *OperatorReconciler) bundleFromSolution(selection []deppy.Variable, packageName string) (*catalogmetadata.Bundle, error) {
for _, variable := range selection {
switch v := variable.(type) {
case *olmvariables.BundleVariable:
bundlePkgName := v.Bundle().Package
Expand Down
5 changes: 4 additions & 1 deletion internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ func newClient(t *testing.T) client.Client {
}

func newClientAndReconciler(t *testing.T) (client.Client, *controllers.OperatorReconciler) {
resolver, err := solver.New()
require.NoError(t, err)

cl := newClient(t)
fakeCatalogClient := testutil.NewFakeCatalogClient(testBundleList)
reconciler := &controllers.OperatorReconciler{
Client: cl,
BundleProvider: &fakeCatalogClient,
Scheme: sch,
Resolver: solver.NewDeppySolver(),
Resolver: resolver,
}
return cl, reconciler
}
Expand Down

0 comments on commit 8d428a5

Please sign in to comment.