Skip to content

Commit

Permalink
Changes watch events to AddFunc rather than UpdateFunc
Browse files Browse the repository at this point in the history
The same events are covered by AddFunc as by UpdateFunc with less overhead. Any container crashes are caught by the Game Server Unhealthy watch, and are not needed in this watch.
  • Loading branch information
igooch committed Dec 4, 2024
1 parent 8c1c678 commit 083bf3c
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions test/upgrade/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,10 @@ func watchGameServers(agonesClient *versioned.Clientset, acceptedFailures int) {
}
}

// watchGameServerEvents watches all `sdk-client-test` containers for BackOff errors. The purpose is
// to catch ImagePullBackOff and CrashBackOffLoop errors.
// watchGameServerEvents watches all events on `sdk-client-test` containers for BackOff errors. The
// purpose is to catch ImagePullBackOff errors.
func watchGameServerEvents(kubeClient *kubernetes.Clientset) {
stopCh := make(chan struct{})
failedPods := make(map[string]int)
acceptedFailures := 6 // (6 * 5*time.Second defaultResync) == 30 seconds until failure

// Filter by Game Server `sdk-client-test` containers
containerName := "sdk-client-test"
Expand All @@ -539,22 +537,14 @@ func watchGameServerEvents(kubeClient *kubernetes.Clientset) {
eventInformer := kubeInformerFactory.Core().V1().Events().Informer()

_, err = eventInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(_, newObj interface{}) {
newEvent := newObj.(*v1.Event)
AddFunc: func(obj interface{}) {
newEvent := obj.(*v1.Event)
gsPodName := newEvent.InvolvedObject.Name
log.Println("AddFunc", gsPodName, newEvent.Reason)
if newEvent.Reason == "Failed" {
log.Fatalf("%s on %s %s has failed. Latest event: message %s", containerName, newEvent.Kind,
gsPodName, newEvent.Message)
}
if newEvent.Reason == "BackOff" {
failedPods[gsPodName]++
if backOffs, ok := failedPods[gsPodName]; ok {
if backOffs > acceptedFailures {
log.Fatalf("%s on %s %s has too many BackOffs. Latest event message: %s", containerName, newEvent.Kind,
gsPodName, newEvent.Message)
}
}
}
},
})
if err != nil {
Expand Down

0 comments on commit 083bf3c

Please sign in to comment.