-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Fix incorrect Pod MTU when WireGuard enabled
The default tunnel type is GENEVE, when the WireGuard encryption is enabled, the Pod MTU calculator still deducts the GENEVE overhead directly, which causes a MTU error. This patch will calculate all MTU deduction in function CalculateMTUDeduction, including WireGuard and Multicluster. Signed-off-by: Jiajing Hu <[email protected]>
- Loading branch information
Showing
7 changed files
with
295 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
// Copyright 2024 Antrea Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
agentconfig "antrea.io/antrea/pkg/config/agent" | ||
) | ||
|
||
func TestPodMTU(t *testing.T) { | ||
data, err := setupTest(t) | ||
if err != nil { | ||
t.Fatalf("Error when setting up test: %v", err) | ||
} | ||
defer teardownTest(t, data) | ||
|
||
t.Run("testPodMTUWithGeneveTunnel", func(t *testing.T) { | ||
testPodMTUWithGeneveTunnel(t, data) | ||
}) | ||
t.Run("testPodMTUWithVXLANTunnel", func(t *testing.T) { | ||
testPodMTUWithVXLANTunnel(t, data) | ||
}) | ||
t.Run("testPodMTUWithGRETunnel", func(t *testing.T) { | ||
testPodMTUWithGRETunnel(t, data) | ||
}) | ||
t.Run("testPodMTUWithWireGuard", func(t *testing.T) { | ||
testPodMTUWithWireGuard(t, data) | ||
}) | ||
} | ||
|
||
func testPodMTUWithGeneveTunnel(t *testing.T, data *TestData) { | ||
var previousTunnelType string | ||
ac := func(config *agentconfig.AgentConfig) { | ||
previousTunnelType = config.TunnelType | ||
config.TunnelType = "geneve" | ||
} | ||
if err := data.mutateAntreaConfigMap(nil, ac, false, true); err != nil { | ||
t.Fatalf("Failed to enable geneve tunnel: %v", err) | ||
} | ||
defer func() { | ||
ac := func(config *agentconfig.AgentConfig) { | ||
config.TunnelType = previousTunnelType | ||
} | ||
if err := data.mutateAntreaConfigMap(nil, ac, false, true); err != nil { | ||
t.Errorf("Failed to enable %s tunnel: %v", previousTunnelType, err) | ||
} | ||
}() | ||
|
||
podName := "geneve" | ||
err := data.createBusyboxPodOnNode(podName, data.testNamespace, workerNodeName(1), false) | ||
if err != nil { | ||
t.Fatalf("Failed to create busybox pod: %v", err) | ||
} | ||
defer deletePodWrapper(t, data, data.testNamespace, podName) | ||
if err := data.podWaitForRunning(defaultTimeout, podName, data.testNamespace); err != nil { | ||
t.Fatalf("Error when waiting for Pod %s: %v", podName, err) | ||
} | ||
|
||
podInterface, err := data.GetPodInterfaceName(workerNodeName(1), podName) | ||
if err != nil { | ||
t.Fatalf("Failed to get Pod interface: %v", err) | ||
} | ||
mtu, err := data.GetInterfaceMTU(workerNodeName(1), podInterface) | ||
if err != nil { | ||
t.Fatalf("Failed to get interface MTU: %v", err) | ||
} | ||
if mtu != 1450 { | ||
t.Errorf("Interface MTU is not 1450: %d", mtu) | ||
} | ||
} | ||
|
||
func testPodMTUWithVXLANTunnel(t *testing.T, data *TestData) { | ||
var previousTunnelType string | ||
ac := func(config *agentconfig.AgentConfig) { | ||
previousTunnelType = config.TunnelType | ||
config.TunnelType = "vxlan" | ||
} | ||
if err := data.mutateAntreaConfigMap(nil, ac, false, true); err != nil { | ||
t.Fatalf("Failed to enable vxlan tunnel: %v", err) | ||
} | ||
defer func() { | ||
ac := func(config *agentconfig.AgentConfig) { | ||
config.TunnelType = previousTunnelType | ||
} | ||
if err := data.mutateAntreaConfigMap(nil, ac, false, true); err != nil { | ||
t.Errorf("Failed to enable %s tunnel: %v", previousTunnelType, err) | ||
} | ||
}() | ||
|
||
podName := "vxlanpod" | ||
err := data.createBusyboxPodOnNode(podName, data.testNamespace, workerNodeName(1), false) | ||
if err != nil { | ||
t.Fatalf("Failed to create busybox pod: %v", err) | ||
} | ||
defer deletePodWrapper(t, data, data.testNamespace, podName) | ||
if err := data.podWaitForRunning(defaultTimeout, podName, data.testNamespace); err != nil { | ||
t.Fatalf("Error when waiting for Pod %s: %v", podName, err) | ||
} | ||
|
||
podInterface, err := data.GetPodInterfaceName(workerNodeName(1), podName) | ||
if err != nil { | ||
t.Fatalf("Failed to get Pod interface: %v", err) | ||
} | ||
mtu, err := data.GetInterfaceMTU(workerNodeName(1), podInterface) | ||
if err != nil { | ||
t.Fatalf("Failed to get interface MTU: %v", err) | ||
} | ||
if mtu != 1450 { | ||
t.Errorf("Interface MTU is not 1450: %d", mtu) | ||
} | ||
} | ||
|
||
func testPodMTUWithGRETunnel(t *testing.T, data *TestData) { | ||
skipIfIPv6Cluster(t) | ||
var previousTunnelType string | ||
ac := func(config *agentconfig.AgentConfig) { | ||
previousTunnelType = config.TunnelType | ||
config.TunnelType = "gre" | ||
} | ||
if err := data.mutateAntreaConfigMap(nil, ac, false, true); err != nil { | ||
t.Fatalf("Failed to enable gre tunnel: %v", err) | ||
} | ||
defer func() { | ||
ac := func(config *agentconfig.AgentConfig) { | ||
config.TunnelType = previousTunnelType | ||
} | ||
if err := data.mutateAntreaConfigMap(nil, ac, false, true); err != nil { | ||
t.Errorf("Failed to enable %s tunnel: %v", previousTunnelType, err) | ||
} | ||
}() | ||
|
||
podName := "grepod" | ||
err := data.createBusyboxPodOnNode(podName, data.testNamespace, workerNodeName(1), false) | ||
if err != nil { | ||
t.Fatalf("Failed to create busybox pod: %v", err) | ||
} | ||
defer deletePodWrapper(t, data, data.testNamespace, podName) | ||
if err := data.podWaitForRunning(defaultTimeout, podName, data.testNamespace); err != nil { | ||
t.Fatalf("Error when waiting for Pod %s: %v", podName, err) | ||
} | ||
|
||
podInterface, err := data.GetPodInterfaceName(workerNodeName(1), podName) | ||
if err != nil { | ||
t.Fatalf("Failed to get Pod interface: %v", err) | ||
} | ||
mtu, err := data.GetInterfaceMTU(workerNodeName(1), podInterface) | ||
if err != nil { | ||
t.Fatalf("Failed to get interface MTU: %v", err) | ||
} | ||
if mtu != 1462 { | ||
t.Errorf("Interface MTU is not 1462: %d", mtu) | ||
} | ||
} | ||
|
||
func testPodMTUWithWireGuard(t *testing.T, data *TestData) { | ||
var previousTunnelType string | ||
var previousTrafficEncryptionMode string | ||
ac := func(config *agentconfig.AgentConfig) { | ||
previousTunnelType = config.TunnelType | ||
previousTrafficEncryptionMode = config.TrafficEncryptionMode | ||
config.TrafficEncryptionMode = "wireguard" | ||
} | ||
if err := data.mutateAntreaConfigMap(nil, ac, false, true); err != nil { | ||
t.Fatalf("Failed to enable wireguard tunnel: %v", err) | ||
} | ||
defer func() { | ||
ac := func(config *agentconfig.AgentConfig) { | ||
config.TunnelType = previousTunnelType | ||
config.TrafficEncryptionMode = previousTrafficEncryptionMode | ||
} | ||
if err := data.mutateAntreaConfigMap(nil, ac, false, true); err != nil { | ||
t.Errorf("Failed to enable %s tunnel: %v", previousTunnelType, err) | ||
} | ||
}() | ||
|
||
podName := "wgpod" | ||
err := data.createBusyboxPodOnNode(podName, data.testNamespace, workerNodeName(1), false) | ||
if err != nil { | ||
t.Fatalf("Failed to create busybox pod: %v", err) | ||
} | ||
defer deletePodWrapper(t, data, data.testNamespace, podName) | ||
|
||
if err := data.podWaitForRunning(defaultTimeout, podName, data.testNamespace); err != nil { | ||
t.Fatalf("Error when waiting for Pod %s: %v", podName, err) | ||
} | ||
|
||
podInterface, err := data.GetPodInterfaceName(workerNodeName(1), podName) | ||
if err != nil { | ||
t.Fatalf("Failed to get Pod interface: %v", err) | ||
} | ||
mtu, err := data.GetInterfaceMTU(workerNodeName(1), podInterface) | ||
if err != nil { | ||
t.Fatalf("Failed to get interface MTU: %v", err) | ||
} | ||
if mtu != 1420 { | ||
t.Errorf("Interface MTU is not 1420: %d", mtu) | ||
} | ||
} |