Skip to content

Commit 59dbe82

Browse files
authored
Depreciate ErrNoOperatorCondition (#65)
Problem: The ErrNoOperatorCondition does not surface any errors encountered when retrieving OperatorConditions from the cluster. It is not possible to know if there is an RBAC issue, if the resource does not exist, or some other error. Solution: Surface the error retrieving the OperatorCondition.
1 parent 5eea60d commit 59dbe82

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

conditions/conditions.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
var (
3131
// ErrNoOperatorCondition indicates that the operator condition CRD is nil
32+
// Depreciated
3233
ErrNoOperatorCondition = fmt.Errorf("operator Condition CRD is nil")
3334

3435
// readNamespace gets the namespacedName of the operator.
@@ -72,7 +73,7 @@ func (c *condition) Get(ctx context.Context) (*metav1.Condition, error) {
7273
operatorCond := &apiv2.OperatorCondition{}
7374
err := c.client.Get(ctx, c.namespacedName, operatorCond)
7475
if err != nil {
75-
return nil, ErrNoOperatorCondition
76+
return nil, err
7677
}
7778
con := meta.FindStatusCondition(operatorCond.Spec.Conditions, string(c.condType))
7879

@@ -87,7 +88,7 @@ func (c *condition) Set(ctx context.Context, status metav1.ConditionStatus, opti
8788
operatorCond := &apiv2.OperatorCondition{}
8889
err := c.client.Get(ctx, c.namespacedName, operatorCond)
8990
if err != nil {
90-
return ErrNoOperatorCondition
91+
return err
9192
}
9293

9394
newCond := &metav1.Condition{

conditions/conditions_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
. "github.com/onsi/ginkgo"
2323
. "github.com/onsi/gomega"
2424
apiv2 "github.com/operator-framework/api/pkg/operators/v2"
25+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2526
"k8s.io/apimachinery/pkg/api/meta"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/runtime"
@@ -156,7 +157,7 @@ var _ = Describe("Condition", func() {
156157
Expect(err).NotTo(HaveOccurred())
157158
con, err := c.Get(ctx)
158159
Expect(err).To(HaveOccurred())
159-
Expect(err).To(MatchError(ErrNoOperatorCondition))
160+
Expect(apierrors.IsNotFound(err)).To(BeTrue())
160161
Expect(con).To(BeNil())
161162
})
162163

@@ -208,7 +209,7 @@ var _ = Describe("Condition", func() {
208209
Expect(err).NotTo(HaveOccurred())
209210
err = c.Set(ctx, metav1.ConditionTrue, WithReason("in_bar_state"), WithMessage("test"))
210211
Expect(err).To(HaveOccurred())
211-
Expect(err).To(MatchError(ErrNoOperatorCondition))
212+
Expect(apierrors.IsNotFound(err)).To(BeTrue())
212213
})
213214

214215
})

0 commit comments

Comments
 (0)