From 13514b7f452da6157c6bd94bcc66427596f0d6d5 Mon Sep 17 00:00:00 2001 From: Tanmay Jain <103629776+tanmayja@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:57:47 +0530 Subject: [PATCH] Fixing a bug in updating status after on-demand operation. (#301) --- controllers/pod.go | 8 ++++---- controllers/rack.go | 8 ++++---- test/cluster_test.go | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/controllers/pod.go b/controllers/pod.go index 04708fc1d..05451e987 100644 --- a/controllers/pod.go +++ b/controllers/pod.go @@ -1537,13 +1537,13 @@ func (r *SingleClusterReconciler) updateOperationStatus(restartedASDPodNames, re statusPods := sets.New(statusOp.PodList...) if statusOp.Kind == asdbv1.OperationWarmRestart { - if quickRestartsSet != nil { + if quickRestartsSet.Len() > 0 { statusOp.PodList = statusPods.Union(quickRestartsSet.Intersection(specPods)).UnsortedList() } // If the operation is a warm restart and the pod undergoes a cold restart for any reason, // we will still consider the warm restart operation as completed for that pod. - if podRestartsSet != nil { + if podRestartsSet.Len() > 0 { statusOp.PodList = statusPods.Union(podRestartsSet.Intersection(specPods)).UnsortedList() } } @@ -1561,13 +1561,13 @@ func (r *SingleClusterReconciler) updateOperationStatus(restartedASDPodNames, re var podList []string if specOp.Kind == asdbv1.OperationWarmRestart { - if quickRestartsSet != nil { + if quickRestartsSet.Len() > 0 { podList = quickRestartsSet.Intersection(specPods).UnsortedList() } // If the operation is a warm restart and the pod undergoes a cold restart for any reason, // we will still consider the warm restart operation as completed for that pod. - if podRestartsSet != nil { + if podRestartsSet.Len() > 0 { podList = append(podList, podRestartsSet.Intersection(specPods).UnsortedList()...) } } diff --git a/controllers/rack.go b/controllers/rack.go index c98ad2018..061e25d5e 100644 --- a/controllers/rack.go +++ b/controllers/rack.go @@ -86,7 +86,7 @@ func (r *SingleClusterReconciler) reconcileRacks() reconcileResult { // remove ignorable pods from failedPods failedPods = getNonIgnorablePods(failedPods, ignorablePodNames) if len(failedPods) != 0 { - r.Log.Info("Reconcile the failed pods in the Rack", "rackID", state.Rack.ID, "failedPods", failedPods) + r.Log.Info("Reconcile the failed pods in the Rack", "rackID", state.Rack.ID, "failedPods", getPodNames(failedPods)) if res = r.reconcileRack( found, state, ignorablePodNames, failedPods, @@ -94,7 +94,7 @@ func (r *SingleClusterReconciler) reconcileRacks() reconcileResult { return res } - r.Log.Info("Reconciled the failed pods in the Rack", "rackID", state.Rack.ID, "failedPods", failedPods) + r.Log.Info("Reconciled the failed pods in the Rack", "rackID", state.Rack.ID, "failedPods", getPodNames(failedPods)) } // 2. Again, fetch the pods for the rack and if there are failed pods then restart them. @@ -114,14 +114,14 @@ func (r *SingleClusterReconciler) reconcileRacks() reconcileResult { // remove ignorable pods from failedPods failedPods = getNonIgnorablePods(failedPods, ignorablePodNames) if len(failedPods) != 0 { - r.Log.Info("Restart the failed pods in the Rack", "rackID", state.Rack.ID, "failedPods", failedPods) + r.Log.Info("Restart the failed pods in the Rack", "rackID", state.Rack.ID, "failedPods", getPodNames(failedPods)) if _, res = r.rollingRestartRack(found, state, ignorablePodNames, nil, failedPods); !res.isSuccess { return res } - r.Log.Info("Restarted the failed pods in the Rack", "rackID", state.Rack.ID, "failedPods", failedPods) + r.Log.Info("Restarted the failed pods in the Rack", "rackID", state.Rack.ID, "failedPods", getPodNames(failedPods)) // Requeue after 1 second to fetch latest CR object with updated pod status return reconcileRequeueAfter(1) } diff --git a/test/cluster_test.go b/test/cluster_test.go index 1c19952c9..df802367c 100644 --- a/test/cluster_test.go +++ b/test/cluster_test.go @@ -350,6 +350,7 @@ func clusterWithMaxIgnorablePod(ctx goctx.Context) { err = k8sClient.Update(ctx, pod) Expect(err).ToNot(HaveOccurred()) + // Underlying kubernetes cluster should have atleast 6 nodes to run this test successfully. By("Delete rack with id 2") aeroCluster, err = getCluster(k8sClient, ctx, clusterNamespacedName) Expect(err).ToNot(HaveOccurred())