mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-10-08 16:31:07 +02:00
prevent processing updates leading to sync when controller doing full sync at boot time (#400)
This commit is contained in:
parent
041c05570a
commit
a1ecedf802
@ -49,6 +49,7 @@ type NetworkPolicyController struct {
|
|||||||
syncPeriod time.Duration
|
syncPeriod time.Duration
|
||||||
MetricsEnabled bool
|
MetricsEnabled bool
|
||||||
v1NetworkPolicy bool
|
v1NetworkPolicy bool
|
||||||
|
readyForUpdates bool
|
||||||
|
|
||||||
// list of all active network policies expressed as networkPolicyInfo
|
// list of all active network policies expressed as networkPolicyInfo
|
||||||
networkPoliciesInfo *[]networkPolicyInfo
|
networkPoliciesInfo *[]networkPolicyInfo
|
||||||
@ -137,7 +138,7 @@ func (npc *NetworkPolicyController) Run(healthChan chan<- *ControllerHeartbeat,
|
|||||||
} else {
|
} else {
|
||||||
sendHeartBeat(healthChan, "NPC")
|
sendHeartBeat(healthChan, "NPC")
|
||||||
}
|
}
|
||||||
|
npc.readyForUpdates = true
|
||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
glog.Infof("Shutting down network policies controller")
|
glog.Infof("Shutting down network policies controller")
|
||||||
@ -152,6 +153,11 @@ func (npc *NetworkPolicyController) OnPodUpdate(obj interface{}) {
|
|||||||
pod := obj.(*api.Pod)
|
pod := obj.(*api.Pod)
|
||||||
glog.V(2).Infof("Received update to pod: %s/%s", pod.Namespace, pod.Name)
|
glog.V(2).Infof("Received update to pod: %s/%s", pod.Namespace, pod.Name)
|
||||||
|
|
||||||
|
if !npc.readyForUpdates {
|
||||||
|
glog.V(3).Infof("Skipping update to pod: %s/%s, controller still performing bootup full-sync", pod.Namespace, pod.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err := npc.Sync()
|
err := npc.Sync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error syncing network policy for the update to pod: %s/%s Error: %s", pod.Namespace, pod.Name, err)
|
glog.Errorf("Error syncing network policy for the update to pod: %s/%s Error: %s", pod.Namespace, pod.Name, err)
|
||||||
@ -162,6 +168,12 @@ func (npc *NetworkPolicyController) OnPodUpdate(obj interface{}) {
|
|||||||
func (npc *NetworkPolicyController) OnNetworkPolicyUpdate(obj interface{}) {
|
func (npc *NetworkPolicyController) OnNetworkPolicyUpdate(obj interface{}) {
|
||||||
netpol := obj.(*networking.NetworkPolicy)
|
netpol := obj.(*networking.NetworkPolicy)
|
||||||
glog.V(2).Infof("Received update for network policy: %s/%s", netpol.Namespace, netpol.Name)
|
glog.V(2).Infof("Received update for network policy: %s/%s", netpol.Namespace, netpol.Name)
|
||||||
|
|
||||||
|
if !npc.readyForUpdates {
|
||||||
|
glog.V(3).Infof("Skipping update to network policy: %s/%s, controller still performing bootup full-sync", netpol.Namespace, netpol.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err := npc.Sync()
|
err := npc.Sync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error syncing network policy for the update to network policy: %s/%s Error: %s", netpol.Namespace, netpol.Name, err)
|
glog.Errorf("Error syncing network policy for the update to network policy: %s/%s Error: %s", netpol.Namespace, netpol.Name, err)
|
||||||
@ -196,7 +208,7 @@ func (npc *NetworkPolicyController) Sync() error {
|
|||||||
if npc.MetricsEnabled {
|
if npc.MetricsEnabled {
|
||||||
controllerIptablesSyncTime.WithLabelValues().Set(float64(endTime))
|
controllerIptablesSyncTime.WithLabelValues().Set(float64(endTime))
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("sync iptables took %v", endTime)
|
glog.V(1).Infof("sync iptables took %v", endTime)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
glog.V(1).Info("Starting periodic sync of iptables")
|
glog.V(1).Info("Starting periodic sync of iptables")
|
||||||
@ -1414,8 +1426,12 @@ func (npc *NetworkPolicyController) newPodEventHandler() cache.ResourceEventHand
|
|||||||
|
|
||||||
},
|
},
|
||||||
UpdateFunc: func(oldObj, newObj interface{}) {
|
UpdateFunc: func(oldObj, newObj interface{}) {
|
||||||
|
newPoObj := newObj.(*api.Pod)
|
||||||
|
oldPoObj := oldObj.(*api.Pod)
|
||||||
|
if newPoObj.Status.Phase != oldPoObj.Status.Phase || newPoObj.Status.PodIP != oldPoObj.Status.PodIP {
|
||||||
|
// for the network policies, we are only interested in pod status phase change or IP change
|
||||||
npc.OnPodUpdate(newObj)
|
npc.OnPodUpdate(newObj)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
DeleteFunc: func(obj interface{}) {
|
DeleteFunc: func(obj interface{}) {
|
||||||
npc.OnPodUpdate(obj)
|
npc.OnPodUpdate(obj)
|
||||||
|
@ -1429,10 +1429,6 @@ func (nrc *NetworkRoutingController) OnNodeUpdate(obj interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nrc *NetworkRoutingController) OnServiceUpdate(obj interface{}) {
|
func (nrc *NetworkRoutingController) OnServiceUpdate(obj interface{}) {
|
||||||
if !nrc.bgpServerStarted {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
svc, ok := obj.(*v1core.Service)
|
svc, ok := obj.(*v1core.Service)
|
||||||
if !ok {
|
if !ok {
|
||||||
glog.Errorf("cache indexer returned obj that is not type *v1.Service")
|
glog.Errorf("cache indexer returned obj that is not type *v1.Service")
|
||||||
@ -1440,6 +1436,11 @@ func (nrc *NetworkRoutingController) OnServiceUpdate(obj interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glog.V(1).Infof("Received update to service: %s/%s from watch API", svc.Namespace, svc.Name)
|
glog.V(1).Infof("Received update to service: %s/%s from watch API", svc.Namespace, svc.Name)
|
||||||
|
if !nrc.bgpServerStarted {
|
||||||
|
glog.V(3).Infof("Skipping update to service: %s/%s, controller still performing bootup full-sync", svc.Namespace, svc.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
toAdvertise, toWithdraw, err := nrc.getVIPsForService(svc, true)
|
toAdvertise, toWithdraw, err := nrc.getVIPsForService(svc, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("error getting routes for service: %s, err: %s", svc.Name, err)
|
glog.Errorf("error getting routes for service: %s, err: %s", svc.Name, err)
|
||||||
@ -1483,10 +1484,6 @@ func (nrc *NetworkRoutingController) OnServiceDelete(obj interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nrc *NetworkRoutingController) OnEndpointsUpdate(obj interface{}) {
|
func (nrc *NetworkRoutingController) OnEndpointsUpdate(obj interface{}) {
|
||||||
if !nrc.bgpServerStarted {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ep, ok := obj.(*v1core.Endpoints)
|
ep, ok := obj.(*v1core.Endpoints)
|
||||||
if !ok {
|
if !ok {
|
||||||
glog.Errorf("cache indexer returned obj that is not type *v1.Endpoints")
|
glog.Errorf("cache indexer returned obj that is not type *v1.Endpoints")
|
||||||
@ -1497,6 +1494,12 @@ func (nrc *NetworkRoutingController) OnEndpointsUpdate(obj interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glog.V(1).Infof("Received update to endpoint: %s/%s from watch API", ep.Namespace, ep.Name)
|
||||||
|
if !nrc.bgpServerStarted {
|
||||||
|
glog.V(3).Infof("Skipping update to endpoint: %s/%s, controller still performing bootup full-sync", ep.Namespace, ep.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
svc, err := nrc.serviceForEndpoints(ep)
|
svc, err := nrc.serviceForEndpoints(ep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("failed to convert endpoints resource to service: %s", err)
|
glog.Errorf("failed to convert endpoints resource to service: %s", err)
|
||||||
|
@ -169,6 +169,7 @@ type NetworkServicesController struct {
|
|||||||
nodeportBindOnAllIp bool
|
nodeportBindOnAllIp bool
|
||||||
MetricsEnabled bool
|
MetricsEnabled bool
|
||||||
ln LinuxNetworking
|
ln LinuxNetworking
|
||||||
|
readyForUpdates bool
|
||||||
|
|
||||||
svcLister cache.Indexer
|
svcLister cache.Indexer
|
||||||
epLister cache.Indexer
|
epLister cache.Indexer
|
||||||
@ -246,7 +247,7 @@ func (nsc *NetworkServicesController) Run(healthChan chan<- *ControllerHeartbeat
|
|||||||
} else {
|
} else {
|
||||||
sendHeartBeat(healthChan, "NSC")
|
sendHeartBeat(healthChan, "NSC")
|
||||||
}
|
}
|
||||||
|
nsc.readyForUpdates = true
|
||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
glog.Info("Shutting down network services controller")
|
glog.Info("Shutting down network services controller")
|
||||||
@ -350,9 +351,6 @@ func (nsc *NetworkServicesController) publishMetrics(serviceInfoMap serviceInfoM
|
|||||||
|
|
||||||
// OnEndpointsUpdate handle change in endpoints update from the API server
|
// OnEndpointsUpdate handle change in endpoints update from the API server
|
||||||
func (nsc *NetworkServicesController) OnEndpointsUpdate(obj interface{}) {
|
func (nsc *NetworkServicesController) OnEndpointsUpdate(obj interface{}) {
|
||||||
nsc.mu.Lock()
|
|
||||||
defer nsc.mu.Unlock()
|
|
||||||
|
|
||||||
ep, ok := obj.(*api.Endpoints)
|
ep, ok := obj.(*api.Endpoints)
|
||||||
if !ok {
|
if !ok {
|
||||||
glog.Error("could not convert endpoints update object to *v1.Endpoints")
|
glog.Error("could not convert endpoints update object to *v1.Endpoints")
|
||||||
@ -364,6 +362,12 @@ func (nsc *NetworkServicesController) OnEndpointsUpdate(obj interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glog.V(1).Infof("Received update to endpoint: %s/%s from watch API", ep.Namespace, ep.Name)
|
glog.V(1).Infof("Received update to endpoint: %s/%s from watch API", ep.Namespace, ep.Name)
|
||||||
|
if !nsc.readyForUpdates {
|
||||||
|
glog.V(3).Infof("Skipping update to endpoint: %s/%s, controller still performing bootup full-sync", ep.Namespace, ep.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nsc.mu.Lock()
|
||||||
|
defer nsc.mu.Unlock()
|
||||||
|
|
||||||
// build new service and endpoints map to reflect the change
|
// build new service and endpoints map to reflect the change
|
||||||
newServiceMap := nsc.buildServicesInfo()
|
newServiceMap := nsc.buildServicesInfo()
|
||||||
@ -381,9 +385,6 @@ func (nsc *NetworkServicesController) OnEndpointsUpdate(obj interface{}) {
|
|||||||
|
|
||||||
// OnServiceUpdate handle change in service update from the API server
|
// OnServiceUpdate handle change in service update from the API server
|
||||||
func (nsc *NetworkServicesController) OnServiceUpdate(obj interface{}) {
|
func (nsc *NetworkServicesController) OnServiceUpdate(obj interface{}) {
|
||||||
nsc.mu.Lock()
|
|
||||||
defer nsc.mu.Unlock()
|
|
||||||
|
|
||||||
svc, ok := obj.(*api.Service)
|
svc, ok := obj.(*api.Service)
|
||||||
if !ok {
|
if !ok {
|
||||||
glog.Error("could not convert service update object to *v1.Service")
|
glog.Error("could not convert service update object to *v1.Service")
|
||||||
@ -391,6 +392,12 @@ func (nsc *NetworkServicesController) OnServiceUpdate(obj interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glog.V(1).Infof("Received update to service: %s/%s from watch API", svc.Namespace, svc.Name)
|
glog.V(1).Infof("Received update to service: %s/%s from watch API", svc.Namespace, svc.Name)
|
||||||
|
if !nsc.readyForUpdates {
|
||||||
|
glog.V(3).Infof("Skipping update to service: %s/%s, controller still performing bootup full-sync", svc.Namespace, svc.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nsc.mu.Lock()
|
||||||
|
defer nsc.mu.Unlock()
|
||||||
|
|
||||||
// build new service and endpoints map to reflect the change
|
// build new service and endpoints map to reflect the change
|
||||||
newServiceMap := nsc.buildServicesInfo()
|
newServiceMap := nsc.buildServicesInfo()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user