Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Remove unused stopChan
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Aug 5, 2020
1 parent 269786a commit 23a8270
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions prog/weave-npc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,14 @@ func hCtx() context.Context {
return context.Background()
}

func stopOnPanicRecover(stopChan chan struct{}) {
func stopOnPanicRecover() {
if r := recover(); r != nil {
os.Exit(1)
}
}

func root(cmd *cobra.Command, args []string) {
var (
npController cache.Controller
stopChan chan struct{}
)
var npController cache.Controller

common.SetLogLevel(logLevel)
if nodeName == "" {
Expand Down Expand Up @@ -266,11 +263,11 @@ func root(cmd *cobra.Command, args []string) {
nsController := makeController(client.CoreV1().RESTClient(), "namespaces", &coreapi.Namespace{},
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
handleError(npc.AddNamespace(hCtx(), obj.(*coreapi.Namespace)))
},
DeleteFunc: func(obj interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
switch obj := obj.(type) {
case *coreapi.Namespace:
handleError(npc.DeleteNamespace(hCtx(), obj))
Expand All @@ -282,18 +279,18 @@ func root(cmd *cobra.Command, args []string) {
}
},
UpdateFunc: func(old, new interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
handleError(npc.UpdateNamespace(hCtx(), old.(*coreapi.Namespace), new.(*coreapi.Namespace)))
}})

podController := makeController(client.CoreV1().RESTClient(), "pods", &coreapi.Pod{},
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
handleError(npc.AddPod(hCtx(), obj.(*coreapi.Pod)))
},
DeleteFunc: func(obj interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
switch obj := obj.(type) {
case *coreapi.Pod:
handleError(npc.DeletePod(hCtx(), obj))
Expand All @@ -305,17 +302,17 @@ func root(cmd *cobra.Command, args []string) {
}
},
UpdateFunc: func(old, new interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
handleError(npc.UpdatePod(hCtx(), old.(*coreapi.Pod), new.(*coreapi.Pod)))
}})

npHandlers := cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
handleError(npc.AddNetworkPolicy(hCtx(), obj))
},
DeleteFunc: func(obj interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
switch obj := obj.(type) {
case cache.DeletedFinalStateUnknown:
// We know this object has gone away, but its final state is no longer
Expand All @@ -327,7 +324,7 @@ func root(cmd *cobra.Command, args []string) {
}
},
UpdateFunc: func(old, new interface{}) {
defer stopOnPanicRecover(stopChan)
defer stopOnPanicRecover()
handleError(npc.UpdateNetworkPolicy(hCtx(), old, new))
},
}
Expand Down

0 comments on commit 23a8270

Please sign in to comment.