-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Have CNI assume mtu from eth0 #1690
Conversation
Hi @faiq. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
images/kindnetd/cmd/kindnetd/cni.go
Outdated
@@ -28,27 +29,49 @@ import ( | |||
"k8s.io/utils/net" | |||
) | |||
|
|||
//sensibleMTU value to fall back on - if we're not able to configure from eth0 | |||
const defaultMtu = 1480 |
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.
why do you think we should change the default?
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.
We could allow the kernel to set the default, as documented here: https://github.com/containernetworking/plugins/tree/master/plugins/main/ptp#example-network-configuration
I've typically found that mtu is configured to 1500, which has been problematic for many people.
Maybe it should be 1400 instead.
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 prefer to keep current behaviour, and allow the kernel to set it
/ok-to-test |
explicit +1 on the approach, btw, since I neglected to put that in github anywhere. |
ping @faiq , it's only missing not defaulting the mtu to 1480, maybe just not inserting that field in the json if we can't get the MTU value from eth0 is enough. please disregard my other comment #1690 (comment) |
Thanks for the ping @aojea. I'll be completing this one today. I believe we just need to template it if we get an error from getting the MTU from |
yeah, that sounds nice, what about something like
|
images/kindnetd/cmd/kindnetd/cni.go
Outdated
} | ||
|
||
// ComputeCNIConfigInputs computes the template inputs for CNIConfigWriter | ||
func ComputeCNIConfigInputs(node corev1.Node) CNIConfigInputs { | ||
podCIDR := node.Spec.PodCIDR | ||
defaultRoute := "0.0.0.0/0" | ||
mtu, err := computeBridgeMTU() |
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.
@BenTheElder if I read it correctly this is going to be executed periodically, can you confirm?
I don't like the idea of iterating over the interfaces periodically, it can cause issues, I had issue with the net library before.
Should be better to try to get the mtu only once? in the main loop? and pass it as a parameter of ComputeCNIConfigInputs?
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.
Actually, yes it will be computed multiple times and I think it's a more sound approach to compute this once.
/retest |
images/kindnetd/cmd/kindnetd/cni.go
Outdated
|
||
var mtu int | ||
|
||
func init() { |
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.
init() and global data is a big anti-pattern.
mtu should be plumbed down from main.
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 didn't realize this was an anti-pattern, sorry. If you have a quick article on best practices, I'd love to read it! If not, no sweat.
I can pull it down from main, but I think it would need to go in makeNodesReconciler
as an extra parameter which then propagates to the ComputeCNIConfigInputs
function.
Alternatively we can put mtu
as a field in CNIConfigWriter
and in this method func (c *CNIConfigWriter) Write(inputs CNIConfigInputs)
we can have inputs.Mtu = c.mtu
Let me know what you would prefer.
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 lean to the CNIConfigWriter
since mtu only matter to that type.
what do you think Ben?
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.
no sweat :-)
I would say "avoid globals" is a good practice for all languages, I don't have a reference handy just this moment though, sorry.
init
is best avoided in code because it's both global behavior and unpredictable import side-effects (importing the package causes this code to be run during the binary startup, in some random order versus other packages)
CNIConfigWriter makes sense to me 👍
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.
https://stackoverflow.com/a/56039373 is a pretty decent short reference on this point specifically 😅
/retest |
@@ -76,6 +94,9 @@ const cniConfigTemplate = ` | |||
] | |||
] | |||
} | |||
{{if .Mtu}}, |
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.
if the eth0 interface is not found mtu will be 0,
and {{if .Mtu}}, will skip this based on the go template docs
{{if pipeline}} T1 {{end}}
If the value of the pipeline is empty, no output is generated;
otherwise, T1 is executed. The empty values are false, 0, any
nil pointer or interface value, and any array, slice, map, or
string of length zero.
Dot is unaffected.
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, and then it will default to the ptp behavior of being set by the kernel. I thought that's what we wanted #1690 (comment)
In the docs it says it is an optional field and will be set by Kernel if its not there: https://github.com/containernetworking/plugins/tree/master/plugins/main/ptp#network-configuration-reference
Network configuration reference
name (string, required): the name of the network
type (string, required): "ptp"
ipMasq (boolean, optional): set up IP Masquerade on the host for traffic originating from ip of this network and destined outside of this network. Defaults to false.
mtu (integer, optional): explicitly set MTU to the specified value. Defaults to value chosen by the kernel.
ipam (dictionary, required): IPAM configuration to be used for this network.
dns (dictionary, optional): DNS information to return as described in the Result.
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.
right, perfect
this looks good now, thanks for your patience. |
I can squash all the commits, sure. |
/retest |
/retest |
1 similar comment
/retest |
tested locally and works
|
Sorry I was out the end of last week (holidays at employer / USA). Looking at this again now. |
d446edc
to
a0e2d0e
Compare
rebased to HEAD and pushed a kindnetd image |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: BenTheElder, faiq The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
thanks for this! |
As per my conversation with @aojea in the following issue We figured the best path going forward would be to auto configure the MTU of kindnet from the host's device
This pull request replaces the one here
#1686