Skip to content

Commit 87e9335

Browse files
committed
udn, nad template: Set explicit default MTU for locanet topology
For Localnet topology, the interface MTU should be default MTU (1500) because the underlay is not part of the SDN and should not compensate for the SDN overhead. When MTU is unset, set the MTU explicitly in the NAD with default MTU (1500). Signed-off-by: Or Mergi <[email protected]>
1 parent 8efb425 commit 87e9335

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

dist/templates/k8s.ovn.org_clusteruserdefinednetworks.yaml.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ spec:
389389
mtu:
390390
description: |-
391391
mtu is the maximum transmission unit for a network.
392-
mtu is optional, if not provided, the globally configured value in OVN-Kubernetes (defaults to 1400) is used for the network.
392+
mtu is optional. When omitted, the configured value in OVN-Kubernetes (defaults to 1500 for localnet topology)
393+
is used for the network.
393394
Minimum value for IPv4 subnet is 576, and for IPv6 subnet is 1280.
394395
Maximum value is 65536.
395396
In a scenario `physicalNetworkName` points to OVS bridge mapping of a network configured with certain MTU settings,

go-controller/pkg/clustermanager/userdefinednetwork/template/net-attach-def-template.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sigs.k8s.io/controller-runtime/pkg/client"
1414

1515
ovncnitypes "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/cni/types"
16+
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
1617
userdefinednetworkv1 "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/userdefinednetwork/v1"
1718
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
1819
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"
@@ -155,7 +156,7 @@ func renderCNINetworkConfig(networkName, nadName string, spec SpecGetter) (map[s
155156
case userdefinednetworkv1.NetworkTopologyLocalnet:
156157
cfg := spec.GetLocalnet()
157158
netConfSpec.Role = strings.ToLower(string(cfg.Role))
158-
netConfSpec.MTU = int(cfg.MTU)
159+
netConfSpec.MTU = localnetMTU(cfg.MTU)
159160
netConfSpec.AllowPersistentIPs = cfg.IPAM != nil && cfg.IPAM.Lifecycle == userdefinednetworkv1.IPAMLifecyclePersistent
160161
netConfSpec.Subnets = cidrString(cfg.Subnets)
161162
netConfSpec.ExcludeSubnets = cidrString(cfg.ExcludeSubnets)
@@ -211,6 +212,17 @@ func renderCNINetworkConfig(networkName, nadName string, spec SpecGetter) (map[s
211212
return cniNetConf, nil
212213
}
213214

215+
func localnetMTU(desiredMTU int32) int {
216+
// The MTU for localnet topology should be as the default MTU (1500) because the underlay
217+
// is not part of the SDN and compensating for the SDN overhead (100) is not required.
218+
mtu := config.Default.MTU + 100
219+
if desiredMTU > 0 {
220+
mtu = int(desiredMTU)
221+
}
222+
223+
return mtu
224+
}
225+
214226
func ipamEnabled(ipam *userdefinednetworkv1.IPAMConfig) bool {
215227
return ipam == nil || ipam.Mode == "" || ipam.Mode == userdefinednetworkv1.IPAMEnabled
216228
}

go-controller/pkg/clustermanager/userdefinednetwork/template/net-attach-def-template_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,5 +571,34 @@ var _ = Describe("NetAttachDefTemplate", func() {
571571
"allowPersistentIPs": true
572572
}`,
573573
),
574+
Entry("secondary network, localnet, when MTU is unset it should set default MTU",
575+
udnv1.NetworkSpec{
576+
Topology: udnv1.NetworkTopologyLocalnet,
577+
Localnet: &udnv1.LocalnetConfig{
578+
Role: udnv1.NetworkRoleSecondary,
579+
PhysicalNetworkName: "mylocalnet1",
580+
VLAN: &udnv1.VLANConfig{Mode: udnv1.VLANModeAccess, Access: &udnv1.AccessVLANConfig{ID: 200}},
581+
Subnets: udnv1.DualStackCIDRs{"192.168.100.0/24", "2001:dbb::/64"},
582+
ExcludeSubnets: []udnv1.CIDR{"192.168.100.1/32", "2001:dbb::0/128"},
583+
IPAM: &udnv1.IPAMConfig{
584+
Lifecycle: udnv1.IPAMLifecyclePersistent,
585+
},
586+
},
587+
},
588+
`{
589+
"cniVersion": "1.0.0",
590+
"type": "ovn-k8s-cni-overlay",
591+
"name": "cluster_udn_test-net",
592+
"netAttachDefName": "mynamespace/test-net",
593+
"role": "secondary",
594+
"topology": "localnet",
595+
"physicalNetworkName": "mylocalnet1",
596+
"subnets": "192.168.100.0/24,2001:dbb::/64",
597+
"excludeSubnets": "192.168.100.1/32,2001:dbb::0/128",
598+
"mtu": 1500,
599+
"vlanID": 200,
600+
"allowPersistentIPs": true
601+
}`,
602+
),
574603
)
575604
})

go-controller/pkg/crd/userdefinednetwork/v1/cudn.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ type LocalnetConfig struct {
162162
IPAM *IPAMConfig `json:"ipam,omitempty"`
163163

164164
// mtu is the maximum transmission unit for a network.
165-
// mtu is optional, if not provided, the globally configured value in OVN-Kubernetes (defaults to 1400) is used for the network.
165+
// mtu is optional. When omitted, the configured value in OVN-Kubernetes (defaults to 1500 for localnet topology)
166+
// is used for the network.
166167
// Minimum value for IPv4 subnet is 576, and for IPv6 subnet is 1280.
167168
// Maximum value is 65536.
168169
// In a scenario `physicalNetworkName` points to OVS bridge mapping of a network configured with certain MTU settings,

0 commit comments

Comments
 (0)