From 7c46a958a2507caf8ef809fd3c3ba029dadbd151 Mon Sep 17 00:00:00 2001 From: Daniel Boucher Date: Fri, 31 May 2019 12:46:24 -0400 Subject: [PATCH] Send heartbeats during NetworkPolicy and NetworkService sync. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In reference to issue #725, we modified kube-router to send heartbeats during policy sync to prevent missing heartbeats while running iptables commands. This commit is the first part to make kube-router faster and more robust when applying network policies. Signed-off-by: Jérôme Poulin --- pkg/controllers/netpol/network_policy_controller.go | 5 ++++- pkg/controllers/proxy/network_services_controller.go | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/netpol/network_policy_controller.go b/pkg/controllers/netpol/network_policy_controller.go index 41b25c6f54..9528710f5c 100644 --- a/pkg/controllers/netpol/network_policy_controller.go +++ b/pkg/controllers/netpol/network_policy_controller.go @@ -58,6 +58,7 @@ type NetworkPolicyController struct { MetricsEnabled bool v1NetworkPolicy bool readyForUpdates bool + healthChan chan<- *healthcheck.ControllerHeartbeat // list of all active network policies expressed as networkPolicyInfo networkPoliciesInfo *[]networkPolicyInfo @@ -140,6 +141,7 @@ func (npc *NetworkPolicyController) Run(healthChan chan<- *healthcheck.Controlle defer wg.Done() glog.Info("Starting network policy controller") + npc.healthChan = healthChan // loop forever till notified to stop on stopCh for { @@ -154,7 +156,7 @@ func (npc *NetworkPolicyController) Run(healthChan chan<- *healthcheck.Controlle err := npc.Sync() if err != nil { glog.Errorf("Error during periodic sync of network policies in network policy controller. Error: " + err.Error()) - glog.Errorf("Skipping sending heartbeat from network policy controller as periodic sync failed.") + return } else { healthcheck.SendHeartBeat(healthChan, "NPC") } @@ -222,6 +224,7 @@ func (npc *NetworkPolicyController) Sync() error { npc.mu.Lock() defer npc.mu.Unlock() + healthcheck.SendHeartBeat(npc.healthChan, "NPC") start := time.Now() syncVersion := strconv.FormatInt(start.UnixNano(), 10) defer func() { diff --git a/pkg/controllers/proxy/network_services_controller.go b/pkg/controllers/proxy/network_services_controller.go index 2bf4c18451..87793ad318 100644 --- a/pkg/controllers/proxy/network_services_controller.go +++ b/pkg/controllers/proxy/network_services_controller.go @@ -384,10 +384,11 @@ func (nsc *NetworkServicesController) Run(healthChan chan<- *healthcheck.Control case <-t.C: glog.V(1).Info("Performing periodic sync of ipvs services") + healthcheck.SendHeartBeat(healthChan, "NSC") err := nsc.doSync() if err != nil { glog.Errorf("Error during periodic ipvs sync in network service controller. Error: " + err.Error()) - glog.Errorf("Skipping sending heartbeat from network service controller as periodic sync failed.") + return nil } else { healthcheck.SendHeartBeat(healthChan, "NSC") }