Skip to content
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

Fix issue with ipset or iptables chain removal during NodeNetworkPolicy updates or deletions #6707

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

hongliangl
Copy link
Contributor

@hongliangl hongliangl commented Sep 30, 2024

Fix #6706

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

@hongliangl hongliangl changed the title Fix that when destroying ipset when updating NodeNetworkPolicy Fix that when destroying ipset when updating/deleting NodeNetworkPolicy Sep 30, 2024
@hongliangl hongliangl added this to the Antrea v2.2 release milestone Sep 30, 2024
@hongliangl hongliangl added action/backport Indicates a PR that requires backports. action/release-note Indicates a PR that should be included in release notes. labels Sep 30, 2024
@antoninbas
Copy link
Contributor

@hongliangl please fix the commit title / PR title (it's not a correct sentence), and add a commit message that explains what the issue was and what your change is doing.

@hongliangl
Copy link
Contributor Author

@hongliangl please fix the commit title / PR title (it's not a correct sentence), and add a commit message that explains what the issue was and what your change is doing.

Will do.

@hongliangl hongliangl changed the title Fix that when destroying ipset when updating/deleting NodeNetworkPolicy Fix issue with ipset or iptables chain removal during NodeNetworkPolicy updates or deletions Sep 30, 2024
@@ -442,19 +442,35 @@ func (r *nodeReconciler) update(lastRealized *nodePolicyLastRealized, newRule *C
ipnet := newLastRealized.ipnets[ipProtocol]
prevIPSet := lastRealized.ipsets[ipProtocol]
ipset := newLastRealized.ipsets[ipProtocol]

shouldUpdateCoreIPTRules := prevIPSet != ipset || prevIPNet != ipnet
// The name of ipset for a rule will not change during updates.
Copy link
Contributor

Choose a reason for hiding this comment

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

is that why the case where ipset != "" && prevIPSet != "" && ipset != prevIPSet is not possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. Here are the cases:

  • Single IP change: A -> B (prevIPSet = "", ipset = "", prevIPNet = A, ipnet = B).
  • Transition from multiple addresses to a single IP: {A, B} -> A (prevIPSet = "ipset name", ipset = "", prevIPNet = "", ipnet = A).
  • Transition from a single IP to multiple addresses: A -> {A, B} (prevIPNet = A, ipnet = "", prevIPSet = "", ipset = "ipset name").

Copy link
Member

Choose a reason for hiding this comment

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

The ipset name is based on the rule ID, which determines that it will not change for a given rule.

s2p1 := mockRouteClient.DeleteNodeNetworkPolicyIPTables([]string{"ANTREA-POL-INGRESSRULE1"}, false).Times(1)
s2p2 := mockRouteClient.DeleteNodeNetworkPolicyIPSet("ANTREA-POL-INGRESSRULE1-4", false)
s2p3 := mockRouteClient.AddOrUpdateNodeNetworkPolicyIPTables([]string{"ANTREA-POL-INGRESS-RULES"}, [][]string{nil}, false).Times(1)
s1p2.After(s1p1)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any chance that we can use gomock.InOrder for those? Maybe not because of the last one (s2p3.After(s1p2))?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gomock.InOrder is a great way for these test cases! It can be used to optimize all the existing test cases.

@hongliangl hongliangl force-pushed the 20241001-fix-nnp branch 2 times, most recently from 58ceb7a to 56c8285 Compare October 8, 2024 04:35
…cy updates or deletions

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

Signed-off-by: Hongliang Liu <[email protected]>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

@antoninbas
Copy link
Contributor

/test-kind-all

@antoninbas antoninbas merged commit 2722184 into antrea-io:main Oct 8, 2024
54 of 62 checks passed
@hongliangl hongliangl deleted the 20241001-fix-nnp branch October 9, 2024 01:58
hongliangl added a commit to hongliangl/antrea that referenced this pull request Oct 9, 2024
…cy updates or deletions (antrea-io#6707)

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

Signed-off-by: Hongliang Liu <[email protected]>
hongliangl added a commit to hongliangl/antrea that referenced this pull request Oct 9, 2024
…cy updates or deletions (antrea-io#6707)

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

Signed-off-by: Hongliang Liu <[email protected]>
hongliangl added a commit to hongliangl/antrea that referenced this pull request Oct 9, 2024
…cy updates or deletions (antrea-io#6707)

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

Signed-off-by: Hongliang Liu <[email protected]>
tnqn pushed a commit that referenced this pull request Oct 9, 2024
…cy updates or deletions (#6707) (#6728)

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

Signed-off-by: Hongliang Liu <[email protected]>
tnqn pushed a commit that referenced this pull request Oct 9, 2024
…cy updates or deletions (#6707) (#6727)

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

Signed-off-by: Hongliang Liu <[email protected]>
tnqn pushed a commit that referenced this pull request Oct 9, 2024
…cy updates or deletions (#6707) (#6726)

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

Signed-off-by: Hongliang Liu <[email protected]>
hangyan pushed a commit to hangyan/antrea that referenced this pull request Oct 29, 2024
…cy updates or deletions (antrea-io#6707)

This commit addresses an issue where stale ipset or iptables chain is
not deleted during NodeNetworkPolicy updates or deletions. The root cause
is that the ipset or iptables chain is still referenced by other iptables
rules during the deletion or update attempt. The fix ensures proper order
of ipset and iptables synchronization.

Signed-off-by: Hongliang Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/backport Indicates a PR that requires backports. action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error destroying ipset when deleting NodeNetworkPolicy
3 participants