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

Support NodePortLocal on Antrea Windows Agent and Update NPL annotation #3453

Merged
merged 6 commits into from
May 31, 2022

Conversation

XinShuYang
Copy link
Contributor

  • Support NodePortLocal rules on by using NetNatStaticMapping on windows
  • Support NPL agent on Windows platform
  • Require the same Antrea NPL configuration as Linux

Signed-off-by: Shuyang Xin gavinx@vmware.com

@XinShuYang XinShuYang requested a review from wenyingd March 16, 2022 05:55
@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2022

Codecov Report

Merging #3453 (a377b57) into main (58f17de) will decrease coverage by 4.83%.
The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3453      +/-   ##
==========================================
- Coverage   62.20%   57.37%   -4.84%     
==========================================
  Files         281      398     +117     
  Lines       40096    55954   +15858     
==========================================
+ Hits        24941    32102    +7161     
- Misses      13190    21351    +8161     
- Partials     1965     2501     +536     
Flag Coverage Δ
e2e-tests 46.16% <60.00%> (?)
integration-tests 38.20% <ø> (?)
kind-e2e-tests 53.11% <60.00%> (+5.12%) ⬆️
unit-tests 43.92% <20.63%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/agent/nodeportlocal/k8s/annotations.go 100.00% <ø> (+15.55%) ⬆️
pkg/agent/nodeportlocal/npl_agent_init.go 57.14% <ø> (ø)
pkg/features/antrea_features.go 11.11% <ø> (ø)
.../agent/nodeportlocal/portcache/port_table_linux.go 57.69% <57.69%> (ø)
pkg/agent/util/net.go 54.97% <66.66%> (+3.42%) ⬆️
pkg/agent/nodeportlocal/portcache/port_table.go 67.50% <75.00%> (+7.23%) ⬆️
pkg/agent/nodeportlocal/k8s/npl_controller.go 61.12% <100.00%> (-0.10%) ⬇️
pkg/agent/nodeportlocal/rules/iptable_rule.go 55.78% <100.00%> (+1.44%) ⬆️
pkg/agent/openflow/client.go 70.28% <100.00%> (+0.90%) ⬆️
pkg/agent/openflow/pipeline.go 74.16% <100.00%> (+0.54%) ⬆️
... and 170 more

@XinShuYang XinShuYang force-pushed the npl branch 12 times, most recently from c302ab1 to 75c12d5 Compare March 22, 2022 07:52
@XinShuYang
Copy link
Contributor Author

/test-e2e

@XinShuYang XinShuYang force-pushed the npl branch 3 times, most recently from 2764a37 to 720288a Compare April 1, 2022 05:02
@XinShuYang
Copy link
Contributor Author

/test-windows-all

@XinShuYang
Copy link
Contributor Author

/test-windows-e2e

@@ -18,28 +18,31 @@
package nodeportlocal
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 still need this file? it seems to be pretty much the same as npl_agent_init.go now. I think you just need to remove the //go:build !windows tag in npl_agent_init.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks.

