Skip to content

Commit ef72845

Browse files
committed
Sort cell-names in nova_controller
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
1 parent dfc4cc1 commit ef72845

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

controllers/nova_controller.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"sort"
2223
"strings"
2324

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

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

316+
// We need to sort the list of cellNames to iterate on to avoid
317+
// unnecessary reconcile loop runs, as the map iteration order is undefined.
318+
sort.Strings(orderedCellNames)
319+
// Also we need to make sure that cell0 is the first to allow dependency
320+
// handling during ensureCell calls.
321+
orderedCellNames = append([]string{novav1.Cell0Name}, orderedCellNames...)
322+
318323
// Create the Cell DBs. Note that we are not returning on error or if the
319324
// DB creation is still in progress. We move forward with whatever we can
320325
// and relay on the watch to get reconciled if some of the resources change

0 commit comments

Comments
 (0)