Skip to content

Commit 4043df9

Browse files
committed
Order an operator CR's status.Component.Refs array
Problem: The operator CR's status includes a list of componenets owned by the operator. The list of components are ordered by GVK, but the order of objects with the same GVK may change. If an operator owns many components, there is a high likelyhood that OLM will continuously update the status of the operator CR because the order of its components have changed, Solution: Order an operators component references so OLM does not attempt to update the status of the operator CR. Signed-off-by: Alexander Greene <[email protected]>
1 parent 91e5d90 commit 4043df9

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

pkg/controller/operators/decorators/operator.go

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package decorators
22

33
import (
44
"fmt"
5+
"sort"
56
"strings"
67

78
"github.com/itchyny/gojq"
@@ -331,6 +332,10 @@ func (o *Operator) AddComponents(components ...runtime.Object) error {
331332

332333
o.Status.Components.Refs = append(o.Status.Components.Refs, refs...)
333334

335+
// Order the operator.Status.Components.Refs entries so the status of the
336+
// operator CR does not change on subsequent runs.
337+
sort.Sort(o.Status.Components)
338+
334339
return nil
335340
}
336341

pkg/controller/operators/operator_controller.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package operators
33
import (
44
"context"
55
"fmt"
6+
"reflect"
67

78
"github.com/go-logr/logr"
89
appsv1 "k8s.io/api/apps/v1"
@@ -152,9 +153,11 @@ func (r *OperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
152153
return ctrl.Result{Requeue: true}, nil
153154
}
154155
} else {
155-
if err := r.Status().Update(ctx, operator.Operator); err != nil {
156-
log.Error(err, "Could not update Operator status")
157-
return ctrl.Result{Requeue: true}, nil
156+
if !reflect.DeepEqual(in.Status, operator.Operator.Status) {
157+
if err := r.Status().Update(ctx, operator.Operator); err != nil {
158+
log.Error(err, "Could not update Operator status")
159+
return ctrl.Result{Requeue: true}, nil
160+
}
158161
}
159162
}
160163

vendor/github.com/operator-framework/api/pkg/operators/v1/operator_types.go

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)