generated from kyma-project/template-repository
/
emit_event.go
44 lines (38 loc) · 1.1 KB
/
emit_event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package state
import (
"strings"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
warningMessagePrefix = "Warning"
)
func emitEvent(m *reconciler, s *systemState) {
// compare if any condition change
for _, condition := range s.instance.Status.Conditions {
// check if condition exists in memento status
memorizedCondition := meta.FindStatusCondition(s.snapshot.Conditions, condition.Type)
// ignore unchanged conditions
if memorizedCondition != nil &&
memorizedCondition.Status == condition.Status &&
memorizedCondition.Reason == condition.Reason &&
memorizedCondition.Message == condition.Message {
continue
}
m.Event(
&s.instance,
eventType(condition, condition.Message),
condition.Reason,
condition.Message,
)
}
// take a snapshot to not repeat lastly emitted events
s.saveSnapshot()
}
func eventType(condition metav1.Condition, message string) string {
eventType := "Normal"
if condition.Status == metav1.ConditionFalse || strings.HasPrefix(message, warningMessagePrefix) {
eventType = "Warning"
}
return eventType
}