From ef728457eb667f3e4584063b5dbb4ac3f3ebcc2e Mon Sep 17 00:00:00 2001 From: Rajesh Tailor Date: Thu, 28 Nov 2024 17:52:53 +0530 Subject: [PATCH] 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 --- controllers/nova_controller.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/controllers/nova_controller.go b/controllers/nova_controller.go index 575e378d3..4f47441b8 100644 --- a/controllers/nova_controller.go +++ b/controllers/nova_controller.go @@ -19,6 +19,7 @@ package controllers import ( "context" "fmt" + "sort" "strings" batchv1 "k8s.io/api/batch/v1" @@ -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