Skip to content

Commit 8f13601

Browse files
committed
feat: allow to log update of events
1 parent 46b4208 commit 8f13601

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

main.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
var (
1717
ignoreNormal = flag.Bool("ignore-normal", false, "ignore events of type 'Normal' to reduce noise")
18+
ignoreUpdate = flag.Bool("ignore-update", true, "ignore update of events")
1819
)
1920

2021
func main() {
@@ -58,11 +59,16 @@ func main() {
5859
0,
5960
cache.ResourceEventHandlerFuncs{
6061
AddFunc: func(obj interface{}) {
61-
if (*ignoreNormal && obj.(*corev1.Event).Type == corev1.EventTypeNormal) {
62+
if *ignoreNormal && obj.(*corev1.Event).Type == corev1.EventTypeNormal {
6263
return
6364
}
64-
j, _ := json.Marshal(obj)
65-
loggerEvent.Printf("%s\n", string(j))
65+
logEvent(obj, loggerEvent)
66+
},
67+
UpdateFunc: func(oldObj, newObj interface{}) {
68+
if *ignoreUpdate || (*ignoreNormal && newObj.(*corev1.Event).Type == corev1.EventTypeNormal) {
69+
return
70+
}
71+
logEvent(newObj, loggerEvent)
6672
},
6773
},
6874
)
@@ -72,3 +78,8 @@ func main() {
7278
go controller.Run(stop)
7379
select {}
7480
}
81+
82+
func logEvent(obj interface{}, logger *log.Logger) {
83+
j, _ := json.Marshal(obj)
84+
logger.Printf("%s\n", string(j))
85+
}

0 commit comments

Comments
 (0)