Skip to content

Commit

Permalink
Sort cell-names in nova_controller
Browse files Browse the repository at this point in the history
As of now, the orderedCellNames variable contains 'cell0' as first
element and then appends cell-names coming from CellTemplates map,
which doesn't provide stable ordering. Then the CR status condition
message could change for each reconcile with any change in the actual
status of the CR. And a changing status message could trigger
unnecessary reconcile loops.

This change sorts the cell-names and also make sure
that the cell0 is the first element in the orderedCellNames
slice to maintain stable ordering.

Closes: #OSPRH-9980
  • Loading branch information
ratailor committed Dec 4, 2024
1 parent dfc4cc1 commit ef72845
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions controllers/nova_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"sort"
"strings"

batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -305,16 +306,20 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
return ctrl.Result{}, fmt.Errorf("invalid DatabaseStatus from ensureAPIDB: %d", apiDBStatus)
}

// We need to create a list of cellNames to iterate on and as the map
// iteration order is undefined we need to make sure that cell0 is the
// first to allow dependency handling during ensureCell calls.
orderedCellNames := []string{novav1.Cell0Name}
orderedCellNames := []string{}
for cellName := range instance.Spec.CellTemplates {
if cellName != novav1.Cell0Name {
orderedCellNames = append(orderedCellNames, cellName)
}
}

// We need to sort the list of cellNames to iterate on to avoid
// unnecessary reconcile loop runs, as the map iteration order is undefined.
sort.Strings(orderedCellNames)
// Also we need to make sure that cell0 is the first to allow dependency
// handling during ensureCell calls.
orderedCellNames = append([]string{novav1.Cell0Name}, orderedCellNames...)

// Create the Cell DBs. Note that we are not returning on error or if the
// DB creation is still in progress. We move forward with whatever we can
// and relay on the watch to get reconciled if some of the resources change
Expand Down

0 comments on commit ef72845

Please sign in to comment.