@@ -160,73 +160,62 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat
160
160
for i := range c .conditions {
161
161
condition := & c .conditions [i ]
162
162
if condition .Type == result .Rule .Condition {
163
- status := toConditionStatus (result .ExitStatus )
164
- // change 1: Condition status change from True to False/Unknown
165
- if condition .Status == types .True && status != types .True {
166
- condition .Transition = timestamp
167
- var defaultConditionReason string
168
- var defaultConditionMessage string
169
- for j := range c .config .DefaultConditions {
170
- defaultCondition := & c .config .DefaultConditions [j ]
171
- if defaultCondition .Type == result .Rule .Condition {
172
- defaultConditionReason = defaultCondition .Reason
173
- defaultConditionMessage = defaultCondition .Message
174
- break
175
- }
163
+ var defaultConditionReason string
164
+ var defaultConditionMessage string
165
+ for j := range c .config .DefaultConditions {
166
+ defaultCondition := & c .config .DefaultConditions [j ]
167
+ if defaultCondition .Type == result .Rule .Condition {
168
+ defaultConditionReason = defaultCondition .Reason
169
+ defaultConditionMessage = defaultCondition .Message
170
+ break
176
171
}
172
+ }
177
173
178
- inactiveProblemEvents = append (inactiveProblemEvents , util .GenerateConditionChangeEvent (
179
- condition .Type ,
180
- status ,
181
- defaultConditionReason ,
182
- timestamp ,
183
- ))
184
-
185
- condition .Status = status
186
- condition .Message = defaultConditionMessage
187
- condition .Reason = defaultConditionReason
174
+ needToUpdateCondition := true
175
+ var newReason string
176
+ var newMessage string
177
+ status := toConditionStatus (result .ExitStatus )
178
+ if condition .Status == types .True && status != types .True {
179
+ // Scenario 1: Condition status changes from True to False/Unknown
180
+ newReason = defaultConditionReason
181
+ newMessage = defaultConditionMessage
188
182
} else if condition .Status != types .True && status == types .True {
189
- // change 2: Condition status change from False/Unknown to True
190
- condition .Transition = timestamp
191
- condition .Message = result .Message
192
- activeProblemEvents = append (activeProblemEvents , util .GenerateConditionChangeEvent (
193
- condition .Type ,
194
- status ,
195
- result .Rule .Reason ,
196
- timestamp ,
197
- ))
198
-
199
- condition .Status = status
200
- condition .Reason = result .Rule .Reason
183
+ // Scenario 2: Condition status changes from False/Unknown to True
184
+ newReason = result .Rule .Reason
185
+ newMessage = result .Message
201
186
} else if condition .Status != status {
202
- // change 3: Condition status change from False to Unknown or vice versa
203
- condition .Transition = timestamp
204
- condition .Message = result .Message
205
- inactiveProblemEvents = append (inactiveProblemEvents , util .GenerateConditionChangeEvent (
206
- condition .Type ,
207
- status ,
208
- result .Rule .Reason ,
209
- timestamp ,
210
- ))
211
-
212
- condition .Status = status
213
- condition .Reason = result .Rule .Reason
214
- } else if condition .Status == status &&
187
+ // Scenario 3: Condition status changes from False to Unknown or vice versa
188
+ newReason = defaultConditionReason
189
+ newMessage = defaultConditionMessage
190
+ } else if condition .Status == types .True && status == types .True &&
215
191
(condition .Reason != result .Rule .Reason ||
216
192
(* c .config .PluginGlobalConfig .EnableMessageChangeBasedConditionUpdate && condition .Message != result .Message )) {
217
- // change 4: Condition status do not change.
193
+ // Scenario 4: Condition status does not change and it stays true .
218
194
// condition reason changes or
219
195
// condition message changes when message based condition update is enabled.
196
+ newReason = result .Rule .Reason
197
+ newMessage = result .Message
198
+ } else {
199
+ // Scenario 5: Condition status does not change and it stays False/Unknown.
200
+ // This should just be the default reason or message (as a consequence
201
+ // of scenario 1 and scenario 3 above).
202
+ needToUpdateCondition = false
203
+ }
204
+
205
+ if needToUpdateCondition {
220
206
condition .Transition = timestamp
221
- condition .Reason = result .Rule .Reason
222
- condition .Message = result .Message
207
+ condition .Status = status
208
+ condition .Reason = newReason
209
+ condition .Message = newMessage
210
+
223
211
updateEvent := util .GenerateConditionChangeEvent (
224
212
condition .Type ,
225
213
status ,
226
- condition . Reason ,
214
+ newReason ,
227
215
timestamp ,
228
216
)
229
- if condition .Status == types .True {
217
+
218
+ if status == types .True {
230
219
activeProblemEvents = append (activeProblemEvents , updateEvent )
231
220
} else {
232
221
inactiveProblemEvents = append (inactiveProblemEvents , updateEvent )
0 commit comments