Skip to content

Conversation

@huntergregory
Copy link
Contributor

@huntergregory huntergregory commented Jan 8, 2022

Adds a go-routine for policy manager reconciling, which:

  1. adds the jump from AZURE-NPM to FORWARD chain
  2. deletes stale chains

Lock stale chains when:

  • modifying the stale chains cache
  • deleting chains that were in staleChains (in reconcile())
  • adding policy chains/rules via iptables-restore in case a chain is in staleChains

As an optimization, policy manager can "force lock" staleChains, which pauses stale chain deletion until next reconcile period.

@huntergregory huntergregory added the npm Related to NPM. label Jan 12, 2022

// 3. Delete policy chains in the background.
// lock here since stale chains are only affected if we successfully remove policies
pMgr.staleChains.forceLock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. calculate creator:
  2. acquire reconcileLock (stalechain lock )
  3. Delete jump rules
  4. restore

*ipsets.IPSetManagerCfg
*policies.PolicyManagerCfg
// helpful for UTs (defaults to false for external packages)
disableGoRoutines bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename this to something like concurrencyEnabled or concurrencyDisabled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at what it does below - maybe something like disableReconcile?

Comment on lines 73 to 75
if !dp.disableGoRoutines {
dp.policyMgr.Reconcile(dp.stopChannel)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if this is disabled we're not running reconcile at all? 😕 or am I misunderstanding this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is just for unit testing because we test exec calls, and don't want to intermingle exec calls from reconciling with other exec calls

pMgr.reconcileManager.Lock()
defer pMgr.reconcileManager.Unlock()
start <- struct{}{}
require.NoError(t, pMgr.cleanupChains(testChains))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for cleanupChains function can we move

errCode, err := pMgr.runIPTablesCommand(util.IptablesDestroyFlag, chain)
if err != nil && errCode != doesNotExistErrorCode {
// add to staleChains if it's not one of the iptablesAzureChains
pMgr.staleChains.add(chain)
currentErrString := fmt.Sprintf("failed to clean up chain %s with err [%v]", chain, err)
if aggregateError == nil {
aggregateError = npmerrors.SimpleError(currentErrString)
} else {
aggregateError = npmerrors.SimpleErrorWrapper(fmt.Sprintf("%s and had previous error", currentErrString), aggregateError)
}
}
to the default case in the select loop above it?


func main() {
dp, err := dataplane.NewDataPlane(nodeName, common.NewIOShim(), dpCfg)
dp, err := dataplane.NewDataPlane(nodeName, common.NewIOShim(), dpCfg, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to keep the stop channel nil? Can we pass a legit channel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason. I can do that

Copy link
Contributor

@nitishm nitishm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionality wise I think it LGTM. But I have some nits and comments/questions

return nil, err
}
// necessary for UTs because of ioshim
if !dp.disableReconcileForUTs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call it disableReconcile, and if needed we can make this as a toggle tomorrow to stop if required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we remove this flag, and move reconcile to a function called RunDPTasks, and call RunDPTasks in relevant place after newDP is created ? We can skip running this for UTs, and in main.go we can call dp.RunDPTasks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this flag and created a dp.RunPeriodicTasks()

Copy link
Contributor

@vakalapa vakalapa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work ! 💯

Copy link
Contributor

@nitishm nitishm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@huntergregory huntergregory merged commit 3d1e739 into master Jan 19, 2022
@huntergregory huntergregory deleted the call-reconcile-in-dp branch January 19, 2022 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

npm Related to NPM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants