-
Notifications
You must be signed in to change notification settings - Fork 260
feat: [NPM] call policy reconcile in dataplane #1188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| // 3. Delete policy chains in the background. | ||
| // lock here since stale chains are only affected if we successfully remove policies | ||
| pMgr.staleChains.forceLock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- calculate creator:
- acquire reconcileLock (stalechain lock )
- Delete jump rules
- restore
npm/pkg/dataplane/dataplane.go
Outdated
| *ipsets.IPSetManagerCfg | ||
| *policies.PolicyManagerCfg | ||
| // helpful for UTs (defaults to false for external packages) | ||
| disableGoRoutines bool |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
npm/pkg/dataplane/dataplane.go
Outdated
| if !dp.disableGoRoutines { | ||
| dp.policyMgr.Reconcile(dp.stopChannel) | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
azure-container-networking/npm/pkg/dataplane/policies/chain-management_linux.go
Lines 227 to 237 in fea8283
| 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) | |
| } | |
| } |
default case in the select loop above it?
test/integration/npm/main.go
Outdated
|
|
||
| func main() { | ||
| dp, err := dataplane.NewDataPlane(nodeName, common.NewIOShim(), dpCfg) | ||
| dp, err := dataplane.NewDataPlane(nodeName, common.NewIOShim(), dpCfg, nil) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
nitishm
left a comment
There was a problem hiding this 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
npm/pkg/dataplane/dataplane.go
Outdated
| return nil, err | ||
| } | ||
| // necessary for UTs because of ioshim | ||
| if !dp.disableReconcileForUTs { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
vakalapa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work ! 💯
nitishm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adds a go-routine for policy manager reconciling, which:
Lock stale chains when:
staleChains(inreconcile())staleChainsAs an optimization, policy manager can "force lock"
staleChains, which pauses stale chain deletion until next reconcile period.