Skip to content

Commit

Permalink
[IPv6] Fix MTU config (#1317)
Browse files Browse the repository at this point in the history
Use Node's internal address to decide if extra IPv6 overhead is needed.
  • Loading branch information
lzhecheng committed Nov 9, 2020
1 parent 80001ec commit 03c7d80
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ func (i *Initializer) initNodeLocalConfig() error {
NodeIPAddr: localAddr,
UplinkNetConfig: new(config.AdapterNetConfig)}

mtu, err := i.getNodeMTU(localIntf)
if err != nil {
return err
}
i.nodeConfig.NodeMTU = mtu
klog.Infof("Setting Node MTU=%d", mtu)

if i.networkConfig.TrafficEncapMode.IsNetworkPolicyOnly() {
return nil
}
Expand Down Expand Up @@ -603,31 +610,24 @@ func (i *Initializer) initNodeLocalConfig() error {
klog.V(2).Infof("Configure IPv6 Subnet CIDR %s on this Node", localSubnet.String())
}
}
} else {
// Spec.PodCIDR can be empty due to misconfiguration.
if node.Spec.PodCIDR == "" {
klog.Errorf("Spec.PodCIDR is empty for Node %s. Please make sure --allocate-node-cidrs is enabled "+
"for kube-controller-manager and --cluster-cidr specifies a sufficient CIDR range", nodeName)
return fmt.Errorf("CIDR string is empty for node %s", nodeName)
}
_, localSubnet, err := net.ParseCIDR(node.Spec.PodCIDR)
if err != nil {
klog.Errorf("Failed to parse subnet from CIDR string %s: %v", node.Spec.PodCIDR, err)
return err
}
if localSubnet.IP.To4() != nil {
i.nodeConfig.PodIPv4CIDR = localSubnet
} else {
i.nodeConfig.PodIPv6CIDR = localSubnet
}
return nil
}

mtu, err := i.getNodeMTU(localIntf)
// Spec.PodCIDR can be empty due to misconfiguration.
if node.Spec.PodCIDR == "" {
klog.Errorf("Spec.PodCIDR is empty for Node %s. Please make sure --allocate-node-cidrs is enabled "+
"for kube-controller-manager and --cluster-cidr specifies a sufficient CIDR range", nodeName)
return fmt.Errorf("CIDR string is empty for node %s", nodeName)
}
_, localSubnet, err := net.ParseCIDR(node.Spec.PodCIDR)
if err != nil {
klog.Errorf("Failed to parse subnet from CIDR string %s: %v", node.Spec.PodCIDR, err)
return err
}
i.nodeConfig.NodeMTU = mtu
klog.Infof("Setting Node MTU=%d", mtu)
if localSubnet.IP.To4() != nil {
i.nodeConfig.PodIPv4CIDR = localSubnet
} else {
i.nodeConfig.PodIPv6CIDR = localSubnet
}
return nil
}

Expand Down Expand Up @@ -746,13 +746,13 @@ func (i *Initializer) getNodeMTU(localIntf *net.Interface) (int, error) {
} else if i.networkConfig.TunnelType == ovsconfig.GRETunnel {
mtu -= config.GREOverhead
}
if i.nodeConfig.NodeIPAddr.IP.To4() == nil {
mtu -= config.IPv6ExtraOverhead
}
}
if i.networkConfig.EnableIPSecTunnel {
mtu -= config.IpsecESPOverhead
}
if i.nodeConfig.PodIPv6CIDR != nil {
mtu -= config.IPv6ExtraOverhead
}
return mtu, nil
}

Expand Down

0 comments on commit 03c7d80

Please sign in to comment.