-
Notifications
You must be signed in to change notification settings - Fork 376
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
Implement NPL agent unification. #3936
Conversation
/test-all |
Codecov Report
@@ Coverage Diff @@
## main #3936 +/- ##
==========================================
+ Coverage 61.42% 64.87% +3.45%
==========================================
Files 296 294 -2
Lines 43864 44520 +656
==========================================
+ Hits 26942 28882 +1940
+ Misses 14672 13315 -1357
- Partials 2250 2323 +73
*This pull request uses carry forward flags. Click here to find out more.
|
/test-all |
85c426b
to
3156ae3
Compare
bf0acfb
to
d97231f
Compare
/test-all |
/test-all |
/test-all |
/test-all |
9ac1c52
to
e50a9e8
Compare
/test-windows-proxyall-e2e |
/test-all |
/test-all |
7fedcb5
to
bf9ac29
Compare
Hi @antoninbas , do you have more comments for this PR? |
// irrespective of which protocol is in use. | ||
// In particular we make sure that a given NodePort is never used by more than one Pod. | ||
// One Pod could use multiple Nodeports for different protocol with the same Pod port | ||
// because of the new NPL unification implementation. |
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.
that may not be a useful precision
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.
Updated.
// TestNodePortAlreadyBoundTo validates that when a port with TCP protocol is already bound to, | ||
// the same port should be selected for NPL if any other protocol is available. |
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.
this comment is incorrect.
the same port should be selected for NPL
we don't use the same port
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.
Updated.
@@ -20,9 +20,15 @@ import ( | |||
"net" | |||
"sync" | |||
|
|||
"k8s.io/klog/v2" |
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.
removing klog seems to be causing build issues?
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.
Yes, it should not be removed.
func (pt *PortTable) getEntryByPodIPPortProto(ip string, port int, protocol string) *NodePortData { | ||
return pt.PodEndpointTable[podIPPortProtoFormat(ip, port, protocol)] | ||
} | ||
|
||
func (pt *PortTable) GetEntry(ip string, port int, protocol string) *NodePortData { |
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.
This function is duplicated for the Linux and Windows implementations I think. I don't a difference between the 2 versions.
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.
This function has been moved to port_table.go. So both linux and windows implementation can call it.
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.
Have you made this change, I don't see it?
var protocolSocketData *ProtocolSocketData | ||
protocolSocketData = &data.Protocols[0] | ||
protocolSocketData = &data.Protocol | ||
if protocolSocketData != nil { |
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.
I don't understand what we need protocolSocketData
for here. I don't see similar logic in the Linux version?
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.
This data structure is shared by both linux and windows. Do you think we need to build a new data structure without socket variable for windows?
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.
Sorry, I don't understand your reply.
Let me rephrase my question. This is the corresponding code for Linux:
if err := pt.PodPortRules.DeleteRule(data.NodePort, podIP, podPort, protocol); err != nil {
return err
}
why do we need to check protocolSocketData
/ data.Protocol
for Windows:
var protocolSocketData *ProtocolSocketData
protocolSocketData = &data.Protocols[0]
protocolSocketData = &data.Protocol
if protocolSocketData != nil {
if err := pt.PodPortRules.DeleteRule(data.NodePort, podIP, podPort, protocol); err != nil {
return err
}
}
- we don't seem to actually use
protocolSocketData
- is it even possible for
protocolSocketData
to benil
? I am not sure, I don't see any other place where we check for this.
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.
@antoninbas I see, yes, protocolSocketData will never be nil if we can successfully get entry from cache table. I have removed it, thanks.
pt.addPortTableCache(npData) | ||
} else { | ||
// Only add rules for if the entry does not exist. | ||
return 0, fmt.Errorf("existed windows nodeport entry for %s:%d:%s", podIP, podPort, protocol) |
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.
wrong
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.
Updated.
} | ||
|
||
pt.NodePortTable[NodePortProtoFormat(nodePort, protocol)] = npData | ||
pt.PodEndpointTable[podIPPortProtoFormat(podIP, podPort, protocol)] = npData | ||
pt.addPortTableCache(npData) | ||
} else { | ||
// Only add rules for if the entry does not exist. | ||
return 0, fmt.Errorf("existed windows nodeport entry for %s:%d:%s", podIP, podPort, protocol) |
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.
return 0, fmt.Errorf("existed windows nodeport entry for %s:%d:%s", podIP, podPort, protocol) | |
return 0, fmt.Errorf("existing Windows NodePort entry for %s:%d:%s", podIP, podPort, protocol) |
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.
Updated, thanks.
16d5be1
to
f00f3ae
Compare
/test-all |
var protocolSocketData *ProtocolSocketData | ||
protocolSocketData = &data.Protocols[0] | ||
protocolSocketData = &data.Protocol | ||
if protocolSocketData != nil { |
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.
Sorry, I don't understand your reply.
Let me rephrase my question. This is the corresponding code for Linux:
if err := pt.PodPortRules.DeleteRule(data.NodePort, podIP, podPort, protocol); err != nil {
return err
}
why do we need to check protocolSocketData
/ data.Protocol
for Windows:
var protocolSocketData *ProtocolSocketData
protocolSocketData = &data.Protocols[0]
protocolSocketData = &data.Protocol
if protocolSocketData != nil {
if err := pt.PodPortRules.DeleteRule(data.NodePort, podIP, podPort, protocol); err != nil {
return err
}
}
- we don't seem to actually use
protocolSocketData
- is it even possible for
protocolSocketData
to benil
? I am not sure, I don't see any other place where we check for this.
// TestNodePortAlreadyBoundTo validates that when a port is already bound to, a different port will | ||
// be selected for NPL. | ||
// TestNodePortAlreadyBoundTo validates that when a port with TCP protocol is already bound to, | ||
// the next port should be selected for NPL if the same protocol is available. |
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.
// the next port should be selected for NPL if the same protocol is available. | |
// the next sequential TCP port should be selected for NPL when it is available. |
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.
Updated.
socket: socket, | ||
}) | ||
func openSocketsForPort(localPortOpener LocalPortOpener, port int, protocol string) (ProtocolSocketData, error) { | ||
// Port needs to be only available for the protocol used by NPL rule. |
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.
// Port needs to be only available for the protocol used by NPL rule. | |
// Port only needs to be available for the protocol used by the NPL rule. |
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.
Updated.
func (pt *PortTable) getEntryByPodIPPortProto(ip string, port int, protocol string) *NodePortData { | ||
return pt.PodEndpointTable[podIPPortProtoFormat(ip, port, protocol)] | ||
} | ||
|
||
func (pt *PortTable) GetEntry(ip string, port int, protocol string) *NodePortData { |
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.
Have you made this change, I don't see it?
return nil | ||
} | ||
|
||
func (pt *PortTable) delPortTableCache(npData *NodePortData) error { |
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.
s/del/delete
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.
Updated.
return fmt.Sprintf("%s:%d:%s", ip, port, protocol) | ||
} | ||
|
||
func (pt *PortTable) getEntryByPodIPPortProto(ip string, port int, protocol string) *NodePortData { |
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.
Have you made this change, I don't see it?
@antoninbas I moved getEntryByPodIPPortProto here.
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.
I was talking about GetEntry
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.
My bad. Move it to port_table.go, thanks.
* Unify agent behavior across Linux and Windows. Linux agent should support allocating different nodeports for different protocols when the podports are the same. * Replace map with cache.indexer for cachetable to reduce repeated insertion. * Update port allocation related unit tests. * Enable windows e2e test. * Delete unused functions. Signed-off-by: Shuyang Xin <[email protected]>
/test-all |
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.
LGTM
/test-windows-e2e |
/test-windows-proxyall-e2e |
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.
LGTM
/skip-integration tested manually |
allocating different nodeports for different protocols when the podports are the same.
Signed-off-by: Shuyang Xin [email protected]