Skip to content
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

Add unit test and readme update for POD_MTU/ AWS_VPC_ENI_MTU for Egress plugin behavior. #2979

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added Coverage for IPV6 Egress Env Var.
  • Loading branch information
orsenthil committed Jul 3, 2024
commit c643f8b728408d1e380c648d40fb15deb9b18bd7
28 changes: 27 additions & 1 deletion cmd/aws-vpc-cni/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestGenerateJSONPlusBandwidthAndTuning(t *testing.T) {
}

// Validate setting environment AWS_VPC_ENI_MTU, takes effect for egress-cni plugin
func TestEgressCNIPlugin(t *testing.T) {
func TestEgressCNIPluginIPv4Egress(t *testing.T) {
_ = os.Setenv(envEnIPv4Egress, "true")
_ = os.Setenv(envPodMTU, "5000")
assert.True(t, validateMTU(envEniMTU))
Expand All @@ -76,6 +76,32 @@ func TestEgressCNIPlugin(t *testing.T) {
assert.Equal(t, "5000", plugins[1].(map[string]interface{})["mtu"])
}

func TestEgressCNIPluginIPv6Egress(t *testing.T) {
_ = os.Setenv(envEnIPv6Egress, "true")
_ = os.Setenv(envPodMTU, "8000")
assert.True(t, validateMTU(envEniMTU))

// Use a temporary file for the parsed output.
tmpfile, err := os.CreateTemp("", "temp-aws-vpc-cni.conflist")
assert.NoError(t, err)
defer os.Remove(tmpfile.Name())

err = generateJSON(awsConflist, tmpfile.Name(), getPrimaryIPMock)
assert.NoError(t, err)

// Read the json file and verify the MTU value for the egress-cni plugin
var jsonData map[string]interface{}
jsonFile, err := os.ReadFile(tmpfile.Name())
assert.NoError(t, err)

err = json.Unmarshal(jsonFile, &jsonData)
assert.NoError(t, err)

plugins, _ := jsonData["plugins"].([]interface{})
assert.Equal(t, "egress-cni", plugins[1].(map[string]interface{})["type"])
assert.Equal(t, "8000", plugins[1].(map[string]interface{})["mtu"])
}

func TestMTUValidation(t *testing.T) {
// By default, ENI MTU and pod MTU should be valid
assert.True(t, validateMTU(envEniMTU))
Expand Down
Loading