Comment on lines 24 to 40
// PrepareAddRule closes socket on Windows before inserting NetNatStaticMapping rules.
func PrepareAddRule(protocolSocketData *ProtocolSocketData) error {
if err := protocolSocketData.socket.Close(); err != nil {
return fmt.Errorf("Windows socket close failed %v", err)
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems quite hacky to me.
On Linux, we open a socket to ensure that the port is reserved for this specific mapping, as otherwise it would be possible for another process to use the port (the DNAT iptables rule doesn't "reserve" the port).
If on Windows, inserting a NetNatStaticMapping rule means that the port cannot be used by any other process, then there is no need to open a socket at all.
I don't know if it is exactly the same thing, but the inspiration from this comes from the kube-proxy iptables & IPVS implementations, which open a socket to reserve ports. However, there is no equivalent for the kube-proxy winkernel implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@antoninbas NPL will try to listen to a port during getting free port stage.The reason to reserve the port is to make sure the free port is avaliable until inserting NetNatStaticMapping rules. Otherwise other processes are more likely to occupy the allocated port in advance, which causes the rule insertion to fail. I also had an discussion about this implementation with Wenying, @wenyingd do you have other comments here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand. I would say that if the NetNatStaticMapping rule insertion fails, you just need to try with the next port, and so on. This is not so different from trying to open a socket first: if the port is not available, it will fail, and we try with the next port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If NetNatStaticMapping insertion fails, the reason is not necessarily that the port is invalid. But if the port can be listened and NetNatStaticMapping insertion still fails we can make troubleshooting easier.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, we cannot know the reason after NetNatStaticMapping fails? I also feel creating a socket is not worthwhile.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree to create NetNatStaticMapping directly to for a free port chosen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for all comments. After discussion I agree it is not necessary to open socket in Windows. The result of rule insertion/deletion can be used by port reservation. PR updated.

@XinShuYang XinShuYang force-pushed the npl branch 2 times, most recently from 66ce016 to edeb9bd Compare April 6, 2022 02:26
@XinShuYang
Copy link
Contributor Author

/test-windows-e2e

@XinShuYang
Copy link
Contributor Author

/test-integration

1 similar comment
@XinShuYang
Copy link
Contributor Author

/test-integration

@lgtm-com
Copy link

lgtm-com bot commented May 24, 2022

This pull request introduces 1 alert and fixes 1 when merging 4ead74e into 7487453 - view on LGTM.com

new alerts:

  • 1 for Incorrect conversion between integer types

fixed alerts:

  • 1 for Incorrect conversion between integer types

@antoninbas
Copy link
Contributor

Hi Antonin, thanks for the new comments. Wenying and I also agreed that we should set the unified implementation as our ultimate goal. But we’d like to only introduce windows function and preserve Linux legacy behavior in this PR for Antrea1.7 because we may not have enough time for development and full verification. If you agree I can build another PR to implement final unified code in next release. What do you think? @antoninbas Other comments has been addressed.

It feels to me that we are not preserving exactly the Linux legacy behavior though: while we are still allocating the same nodePort value for UDP & TCP when the podPort is the same, we are now generating 2 distinct Pod annotations instead of 1. Given this change, I think it would have been ok to unify the implementations from the get-go. That being said, if you prefer to do it in a follow-up PR, that's fine by me.

@XinShuYang
Copy link
Contributor Author

XinShuYang commented May 25, 2022

It feels to me that we are not preserving exactly the Linux legacy behavior though: while we are still allocating the same nodePort value for UDP & TCP when the podPort is the same, we are now generating 2 distinct Pod annotations instead of 1. Given this change, I think it would have been ok to unify the implementations from the get-go. That being said, if you prefer to do it in a follow-up PR, that's fine by me.

@antoninbas Thanks, the "legacy behavior" I mentioned does mean that allocating the same nodePort value when the podPort is the same, and annotation format is the same for both Linux and Windows.
I have created an issue to follow all related features, and will build another pr for unified implementation.
#3826
Do you have more comments?

@lgtm-com
Copy link

lgtm-com bot commented May 25, 2022

This pull request introduces 1 alert and fixes 1 when merging b699ba2 into 9425c61 - view on LGTM.com

new alerts:

  • 1 for Incorrect conversion between integer types

fixed alerts:

  • 1 for Incorrect conversion between integer types

antoninbas
antoninbas previously approved these changes May 25, 2022
@tnqn
Copy link
Member

tnqn commented May 26, 2022

@XinShuYang could you resolve conflict so we can merge?

@lgtm-com
Copy link

lgtm-com bot commented May 29, 2022

This pull request introduces 1 alert and fixes 1 when merging e35ac0c into 58f17de - view on LGTM.com

new alerts:

  • 1 for Incorrect conversion between integer types

fixed alerts:

  • 1 for Incorrect conversion between integer types

@XinShuYang
Copy link
Contributor Author

/test-all
/test-windows-all

@XinShuYang
Copy link
Contributor Author

@tnqn Updated, thanks.

@tnqn
Copy link
Member

tnqn commented May 30, 2022

@wenyingd could you confirm code is expected after rebasing? I will merge it with your approval.

@tnqn
Copy link
Member

tnqn commented May 30, 2022

/test-integration

Copy link
Contributor

@wenyingd wenyingd left a comment

Choose a reason for hiding this comment

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

overall LGTM, one minor comment.

@@ -36,6 +38,8 @@ const (

FamilyIPv4 uint8 = 4
FamilyIPv6 uint8 = 6

AntreaNatName = "antrea-nat"
Copy link
Contributor

Choose a reason for hiding this comment

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

Move it to net_windows.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks.

* Support NodePortLocal rules on by using NetNatStaticMapping on windows
* Support NPL agent on Windows platform
* Require the same Antrea NPL configuration as Linux

issue antrea-io#3826

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
Currently mutateAntreaConfigMap can only support linux agent configmap.
This patch will support windows configmap processing.

issue antrea-io#3826

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
Add related image to support more e2e tests on windows.

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
* Add NPL Netnat rules check on windows
* Replace busybox with agnhost as the client pod
* Still skip windows test by default due to the ovs HNSCall issue

issue antrea-io#3826

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
* Add protocol string to new NPLAnnotation set the protocols map as a deprecated value.
* Support Node port for UDP and TCP using the different number for a single Pod on Windows.

issue antrea-io#3826

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
* Update annotation example with new protocol field.
* Update NPL windows support feature.

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
@XinShuYang
Copy link
Contributor Author

/test-all
/test-windows-all

Copy link
Contributor

@wenyingd wenyingd left a comment

Choose a reason for hiding this comment

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

LGTM

@lgtm-com
Copy link

lgtm-com bot commented May 30, 2022

This pull request introduces 1 alert and fixes 1 when merging a377b57 into f8559ec - view on LGTM.com

new alerts:

  • 1 for Incorrect conversion between integer types

fixed alerts:

  • 1 for Incorrect conversion between integer types

@XinShuYang
Copy link
Contributor Author

/test-windows-networkpolicy
/test-conformance
/test-windows-proxyall-e2e
/test-all-features-conformance
/test-e2e

@XinShuYang
Copy link
Contributor Author

/test-conformance

1 similar comment
@XinShuYang
Copy link
Contributor Author

/test-conformance

@tnqn tnqn merged commit 87918f6 into antrea-io:main May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes. area/proxy/nodeportlocal Issues or PRs related to the NodePortLocal feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants