From c537a0499ed4b68256498d98161691ea7dd31b12 Mon Sep 17 00:00:00 2001
From: Saurov Chandra Biswas
 <48715910+souravbiswassanto@users.noreply.github.com>
Date: Tue, 19 Nov 2024 18:29:40 +0600
Subject: [PATCH] Count node shift of pod as failure (#22)

Signed-off-by: souravbiswassanto <saurov@appscode.com>
---
 pkg/controllers/apps/sidekick_controller.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pkg/controllers/apps/sidekick_controller.go b/pkg/controllers/apps/sidekick_controller.go
index d42c965..5428889 100644
--- a/pkg/controllers/apps/sidekick_controller.go
+++ b/pkg/controllers/apps/sidekick_controller.go
@@ -145,11 +145,13 @@ func (r *SidekickReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
 		if expectedHash != actualHash ||
 			leader.Name != pod.Annotations[keyLeader] ||
 			leader.Spec.NodeName != pod.Spec.NodeName || (pod.Status.Phase == corev1.PodFailed && sidekick.Spec.RestartPolicy == corev1.RestartPolicyNever) {
+			if leader.Spec.NodeName != pod.Spec.NodeName && pod.Spec.NodeName != "" {
+				sidekick.Status.FailureCount[string(pod.GetUID())] = true
+			}
 			err := r.deletePod(ctx, &pod)
 			if err != nil {
 				return ctrl.Result{}, err
 			}
-
 			sidekick.Status.Leader.Name = ""
 			sidekick.Status.Pod = ""
 			sidekick.Status.ObservedGeneration = sidekick.GetGeneration()