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
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Review the [Network Policy FAQ](./docs/network-policy-faq.md) for more informati
* This controller is automatically installed on the EKS Control Plane.
* [Network Policy Node Agent](https://github.com/aws/aws-network-policy-agent) implements Network Policies on nodes by creating eBPF programs.
* [AWS eBPF SDK for Go](https://github.com/aws/aws-ebpf-sdk-go) provides an interface to interact with eBPF programs on the node. This SDK allows for runtime introspection, tracing, and analysis of eBPF execution, aiding in identifying and resolving connectivity issues.
* [VPC Resource Controller](https://github.com/aws/amazon-vpc-resource-controller-k8s) manages Branch & Trunk Network Interfaces for Kubernetes Pods.
* [VPC Resource Controller](https://github.com/aws/amazon-vpc-resource-controller-k8s) manages Branch & Trunk Network Interfaces for Kubernetes Pods.

## ConfigMap

Expand Down Expand Up @@ -343,7 +343,7 @@ elasticity, but uses roughly half as many IPs as using WARM_IP_TARGET alone (32
This also improves the reliability of the EKS cluster by reducing the number of calls necessary to allocate or deallocate
private IPs, which may be throttled, especially at scaling-related times.

**NOTE!**
**NOTE!**
1. If `MINIMUM_IP_TARGET` is set, `WARM_ENI_TARGET` will be ignored. Please utilize `WARM_IP_TARGET` instead.
2. If `MINIMUM_IP_TARGET` is set and `WARM_IP_TARGET` is not set, `WARM_IP_TARGET` is assumed to be 0, which leads to the number of IPs attached to the node will be the value of `MINIMUM_IP_TARGET`. This configuration will prevent future ENIs/IPs from being allocated. It is strongly recommended that `WARM_IP_TARGET` should be set greater than 0 when `MINIMUM_IP_TARGET` is set.

Expand Down Expand Up @@ -697,6 +697,8 @@ This environment variable must be set for both the `aws-vpc-cni-init` and `aws-n

Note that enabling/disabling this feature only affects whether newly created pods have an IPv6 interface created. Therefore, it is recommended that you reboot existing nodes after enabling/disabling this feature.

The value set in `POD_MTU` / `AWS_VPC_ENI_MTU` is used to configure the MTU size of egress interface.

#### `ENABLE_V4_EGRESS` (v1.15.1+)

Type: Boolean as a String
Expand All @@ -707,6 +709,8 @@ Specifies whether PODs in an IPv6 cluster support IPv4 egress. If env is set to

Note that enabling/disabling this feature only affects whether newly created pods have an IPv4 interface created. Therefore, it is recommended that you reboot existing nodes after enabling/disabling this feature.

The value set in `POD_MTU` / `AWS_VPC_ENI_MTU` is used to configure the MTU size of egress interface.

#### `IP_COOLDOWN_PERIOD` (v1.15.0+)

Type: Integer as a String
Expand Down
52 changes: 52 additions & 0 deletions cmd/aws-vpc-cni/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"os"
"testing"

Expand Down Expand Up @@ -48,6 +49,57 @@ func TestGenerateJSONPlusBandwidthAndTuning(t *testing.T) {
assert.NoError(t, err)
}

// Validate setting environment POD_MTU/AWS_VPC_ENI_MTU, takes effect for egress-cni plugin
func TestEgressCNIPluginIPv4EgressTakesMTUEnvVar(t *testing.T) {
_ = os.Setenv(envEnIPv4Egress, "true")
_ = os.Setenv(envPodMTU, "5000")

// 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, "5000", plugins[1].(map[string]interface{})["mtu"])
}

func TestEgressCNIPluginIPv6EgressTakesMTUEnvVar(t *testing.T) {
_ = os.Setenv(envEnIPv6Egress, "true")
_ = os.Setenv(envPodMTU, "8000")

// 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