Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions driver/network_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sort"
"strings"
"time"
"strconv"

"github.com/pkg/errors"
libcalicoErrors "github.com/projectcalico/libcalico-go/lib/errors"
Expand All @@ -29,6 +30,7 @@ const DOCKER_LABEL_PREFIX = "org.projectcalico.label."
const LABEL_POLL_TIMEOUT_ENVKEY = "CALICO_LIBNETWORK_LABEL_POLL_TIMEOUT"
const CREATE_PROFILES_ENVKEY = "CALICO_LIBNETWORK_CREATE_PROFILES"
const LABEL_ENDPOINTS_ENVKEY = "CALICO_LIBNETWORK_LABEL_ENDPOINTS"
const VETH_MTU_ENVKEY = "CALICO_LIBNETWORK_VETH_MTU"

// NetworkDriver is the Calico network driver representation.
// Must be used with Calico IPAM and supports IPv4 only.
Expand All @@ -42,6 +44,8 @@ type NetworkDriver struct {

DummyIPV4Nexthop string

vethMTU uint16

labelPollTimeout time.Duration

createProfiles bool
Expand Down Expand Up @@ -72,6 +76,20 @@ func NewNetworkDriver(client *datastoreClient.Client) network.Driver {
labelEndpoints: strings.EqualFold(os.Getenv(LABEL_ENDPOINTS_ENVKEY), "true"),
}

// Check if MTU environment variable is given, parse into uint16
// and override the default in the NetworkDriver.
if mtuStr, ok := os.LookupEnv(VETH_MTU_ENVKEY); ok {
mtu, err := strconv.ParseUint(mtuStr, 10, 16)
if err != nil {
log.Fatalf("Failed to parse %v '%v' into uint16: %v",
VETH_MTU_ENVKEY, mtuStr, err)
}

driver.vethMTU = uint16(mtu)

log.WithField("mtu", mtu).Info("Parsed veth MTU")
}

if !driver.createProfiles {
log.Info("Feature disabled: no Calico profiles will be created per network")
}
Expand Down Expand Up @@ -377,10 +395,10 @@ func (d NetworkDriver) Join(request *network.JoinRequest) (*network.JoinResponse
hostInterfaceName := "cali" + prefix
tempInterfaceName := "temp" + prefix

if err = netns.CreateVeth(hostInterfaceName, tempInterfaceName); err != nil {
if err = netns.CreateVeth(hostInterfaceName, tempInterfaceName, d.vethMTU); err != nil {
err = errors.Wrapf(
err, "Veth creation error, hostInterfaceName=%v, tempInterfaceName=%v",
hostInterfaceName, tempInterfaceName)
err, "Veth creation error, hostInterfaceName=%v, tempInterfaceName=%v, vethMTU=%v",
hostInterfaceName, tempInterfaceName, d.vethMTU)
log.Errorln(err)
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion utils/netns/netns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"github.com/vishvananda/netlink"
)

func CreateVeth(vethNameHost, vethNameNSTemp string) error {
func CreateVeth(vethNameHost, vethNameNSTemp string, vethMTU uint16) error {
veth := &netlink.Veth{
LinkAttrs: netlink.LinkAttrs{
Name: vethNameHost,
MTU: int(vethMTU),
},
PeerName: vethNameNSTemp,
}
Expand Down