Skip to content

Commit

Permalink
Add error handling for event handlers
Browse files Browse the repository at this point in the history
Signed-off-by: Harisudarsan <[email protected]>
  • Loading branch information
harisudarsan1 committed Aug 6, 2024
1 parent a037494 commit 1cf3167
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions relay-server/informers/informercache.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func StartInformers(client *Client) {
kg.Printf("pod informers created")

// Set up event handlers for Pods
podInformer.AddEventHandler(
_, err := podInformer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
pod, ok := obj.(*v1.Pod)
Expand Down Expand Up @@ -137,11 +137,16 @@ func StartInformers(client *Client) {
},
)

if err != nil {
kg.Errf("Failed to add Event handlers for pods: %v", err)
return
}

// Get the Service informer
serviceInformer := informerFactory.Core().V1().Services().Informer()

// Set up event handlers
serviceInformer.AddEventHandler(
_, err = serviceInformer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
service, ok := obj.(*v1.Service)
Expand Down Expand Up @@ -191,6 +196,11 @@ func StartInformers(client *Client) {
},
)

if err != nil {
kg.Errf("Failed to add Event handlers for services: %v", err)
return
}

// Start the informer
stopCh := make(chan struct{})
defer close(stopCh)
Expand Down

0 comments on commit 1cf3167

Please sign in to comment.