Skip to content

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

Merged
antoninbas merged 1 commit into
antrea-io:mainfrom
hongliangl:20241001-fix-nnp
Oct 8, 2024
Merged

Fix issue with ipset or iptables chain removal during NodeNetworkPolicy updates or deletions#6707
antoninbas merged 1 commit into
antrea-io:mainfrom
hongliangl:20241001-fix-nnp

Conversation

@hongliangl
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
ipset := newLastRealized.ipsets[ipProtocol]

shouldUpdateCoreIPTRules := prevIPSet != ipset || prevIPNet != ipnet
// The name of ipset for a rule will not change during updates.
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 <hongliang.liu@broadcom.com>
Copy link
Copy Markdown
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
Copy Markdown
Contributor

/test-kind-all

@antoninbas antoninbas merged commit 2722184 into antrea-io:main Oct 8, 2024
@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 <hongliang.liu@broadcom.com>
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 <hongliang.liu@broadcom.com>
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 <hongliang.liu@broadcom.com>
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 <hongliang.liu@broadcom.com>
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 <hongliang.liu@broadcom.com>
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 <hongliang.liu@broadcom.com>
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 <hongliang.liu@broadcom.com>
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