Skip to content

Commit 2105d1a

Browse files
authored
Remove prettyUnsatMessage (#547)
It was a workaround a Deppy issue. We no longer need it since Deppy fixed the issue. Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
1 parent a250a9b commit 2105d1a

File tree

3 files changed

+5
-37
lines changed

3 files changed

+5
-37
lines changed

internal/controllers/operator_controller.go

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ package controllers
1818

1919
import (
2020
"context"
21-
"errors"
2221
"fmt"
23-
"sort"
24-
"strings"
2522

2623
"github.com/go-logr/logr"
2724
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
28-
"github.com/operator-framework/deppy/pkg/deppy"
2925
"github.com/operator-framework/deppy/pkg/deppy/solver"
3026
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
3127
"k8s.io/apimachinery/pkg/api/equality"
@@ -142,8 +138,7 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
142138
op.Status.InstalledBundleResource = ""
143139
setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted as resolution is unsatisfiable", op.GetGeneration())
144140
op.Status.ResolvedBundleResource = ""
145-
msg := prettyUnsatMessage(err)
146-
setResolvedStatusConditionFailed(&op.Status.Conditions, msg, op.GetGeneration())
141+
setResolvedStatusConditionFailed(&op.Status.Conditions, err.Error(), op.GetGeneration())
147142
return ctrl.Result{}, err
148143
}
149144

@@ -456,30 +451,3 @@ func operatorRequestsForCatalog(c client.Reader, logger logr.Logger) handler.Map
456451
return requests
457452
}
458453
}
459-
460-
// TODO: This can be removed when operator controller bumps to a
461-
// version of deppy that contains a fix for this issue:
462-
// https://github.com/operator-framework/deppy/issues/142
463-
464-
// prettyUnsatMessage ensures that the unsat message is deterministic and
465-
// human-readable. It sorts the individual constraint strings lexicographically
466-
// and joins them with a semicolon (rather than a comma, which the unsat.Error()
467-
// function does). This function also has the side effect of sorting the items
468-
// in the unsat slice.
469-
func prettyUnsatMessage(err error) string {
470-
unsat := deppy.NotSatisfiable{}
471-
if !errors.As(err, &unsat) {
472-
// This function is specifically for formatting deppy.NotSatisfiable.
473-
// Just return default format if the error is something else.
474-
return err.Error()
475-
}
476-
477-
sort.Slice(unsat, func(i, j int) bool {
478-
return unsat[i].String() < unsat[j].String()
479-
})
480-
msgs := make([]string, 0, len(unsat))
481-
for _, c := range unsat {
482-
msgs = append(msgs, c.String())
483-
}
484-
return fmt.Sprintf("constraints not satisfiable: %s", strings.Join(msgs, "; "))
485-
}

internal/controllers/operator_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ func TestOperatorUpgrade(t *testing.T) {
11281128
assert.Equal(t, metav1.ConditionFalse, cond.Status)
11291129
assert.Equal(t, operatorsv1alpha1.ReasonResolutionFailed, cond.Reason)
11301130
assert.Contains(t, cond.Message, "constraints not satisfiable")
1131-
assert.Contains(t, cond.Message, "installed package prometheus requires at least one of fake-catalog-prometheus-operatorhub/prometheus/beta/1.2.0, fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.1, fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.0;")
1131+
assert.Regexp(t, "installed package prometheus requires at least one of fake-catalog-prometheus-operatorhub/prometheus/beta/1.2.0, fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.1, fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.0$", cond.Message)
11321132

11331133
// Valid update skipping one version
11341134
operator.Spec.Version = "1.2.0"
@@ -1221,7 +1221,7 @@ func TestOperatorUpgrade(t *testing.T) {
12211221
assert.Equal(t, metav1.ConditionFalse, cond.Status)
12221222
assert.Equal(t, operatorsv1alpha1.ReasonResolutionFailed, cond.Reason)
12231223
assert.Contains(t, cond.Message, "constraints not satisfiable")
1224-
assert.Contains(t, cond.Message, "installed package prometheus requires at least one of fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.1, fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.0;")
1224+
assert.Contains(t, cond.Message, "installed package prometheus requires at least one of fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.1, fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.0\n")
12251225

12261226
// Valid update skipping one version
12271227
operator.Spec.Version = "1.0.1"
@@ -1418,7 +1418,7 @@ func TestOperatorDowngrade(t *testing.T) {
14181418
assert.Equal(t, metav1.ConditionFalse, cond.Status)
14191419
assert.Equal(t, operatorsv1alpha1.ReasonResolutionFailed, cond.Reason)
14201420
assert.Contains(t, cond.Message, "constraints not satisfiable")
1421-
assert.Contains(t, cond.Message, "installed package prometheus requires at least one of fake-catalog-prometheus-operatorhub/prometheus/beta/1.2.0, fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.1;")
1421+
assert.Contains(t, cond.Message, "installed package prometheus requires at least one of fake-catalog-prometheus-operatorhub/prometheus/beta/1.2.0, fake-catalog-prometheus-operatorhub/prometheus/beta/1.0.1\n")
14221422
})
14231423
}
14241424
})

test/e2e/install_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ var _ = Describe("Operator Install", func() {
227227
g.Expect(cond).ToNot(BeNil())
228228
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonResolutionFailed))
229229
g.Expect(cond.Message).To(ContainSubstring("constraints not satisfiable"))
230-
g.Expect(cond.Message).To(ContainSubstring("installed package prometheus requires at least one of test-catalog-prometheus-prometheus-operator.1.2.0, test-catalog-prometheus-prometheus-operator.1.0.1, test-catalog-prometheus-prometheus-operator.1.0.0;"))
230+
g.Expect(cond.Message).To(MatchRegexp("installed package prometheus requires at least one of test-catalog-prometheus-prometheus-operator.1.2.0, test-catalog-prometheus-prometheus-operator.1.0.1, test-catalog-prometheus-prometheus-operator.1.0.0$"))
231231
g.Expect(operator.Status.ResolvedBundleResource).To(BeEmpty())
232232
}).Should(Succeed())
233233
})

0 commit comments

Comments
 (0)