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

Avoid allocating NPL port if Host Port is defined #2024

Merged
merged 1 commit into from
Apr 8, 2021
Merged

Avoid allocating NPL port if Host Port is defined #2024

merged 1 commit into from
Apr 8, 2021

Conversation

annakhm
Copy link
Contributor

@annakhm annakhm commented Apr 2, 2021

When Host Port is defined, use same port in NPL annotation, without
reserving port from NPL port range. Avoid adding redundant IP table
entry in NPL code.

@codecov-io
Copy link

codecov-io commented Apr 2, 2021

Codecov Report

Merging #2024 (0ce60c2) into main (9097932) will increase coverage by 7.13%.
The diff coverage is 14.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2024      +/-   ##
==========================================
+ Coverage   55.20%   62.33%   +7.13%     
==========================================
  Files         268      268              
  Lines       20237    20241       +4     
==========================================
+ Hits        11172    12618    +1446     
+ Misses       7873     6315    -1558     
- Partials     1192     1308     +116     
Flag Coverage Δ
e2e-tests 24.49% <0.00%> (?)
kind-e2e-tests 51.70% <14.28%> (+10.75%) ⬆️
unit-tests 41.56% <0.00%> (+0.04%) ⬆️

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

Impacted Files Coverage Δ
pkg/agent/nodeportlocal/k8s/npl_controller.go 59.21% <14.28%> (-0.95%) ⬇️
pkg/agent/route/route_linux.go 42.69% <0.00%> (+0.29%) ⬆️
pkg/agent/cniserver/server.go 68.91% <0.00%> (+0.32%) ⬆️
pkg/agent/controller/networkpolicy/cache.go 85.29% <0.00%> (+0.65%) ⬆️
pkg/controller/grouping/group_entity_index.go 94.58% <0.00%> (+1.27%) ⬆️
pkg/apiserver/storage/ram/store.go 81.95% <0.00%> (+1.50%) ⬆️
pkg/agent/agent.go 48.92% <0.00%> (+1.67%) ⬆️
pkg/agent/controller/networkpolicy/reconciler.go 76.81% <0.00%> (+1.87%) ⬆️
pkg/agent/flowexporter/connections/connections.go 78.32% <0.00%> (+2.09%) ⬆️
pkg/ovs/ovsconfig/ovs_client.go 51.73% <0.00%> (+2.24%) ⬆️
... and 73 more

Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

some nits, otherwise LGTM

@@ -370,6 +370,24 @@ func TestPodAddMultiPort(t *testing.T) {
assert.True(t, testData.portTable.RuleExists(defaultPodIP, newPort))
}

// TestPodAdHostPort creates a Pod with host ports and verifies that the Pod's NPL annotation
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: s/TestPodAdHostPort/TestPodAddHostPort

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, done

if err != nil {
return fmt.Errorf("failed to add rule for Pod %s: %v", key, err)
if int(cport.HostPort) > 0 {
klog.V(2).Infof("Host Port is defined for Pod, thus extra NPL port is not allocated: %s", key)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this should be V(4)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
return fmt.Errorf("failed to add rule for Pod %s: %v", key, err)
if int(cport.HostPort) > 0 {
klog.V(2).Infof("Host Port is defined for Pod, thus extra NPL port is not allocated: %s", key)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a bit more context is needed in the log message (e.g. the container port), since a Pod can have multiple containers, with multiple ports, and hostPort is specific to a given 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.

Added container name

jianjuns
jianjuns previously approved these changes Apr 5, 2021
Copy link
Contributor

@jianjuns jianjuns 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-all

@annakhm
Copy link
Contributor Author

annakhm commented Apr 8, 2021

Fixes: #1930

@antoninbas
Copy link
Contributor

/test-all

antoninbas
antoninbas previously approved these changes Apr 8, 2021
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

Approving again after rebase

When Host Port is defined, use same port in NPL annotation, without
reserving port from NPL port range. Avoid adding redundant IP table
entry in NPL code.

Fixes: #1930
@antoninbas
Copy link
Contributor

/skip-all

The diff is the same, but the author information for the commit had to be updated

@antoninbas antoninbas added this to the Antrea v1.0 release milestone Apr 8, 2021
@antoninbas antoninbas merged commit eb21c41 into antrea-io:main Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants