Skip to content

Conversation

@vakalapa
Copy link
Contributor

@vakalapa vakalapa commented Oct 15, 2021

This PR consists of following changes:

Set Policies:

  1. Reset and initialize of Windows SetPolicies
  2. Add, update and delete events of SetPolicies

ACL Policies:

  1. Add, Update and Delete events of Set Policies

@vakalapa vakalapa added enhancement npm Related to NPM. labels Oct 15, 2021
for setName := range iMgr.toDeleteCache {
_, ok := iMgr.toAddOrUpdateCache[setName]
if ok {
delete(iMgr.toDeleteCache, setName)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do not delete but Log an error to make sure everything is working as expected

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

added nitpicks. might follow up after reading the rest

}
}

if !acl.checkIPSets() {
Copy link
Contributor

Choose a reason for hiding this comment

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

confused what checkIPSets is supposed to do since it looks at more than namedports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is checking if any of the unsupported translation features are used for ACL, if so we will ignore applying this policy

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess to clarify I'm confused why we return ErrNamedPortsNotSupported when the check looks at more than named ports

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

notes on policymanager

}

func (epBuilder *endpointPolicyBuilder) compareAndRemovePolicies(rulesToRemove []*NPMACLPolSettings) error {
lenOfRulesToRemove := len(rulesToRemove)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do this more efficiently? current runtime is O(R A^2) where R is # to remove and A is total # acls. Could also update next iteration

Copy link
Contributor

Choose a reason for hiding this comment

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

We could make it O(R A) w/ a linked list for the builder [O(1) removal], or O(R) w/ a set for the builder [O(1) removal and existence check]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Optimized it to be o(n) now, We will not be using unique ID for all policies, we can get away with using unique for a group of ACL generated from one network policy

}
}
}
if lenOfRulesToRemove > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

can just return an error if it doesn't exist in loop if we don't care about how many don't exist

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

notes on ipsetmanager

@vakalapa
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@huntergregory
Copy link
Contributor

when do we want to delete ipsets from our overall cache? Curious about the bolded situation below. For ApplyOnNeed ipset mode, should we remove the ipset from the overall cache if references become 0? Since creating an empty ipset basically costs the same as checking if it exists, I think we would work at the same speed with optimal memory usage. Also noticing that if we use the ApplyOnNeed mode, then we would never need to use a CreateIPSet() or DeleteIPSet() call.

the contract for DP around policies is:

  1. AddPolicy: for each TranslatedIPSet, we create the set (and any member sets) if it doesn't exist, keeping old members and adding any new members within the TranslatedIPSet
  2. RemovePolicy: for each TranslatedIPSet, we try to delete the set (and any member sets??); however, we won't delete a set if it's referenced anywhere (by other policies or other ipsets)

@vakalapa
Copy link
Contributor Author

@huntergregory As we discussed offline, i am inline with proactively deleting an IPSet when it has no references and no memebers. On a removeFromSets, RemoveFromLists call at the end, we can check for ipset.CanBeDeleted() and if yes add it to delete cache, Anyway when the controller needs this ipsets, it is going to either create, or our AddTo* calls will create ipset if needed.

@vakalapa vakalapa marked this pull request as ready for review October 26, 2021 23:08
@vakalapa vakalapa requested review from JungukCho and matmerr October 26, 2021 23:08
idx := 0
policySettingsOrder := []hcn.SetPolicyType{SetPolicyTypeNestedIPSet, hcn.SetPolicyTypeIpSet}
if operation == hcn.RequestTypeRemove {
policySettingsOrder = []hcn.SetPolicyType{hcn.SetPolicyTypeIpSet, SetPolicyTypeNestedIPSet}
Copy link
Contributor Author

@vakalapa vakalapa Oct 27, 2021

Choose a reason for hiding this comment

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

Add comments here

@huntergregory
Copy link
Contributor

when do we want to delete ipsets from our overall cache? Curious about the bolded situation below. For ApplyOnNeed ipset mode, should we remove the ipset from the overall cache if references become 0? Since creating an empty ipset basically costs the same as checking if it exists, I think we would work at the same speed with optimal memory usage. Also noticing that if we use the ApplyOnNeed mode, then we would never need to use a CreateIPSet() or DeleteIPSet() call.

the contract for DP around policies is:

  1. AddPolicy: for each TranslatedIPSet, we create the set (and any member sets) if it doesn't exist, keeping old members and adding any new members within the TranslatedIPSet
  2. RemovePolicy: for each TranslatedIPSet, we try to delete the set (and any member sets??); however, we won't delete a set if it's referenced anywhere (by other policies or other ipsets)

Update to delete from cache when we delete from kernel in another PR

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

looks good. Can we move some policy checks to generic pMgr? (noted in comments)

// or a single HNS rule in windows
type ACLPolicy struct {
// PolicyID is the rules name with a given network policy
// PolicyID will be same for all ACLs in a Network Policy
Copy link
Contributor

Choose a reason for hiding this comment

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

do we ever use this back-reference?

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 we are using this policyId in policymanager windows, to equate what policies are applied in HNS while updating or removing.

continue
}

epBuilder.compareAndRemovePolicies(rulesToRemove[0].Id, len(rulesToRemove))
Copy link
Contributor

Choose a reason for hiding this comment

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

just removing the first rule?

Copy link
Contributor

Choose a reason for hiding this comment

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

nevermind, I see that they all have the same ID. Perhaps pass in the whole rulesToRemove as an arg instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah i did that first, but there is no reason to send the whole rule set, we just need the ACl Id of one and since all the ACL IDs in a policy are same, we can get away with it. If tomorrow we do add unique ACl Ids then we can send in the full rulesToRemove obj

huntergregory
huntergregory previously approved these changes Oct 28, 2021
Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

🚀

@vakalapa vakalapa merged commit 9850758 into master Oct 28, 2021
@vakalapa vakalapa deleted the vakr/npmwindowslogic branch October 28, 2021 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement npm Related to NPM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants