Skip to content

Commit

Permalink
Order an operator CR's status.Component.Refs array
Browse files Browse the repository at this point in the history
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 <greene.al1991@gmail.com>
  • Loading branch information
awgreene committed Oct 27, 2022
1 parent 91e5d90 commit 3b10544
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/controller/operators/decorators/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package decorators

import (
"fmt"
"sort"
"strings"

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

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

// Order the operator.Status.Components entries so the status of the
// operator CR does not change on subsequent runs.
sort.Sort(o.Status.Components)

return nil
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/controller/operators/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package operators
import (
"context"
"fmt"
"reflect"

"github.com/go-logr/logr"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -152,9 +153,11 @@ func (r *OperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{Requeue: true}, nil
}
} else {
if err := r.Status().Update(ctx, operator.Operator); err != nil {
log.Error(err, "Could not update Operator status")
return ctrl.Result{Requeue: true}, nil
if !reflect.DeepEqual(in.Status, operator.Operator.Status) {
if err := r.Status().Update(ctx, operator.Operator); err != nil {
log.Error(err, "Could not update Operator status")
return ctrl.Result{Requeue: true}, nil
}
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b10544

Please sign in to comment.