Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,19 @@ func (npMgr *NetworkPolicyManager) restore() {
}

// backup takes snapshots of iptables filter table and saves it periodically.
func (npMgr *NetworkPolicyManager) backup() {
func (npMgr *NetworkPolicyManager) backup(stopCh <-chan struct{}) {
iptMgr := iptm.NewIptablesManager()
var err error
for {
time.Sleep(backupWaitTimeInSeconds * time.Second)
ticker := time.NewTicker(time.Second * time.Duration(backupWaitTimeInSeconds))
defer ticker.Stop()

if err = iptMgr.Save(util.IptablesConfigFile); err != nil {
metrics.SendErrorLogAndMetric(util.NpmID, "Error: failed to back up Azure-NPM states %s", err.Error())
for {
select {
case <-stopCh:
return
case <-ticker.C:
if err := iptMgr.Save(util.IptablesConfigFile); err != nil {
metrics.SendErrorLogAndMetric(util.NpmID, "Error: failed to back up Azure-NPM states %s", err.Error())
}
}
}
}
Expand Down Expand Up @@ -194,8 +199,8 @@ func (npMgr *NetworkPolicyManager) Start(stopCh <-chan struct{}) error {
go npMgr.podController.Run(threadness, stopCh)
go npMgr.nameSpaceController.Run(threadness, stopCh)
go npMgr.netPolController.Run(threadness, stopCh)
go npMgr.reconcileChains()
go npMgr.backup()
go npMgr.reconcileChains(stopCh)
go npMgr.backup(stopCh)

return nil
}
Expand Down Expand Up @@ -280,13 +285,19 @@ func NewNetworkPolicyManager(clientset *kubernetes.Clientset, informerFactory in
}

// reconcileChains checks for ordering of AZURE-NPM chain in FORWARD chain periodically.
func (npMgr *NetworkPolicyManager) reconcileChains() error {
func (npMgr *NetworkPolicyManager) reconcileChains(stopCh <-chan struct{}) {
iptMgr := iptm.NewIptablesManager()
select {
case <-time.After(reconcileChainTimeInMinutes * time.Minute):
if err := iptMgr.CheckAndAddForwardChain(); err != nil {
return err
ticker := time.NewTicker(time.Minute * time.Duration(reconcileChainTimeInMinutes))
defer ticker.Stop()

for {
select {
case <-stopCh:
return
case <-ticker.C:
if err := iptMgr.CheckAndAddForwardChain(); err != nil {
metrics.SendErrorLogAndMetric(util.NpmID, "Error: failed to reconcileChains Azure-NPM due to %s", err.Error())
}
}
}
return nil
}