Skip to content

Commit

Permalink
Merge pull request #1 from est357/imp_controller_run
Browse files Browse the repository at this point in the history
Add controller crash handling
  • Loading branch information
est357 authored May 23, 2021
2 parents 512e741 + 5af50a0 commit 4c064e8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package owlk8s

import (
"fmt"
"os"

"github.com/est357/owlk8s/helpers"
Expand Down Expand Up @@ -52,8 +53,6 @@ func NewController(results ResMap) Controller {

stopper := make(chan struct{})

defer runtime.HandleCrash()

informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
newEndpoint := obj.(*corev1.Endpoints)
Expand All @@ -80,7 +79,15 @@ func NewController(results ResMap) Controller {

// Run runs the k8s controller
func (c Controller) Run() {
go c.informer.Run(c.stopper)
go func() {
defer runtime.HandleCrash()
c.informer.Run(c.stopper)
if !cache.WaitForCacheSync(c.stopper, c.informer.HasSynced) {
runtime.HandleError(fmt.Errorf("Timed out waiting for caches to sync"))
return
}
<-c.stopper
}()
}

func deleteEndpoint(endpoint *corev1.Endpoints, results ResMap) {
Expand Down

0 comments on commit 4c064e8

Please sign in to comment.