Skip to content

Commit

Permalink
Send heartbeats during NetworkPolicy and NetworkService sync.
Browse files Browse the repository at this point in the history
In reference to issue cloudnativelabs#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 <[email protected]>
  • Loading branch information
danboucher78 authored and ticpu committed May 31, 2019
1 parent 6470795 commit f5188e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/controllers/netpol/network_policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit f5188e5

Please sign in to comment.