Generic Watcher Code: https://gist.github.com/Thoro/2e81754c253a85981e06d4fd6839eee7
Use in controllers:
func (nec *NetworkEgressController) OnItemUpdate(update *watchers.Update) { nec.mu.Lock(); defer nec.mu.Unlock() switch v:= update.Item.(type) {
default:
glog.Infof("DEFAULT: %v", update.Item)
case *creamfinance.PodIP:
nec.OnPodIPUpdate(update.Op, v)
case *api.Node:
glog.Infof("Node UPDATE: %v", v.Name)
case *api.Service:
nec.OnServiceUpdate(update.Op, v)
case *apiextensions.NetworkPolicy:
nec.OnNetworkPolicyUpdate(update.Op, v)
case *api.Pod:
nec.OnPodUpdate(update.Op, v)
case *api.Endpoints:
glog.Infof("Endpoint UPDATE: %v", v.Name)
} }