Skip to content

Commit

Permalink
fix MTU parameter in egress-v4-cni plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jdn5126 committed Mar 3, 2023
1 parent bc8a1f5 commit f3859a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
19 changes: 10 additions & 9 deletions cmd/aws-vpc-cni/main.go
Expand Up @@ -217,19 +217,12 @@ func isValidJSON(inFile string) error {
return json.Unmarshal([]byte(inFile), &result)
}

func generateJSON(jsonFile string, outFile string) error {
func generateJSON(jsonFile string, outFile string, nodeIP string) error {
byteValue, err := ioutil.ReadFile(jsonFile)
if err != nil {
return err
}

var nodeIP string
nodeIP, err = getNodePrimaryV4Address()
if err != nil {
log.Errorf("Failed to get Node IP")
return err
}

vethPrefix := getEnv(envVethPrefix, defaultVethPrefix)
mtu := getEnv(envEniMTU, defaultMTU)
podSGEnforcingMode := getEnv(envPodSGEnforcingMode, defaultPodSGEnforcingMode)
Expand Down Expand Up @@ -391,8 +384,16 @@ func _main() int {
// return 1
//}

// Get node IP for conflist
var nodeIP string
nodeIP, err = getNodePrimaryV4Address()
if err != nil {
log.Errorf("Failed to get Node IP, error: %v", err)
return 1
}

log.Infof("Copying config file... ")
err = generateJSON(defaultAWSconflistFile, tmpAWSconflistFile)
err = generateJSON(defaultAWSconflistFile, tmpAWSconflistFile, nodeIP)
if err != nil {
log.WithError(err).Errorf("Failed to generate 10-awsconflist")
return 1
Expand Down
27 changes: 27 additions & 0 deletions cmd/aws-vpc-cni/main_test.go
@@ -0,0 +1,27 @@
package main

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

const (
awsConflist = "../../misc/10-aws.conflist"
devNull = "/dev/null"
nodeIP = "10.0.0.0"
)

// Validate that generateJSON runs against default conflist without error
func TestGenerateJSON(t *testing.T) {
err := generateJSON(awsConflist, devNull, nodeIP)
assert.NoError(t, err)
}

// Validate that generateJSON runs without error when bandwidth plugin is added to default conflist
func TestGenerateJSONPlusBandwidth(t *testing.T) {
_ = os.Setenv(envEnBandwidthPlugin, "true")
err := generateJSON(awsConflist, devNull, nodeIP)
assert.NoError(t, err)
}
4 changes: 2 additions & 2 deletions misc/10-aws.conflist
Expand Up @@ -15,7 +15,7 @@
{
"name": "egress-v4-cni",
"type": "egress-v4-cni",
"mtu": 9001,
"mtu": "9001",
"enabled": "__EGRESSV4PLUGINENABLED__",
"randomizeSNAT": "__RANDOMIZESNAT__",
"nodeIP": "__NODEIP__",
Expand All @@ -34,4 +34,4 @@
"snat": true
}
]
}
}

0 comments on commit f3859a5

Please sign in to comment.