@@ -84,6 +84,9 @@ const (
8484
8585 // ConditionTypeTopologyAware indicates that the member is deployed with TopologyAwareness.
8686 ConditionTypeTopologyAware ConditionType = "TopologyAware"
87+
88+ // ConditionTypeLicenseSet indicates that license V2 is set on cluster.
89+ ConditionTypeLicenseSet ConditionType = "LicenseSet"
8790)
8891
8992// Condition represents one current condition of a deployment or deployment member.
@@ -102,6 +105,8 @@ type Condition struct {
102105 Reason string `json:"reason,omitempty"`
103106 // A human readable message indicating details about the transition.
104107 Message string `json:"message,omitempty"`
108+ // Hash keep propagation hash id, for example checksum of secret
109+ Hash string `json:"hash,omitempty"`
105110}
106111
107112func (c Condition ) IsTrue () bool {
@@ -139,7 +144,8 @@ func (c Condition) Equal(other Condition) bool {
139144 util .TimeCompareEqual (c .LastUpdateTime , other .LastUpdateTime ) &&
140145 util .TimeCompareEqual (c .LastTransitionTime , other .LastTransitionTime ) &&
141146 c .Reason == other .Reason &&
142- c .Message == other .Message
147+ c .Message == other .Message &&
148+ c .Hash == other .Hash
143149}
144150
145151// IsTrue return true when a condition with given type exists and its status is `True`.
@@ -178,47 +184,72 @@ func (list *ConditionList) Touch(conditionType ConditionType) bool {
178184 return false
179185}
180186
181- // Update the condition, replacing an old condition with same type (if any)
182- // Returns true when changes were made, false otherwise.
183- func (list * ConditionList ) Update (conditionType ConditionType , status bool , reason , message string ) bool {
187+ func (list ConditionList ) Index (conditionType ConditionType ) int {
188+ for i , x := range list {
189+ if x .Type == conditionType {
190+ return i
191+ }
192+ }
193+
194+ return - 1
195+ }
196+
197+ func (list * ConditionList ) update (conditionType ConditionType , status bool , reason , message , hash string ) bool {
184198 src := * list
185199 statusX := v1 .ConditionFalse
186200 if status {
187201 statusX = v1 .ConditionTrue
188202 }
189- for i , x := range src {
190- if x .Type == conditionType {
191- if x .Status != statusX {
192- // Transition to another status
193- src [i ].Status = statusX
194- now := metav1 .Now ()
195- src [i ].LastTransitionTime = now
196- src [i ].LastUpdateTime = now
197- src [i ].Reason = reason
198- src [i ].Message = message
199- } else if x .Reason != reason || x .Message != message {
200- src [i ].LastUpdateTime = metav1 .Now ()
201- src [i ].Reason = reason
202- src [i ].Message = message
203- } else {
204- return false
205- }
206- return true
207- }
203+
204+ index := list .Index (conditionType )
205+
206+ if index == - 1 {
207+ // Not found
208+ now := metav1 .Now ()
209+ * list = append (src , Condition {
210+ Type : conditionType ,
211+ LastUpdateTime : now ,
212+ LastTransitionTime : now ,
213+ Status : statusX ,
214+ Reason : reason ,
215+ Message : message ,
216+ Hash : hash ,
217+ })
218+ return true
219+ }
220+
221+ if src [index ].Status != statusX {
222+ // Transition to another status
223+ src [index ].Status = statusX
224+ now := metav1 .Now ()
225+ src [index ].LastTransitionTime = now
226+ src [index ].LastUpdateTime = now
227+ src [index ].Reason = reason
228+ src [index ].Message = message
229+ src [index ].Hash = hash
230+ } else if src [index ].Reason != reason || src [index ].Message != message || src [index ].Hash != hash {
231+ src [index ].LastUpdateTime = metav1 .Now ()
232+ src [index ].Reason = reason
233+ src [index ].Message = message
234+ src [index ].Hash = hash
235+ } else {
236+ return false
208237 }
209- // Not found
210- now := metav1 .Now ()
211- * list = append (src , Condition {
212- Type : conditionType ,
213- LastUpdateTime : now ,
214- LastTransitionTime : now ,
215- Status : statusX ,
216- Reason : reason ,
217- Message : message ,
218- })
219238 return true
220239}
221240
241+ // Update the condition, replacing an old condition with same type (if any)
242+ // Returns true when changes were made, false otherwise.
243+ func (list * ConditionList ) Update (conditionType ConditionType , status bool , reason , message string ) bool {
244+ return list .update (conditionType , status , reason , message , "" )
245+ }
246+
247+ // UpdateWithHash updates the condition, replacing an old condition with same type (if any)
248+ // Returns true when changes were made, false otherwise.
249+ func (list * ConditionList ) UpdateWithHash (conditionType ConditionType , status bool , reason , message , hash string ) bool {
250+ return list .update (conditionType , status , reason , message , hash )
251+ }
252+
222253// Remove the condition with given type.
223254// Returns true if removed, or false if not found.
224255func (list * ConditionList ) Remove (conditionType ConditionType ) bool {
0 commit comments