From 7fb8b6decfe6e79fc94230271ca11f1e2c43cf73 Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Fri, 10 Nov 2023 14:37:12 +0000 Subject: [PATCH] Resolve Deppy error check todo We already have a version which contains the fix and can revert to a simpler check. Signed-off-by: Mikalai Radchuk --- internal/controllers/operator_controller.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/controllers/operator_controller.go b/internal/controllers/operator_controller.go index 1fd219c0d..728ffbec3 100644 --- a/internal/controllers/operator_controller.go +++ b/internal/controllers/operator_controller.go @@ -138,19 +138,13 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha return ctrl.Result{}, err } - // TODO: Checking for unsat is awkward using the current version of deppy. - // This awkwardness has been fixed in an unreleased version of deppy. - // When there is a new minor release of deppy, we can revisit this and - // simplify this to a normal error check. - // See https://github.com/operator-framework/deppy/issues/139. - unsat := deppy.NotSatisfiable{} - if ok := errors.As(solution.Error(), &unsat); ok && len(unsat) > 0 { + 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 = "" - msg := prettyUnsatMessage(unsat) + msg := prettyUnsatMessage(err) setResolvedStatusConditionFailed(&op.Status.Conditions, msg, op.GetGeneration()) - return ctrl.Result{}, unsat + return ctrl.Result{}, err } // lookup the bundle in the solution that corresponds to the @@ -472,7 +466,14 @@ func operatorRequestsForCatalog(c client.Reader, logger logr.Logger) handler.Map // and joins them with a semicolon (rather than a comma, which the unsat.Error() // function does). This function also has the side effect of sorting the items // in the unsat slice. -func prettyUnsatMessage(unsat deppy.NotSatisfiable) string { +func prettyUnsatMessage(err error) string { + unsat := deppy.NotSatisfiable{} + if !errors.As(err, &unsat) { + // This function is specifically for formatting deppy.NotSatisfiable. + // Just return default format if the error is something else. + return err.Error() + } + sort.Slice(unsat, func(i, j int) bool { return unsat[i].String() < unsat[j].String() })