Skip to content

Conversation

@huntergregory
Copy link
Contributor

redesign iptables flow for NPM and add/remove ACLs in batch OS calls

TODO in next iteration:

  • remove dead policy chains in background thread
  • retry logic (abort adding a chain if there are errors)

InitializeNPMChains, RemoveNPMChains, and ReconcileChains

WIP

fix compile errors in composer

WIP

UTs and finished but no retry logic yet

assert equal file strings

remove unused stuff

func to test equality of translatedipsets

UTs

final adds
@huntergregory
Copy link
Contributor Author

We have to think how to redesign UTs for generic policy/ipsetmanager since the fakeexec calls will be specific to the OS. This PR fails the generic pMgr UTs currently.

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.

initial comments

@vakalapa vakalapa added enhancement npm Related to NPM. labels Oct 25, 2021
return nil
}

func checkForErrors(networkPolicies ...*NPMNetworkPolicy) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great, i can a OSSpecific function inside this to see if acl policy supports a certain feature.

Copy link
Contributor

@JungukCho JungukCho left a comment

Choose a reason for hiding this comment

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

Great PR and left some comments. Excited to test end-to-end later with new translation and linux dataplane.

One impression is that structures and files in policy package are slightly complex to manage linux and windows. It may be due to less time for me to read policy packages. Also I did not walk through codes related to windows in policy package in details.

// parseChainNameFromRuleLine gets the chain name from given rule line.
func parseChainNameFromRuleLine(ruleLine []byte) (string, int) {
// GetChainNameFromRuleLine gets the chain name from given rule line.
func GetChainNameFromRuleLine(ruleLine []byte) (chainName string, ruleReadIndex int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: for consistency parseChainNameFromRuleLine is better?
I thought since the package name is parse, we can ideally drop all parse- prefix in the functions while it is not scope of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will revert it to the old name for now (unexported since we don't need it elsewhere), but golint complains about stuttering when you have parse.ParseChain...

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I prefer dropping all "Parse-" prefix in the code with the same reasons. If you are ok and it does not require heavy change, we can drop it in this PR or put it in a next small PR. It's up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll drop for this PR

DstSrcMatch MatchType = 5
)

func (policy *ACLPolicy) hasKnownDirection() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: would we put these receiver functions close to ACLPolicy strcut definition?
Also, may just use (aclp (or ap) *ACLPolicy) instead of (policy *ACLPolicy)? While all functions are very small, there are another policy here - NPMNetworkPolicy. So, explicitly use some prefixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rearranged these. Let me know if you have any suggestions

IptablesAzureEgressToPodChain string = "AZURE-NPM-EGRESS-TO-POD"

// Below are the skb->mark NPM will use for different criteria
IptablesAzureClearMarkHex string = "0x0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: now there are multiple dataplanes. So, is it better to these specific const variables in specific dataplane for better maintanance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea. Update in another PR?

Copy link
Contributor

@JungukCho JungukCho left a comment

Choose a reason for hiding this comment

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

Put minor comments and they can be revised in your next PR if they make sense.


// will make a similar func for on update eventually
func (pMgr *PolicyManager) deleteOldJumpRulesOnRemove(policy *NPMNetworkPolicy) error {
fmt.Println(policy.ACLs[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: forget removing this one?

fmt.Println(policy.ACLs[0])

shouldDeleteIngress, shouldDeleteEgress := policy.hasIngressAndEgress()
fmt.Println(shouldDeleteIngress, shouldDeleteEgress)
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: forget removing this one?


// add AZURE-NPM chain rules
creator.AddLine("", nil, util.IptablesAppendFlag, util.IptablesAzureChain, util.IptablesJumpFlag, util.IptablesAzureIngressChain)

Copy link
Contributor

Choose a reason for hiding this comment

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

nitPick: remove unneeded newlines in this function if there is no specific reason.

@huntergregory huntergregory merged commit 5490a9f into master Oct 29, 2021
@vakalapa vakalapa deleted the linux-ACL-rules-squash-merge branch October 29, 2021 22:03
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.

4 participants