From 020b099f1bec630232ad5cea145056de33f70463 Mon Sep 17 00:00:00 2001
From: "mingzhou.swx" <mingzhou.swx@alibaba-inc.com>
Date: Tue, 13 Sep 2022 19:40:07 +0800
Subject: [PATCH] ignore if pod condition has been updated

Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
---
 pkg/util/inplaceupdate/inplace_update.go | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/pkg/util/inplaceupdate/inplace_update.go b/pkg/util/inplaceupdate/inplace_update.go
index 61e6df2f64..81b8966ef9 100644
--- a/pkg/util/inplaceupdate/inplace_update.go
+++ b/pkg/util/inplaceupdate/inplace_update.go
@@ -168,6 +168,10 @@ func (c *realControl) updateCondition(pod *v1.Pod, condition v1.PodCondition) er
 			return err
 		}
 
+		if hasEqualCondition(clone, &condition) {
+			return nil
+		}
+
 		util.SetPodCondition(clone, condition)
 		// We only update the ready condition to False, and let Kubelet update it to True
 		if condition.Status == v1.ConditionFalse {
@@ -408,3 +412,10 @@ func doPreCheckBeforeNext(pod *v1.Pod, preCheck *appspub.InPlaceUpdatePreCheckBe
 	}
 	return nil
 }
+
+func hasEqualCondition(pod *v1.Pod, newCondition *v1.PodCondition) bool {
+	oldCondition := util.GetCondition(pod, newCondition.Type)
+	isEqual := oldCondition != nil && oldCondition.Status == newCondition.Status &&
+		oldCondition.Reason == newCondition.Reason && oldCondition.Message == newCondition.Message
+	return isEqual
+}