-
Notifications
You must be signed in to change notification settings - Fork 260
fix: [NPM] disable v2 CLI & polish linux policy manager #1241
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,34 @@ import ( | |
| ) | ||
|
|
||
| const ( | ||
| maxTryCount = 1 | ||
| unknownLineErrorPattern = "line (\\d+) failed" // TODO this could happen if syntax is off or AZURE-NPM-INGRESS doesn't exist for -A AZURE-NPM-INGRESS -j hash(NP1) ... | ||
| knownLineErrorPattern = "Error occurred at line: (\\d+)" | ||
|
|
||
| chainSectionPrefix = "chain" // TODO are sections necessary for error handling? | ||
| maxLengthForMatchSetSpecs = 6 // 5-6 elements depending on Included boolean | ||
| maxTryCount = 2 | ||
| // the error message doesn't describe the error if this pattern is within the message | ||
| // this could happen if syntax is off or AZURE-NPM-INGRESS doesn't exist for -A AZURE-NPM-INGRESS -j hash(NP1) ... | ||
| unknownLineErrorPattern = "line (\\d+) failed" | ||
| // the error message describes the error if this pattern is within the message | ||
| knownLineErrorPattern = "Error occurred at line: (\\d+)" | ||
|
|
||
| chainSectionPrefix = "chain" | ||
| ) | ||
|
|
||
| /* | ||
| Error handling for iptables-restore: | ||
| Currently we retry on any error and will make two tries max. | ||
| The section IDs and line error patterns are pointless currently. Although we can eventually use them to skip a section with an error and salvage the rest of the file. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can you reduce this oneline into two, its too long.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressing in followup PR |
||
|
|
||
| Known errors that we should retry on: | ||
| - exit status 4 | ||
| - iptables: Resource temporarily unavailable. | ||
| - fork/exec /usr/sbin/iptables: resource temporarily unavailable | ||
| - Another app is currently holding the xtables lock; still 51s 0us time ahead to have a chance to grab the lock... | ||
| Another app is currently holding the xtables lock; still 41s 0us time ahead to have a chance to grab the lock... | ||
| Another app is currently holding the xtables lock; still 31s 0us time ahead to have a chance to grab the lock... | ||
| Another app is currently holding the xtables lock; still 21s 0us time ahead to have a chance to grab the lock... | ||
| Another app is currently holding the xtables lock; still 11s 0us time ahead to have a chance to grab the lock... | ||
| Another app is currently holding the xtables lock; still 1s 0us time ahead to have a chance to grab the lock... | ||
| Another app is currently holding the xtables lock. Stopped waiting after 60s. | ||
| */ | ||
|
|
||
| func (pMgr *PolicyManager) addPolicy(networkPolicy *NPMNetworkPolicy, _ map[string]string) error { | ||
| // 1. Add rules for the network policies and activate NPM (if necessary). | ||
| chainsToCreate := chainNames([]*NPMNetworkPolicy{networkPolicy}) | ||
|
|
@@ -117,7 +137,7 @@ func (pMgr *PolicyManager) newCreatorWithChains(chainNames []string) *ioutil.Fil | |
| sectionID := joinWithDash(chainSectionPrefix, chainName) | ||
| counters := "-" | ||
| creator.AddLine(sectionID, nil, ":"+chainName, "-", counters) | ||
| // TODO remove sections?? | ||
| // TODO remove sections if we never use section-based error handling (e.g. remove the whole section) | ||
| } | ||
| return creator | ||
| } | ||
|
|
@@ -154,10 +174,9 @@ func (pMgr *PolicyManager) deleteJumpRule(policy *NPMNetworkPolicy, direction Un | |
|
|
||
| specs = append([]string{baseChainName}, specs...) | ||
| errCode, err := pMgr.runIPTablesCommand(util.IptablesDeletionFlag, specs...) | ||
| if err != nil && errCode != couldntLoadTargetErrorCode { | ||
| // TODO check rule doesn't exist error code instead because the chain should exist | ||
| if err != nil && errCode != doesNotExistErrorCode { | ||
| errorString := fmt.Sprintf("failed to delete jump from %s chain to %s chain for policy %s with exit code %d", baseChainName, chainName, policy.PolicyKey, errCode) | ||
| log.Errorf(errorString+": %w", err) | ||
| log.Errorf("%s: %w", errorString, err) | ||
| return npmerrors.SimpleErrorWrapper(errorString, err) | ||
| } | ||
| return nil | ||
|
|
@@ -264,13 +283,7 @@ func matchSetSpecsForNetworkPolicy(networkPolicy *NPMNetworkPolicy, matchType Ma | |
| specs := make([]string, 0, maxLengthForMatchSetSpecs*len(networkPolicy.PodSelectorList)) | ||
| matchString := matchType.toIPTablesString() | ||
| for _, setInfo := range networkPolicy.PodSelectorList { | ||
| // TODO consolidate this code with that in matchSetSpecsFromSetInfo | ||
| specs = append(specs, util.IptablesModuleFlag, util.IptablesSetModuleFlag) | ||
| if !setInfo.Included { | ||
| specs = append(specs, util.IptablesNotFlag) | ||
| } | ||
| hashedSetName := setInfo.IPSet.GetHashedName() | ||
| specs = append(specs, util.IptablesMatchSetFlag, hashedSetName, matchString) | ||
| specs = append(specs, setInfo.matchSetSpecs(matchString)...) | ||
| } | ||
| return specs | ||
| } | ||
|
|
@@ -279,12 +292,7 @@ func matchSetSpecsFromSetInfo(setInfoList []SetInfo) []string { | |
| specs := make([]string, 0, maxLengthForMatchSetSpecs*len(setInfoList)) | ||
| for _, setInfo := range setInfoList { | ||
| matchString := setInfo.MatchType.toIPTablesString() | ||
| specs = append(specs, util.IptablesModuleFlag, util.IptablesSetModuleFlag) | ||
| if !setInfo.Included { | ||
| specs = append(specs, util.IptablesNotFlag) | ||
| } | ||
| hashedSetName := setInfo.IPSet.GetHashedName() | ||
| specs = append(specs, util.IptablesMatchSetFlag, hashedSetName, matchString) | ||
| specs = append(specs, setInfo.matchSetSpecs(matchString)...) | ||
| } | ||
| return specs | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we need to disable GetCache for V2, this is useful irrespective of debug CLI.
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.
currently the cache is buggy for v2. Let's fix this in another PR