@@ -160,76 +160,66 @@ 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
+ // change 1: Condition status change from True to False/Unknown
180
+ newReason = defaultConditionReason
181
+ newMessage = defaultConditionMessage
188
182
} else if condition .Status != types .True && status == types .True {
189
183
// 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
184
+ newReason = result .Rule .Reason
185
+ newMessage = result .Message
201
186
} else if condition .Status != status {
202
187
// 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 &&
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
+ // change 4: Condition status do 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
+ // 5: Condition status do not change and it stays False/Unknown.
200
+ needToUpdateCondition = false
201
+ }
202
+
203
+ if needToUpdateCondition {
220
204
condition .Transition = timestamp
221
- condition .Reason = result .Rule .Reason
222
- condition .Message = result .Message
223
- updateEvent := util .GenerateConditionChangeEvent (
224
- condition .Type ,
225
- status ,
226
- condition .Reason ,
227
- timestamp ,
228
- )
229
- if condition .Status == types .True {
230
- activeProblemEvents = append (activeProblemEvents , updateEvent )
205
+ condition .Status = status
206
+ condition .Reason = newReason
207
+ condition .Message = newMessage
208
+
209
+ if status == types .True {
210
+ activeProblemEvents = append (activeProblemEvents , util .GenerateConditionChangeEvent (
211
+ condition .Type ,
212
+ status ,
213
+ newReason ,
214
+ timestamp ,
215
+ ))
231
216
} else {
232
- inactiveProblemEvents = append (inactiveProblemEvents , updateEvent )
217
+ inactiveProblemEvents = append (inactiveProblemEvents , util .GenerateConditionChangeEvent (
218
+ condition .Type ,
219
+ status ,
220
+ newReason ,
221
+ timestamp ,
222
+ ))
233
223
}
234
224
}
235
225
0 commit comments