Skip to content

Commit

Permalink
Use Go 1.19; fix egress-v4-cni MTU parsing, update containerd (#2303)
Browse files Browse the repository at this point in the history
* update to go 1.19; update upstream plugins version; update containerd; fix MTU parsing
  • Loading branch information
jdn5126 authored Mar 6, 2023
1 parent ad8b7af commit fdd1a42
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ docker-metrics-test: ## Run metrics helper unit test suite in a container.
make metrics-unit-test

# Fetch the CNI plugins
plugins: FETCH_VERSION=1.1.1
plugins: FETCH_VERSION=1.2.0
plugins: FETCH_URL=https://github.com/containernetworking/plugins/releases/download/v$(FETCH_VERSION)/cni-plugins-$(GOOS)-$(GOARCH)-v$(FETCH_VERSION).tgz
plugins: VISIT_URL=https://github.com/containernetworking/plugins/tree/v$(FETCH_VERSION)/plugins/
plugins: ## Fetch the CNI plugins
Expand Down Expand Up @@ -374,6 +374,7 @@ clean: ## Clean temporary files and build artifacts from the project.
@rm -f -- $(BINS)
@rm -f -- $(PLUGIN_BINS)
@rm -f -- coverage.txt
@rm -rf -- ${MAKEFILE_PATH}test/build

##@ Helpers

Expand Down
29 changes: 18 additions & 11 deletions cmd/egress-v4-cni-plugin/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net"
"os"
"runtime"
"strconv"

"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/logger"

Expand Down Expand Up @@ -51,8 +52,8 @@ type NetConf struct {
// Interface inside container to create
IfName string `json:"ifName"`

//MTU for Egress v4 interface
MTU int `json:"mtu"`
// MTU for Egress v4 interface
MTU string `json:"mtu"`

Enabled string `json:"enabled"`

Expand Down Expand Up @@ -266,10 +267,10 @@ func cmdAdd(args *skel.CmdArgs) error {
}

log.Debugf("Received an ADD request for: conf=%v; Plugin enabled=%s", netConf, netConf.Enabled)
//We will not be vending out this as a separate plugin by itself and it is only intended to be used as a
//chained plugin to VPC CNI in IPv6 mode. We only need this plugin to kick in if v6 is enabled in VPC CNI. So, the
//value of an env variable in VPC CNI determines whether this plugin should be enabled and this is an attempt to
//pass through the variable configured in VPC CNI.
// We will not be vending out this as a separate plugin by itself and it is only intended to be used as a
// chained plugin to VPC CNI in IPv6 mode. We only need this plugin to kick in if v6 is enabled in VPC CNI. So, the
// value of an env variable in VPC CNI determines whether this plugin should be enabled and this is an attempt to
// pass through the variable configured in VPC CNI.
if netConf.Enabled == "false" {
return types.PrintResult(result, netConf.CNIVersion)
}
Expand Down Expand Up @@ -308,8 +309,15 @@ func cmdAdd(args *skel.CmdArgs) error {
}
defer netns.Close()

// Convert MTU from string to int
mtu, err := strconv.Atoi(netConf.MTU)
if err != nil {
log.Debugf("failed to parse MTU: %s, err: %v", netConf.MTU, err)
return err
}

// NB: This uses netConf.IfName NOT args.IfName.
hostInterface, _, err := setupContainerVeth(netns, netConf.IfName, netConf.MTU, tmpResult)
hostInterface, _, err := setupContainerVeth(netns, netConf.IfName, mtu, tmpResult)
if err != nil {
log.Debugf("failed to setup container Veth: %v", err)
return err
Expand All @@ -322,7 +330,6 @@ func cmdAdd(args *skel.CmdArgs) error {
log.Debugf("Node IP: %s", netConf.NodeIP)
if netConf.NodeIP != nil {
for _, ipc := range tmpResult.IPs {

if ipc.Address.IP.To4() != nil {
//log.Printf("Configuring SNAT %s -> %s", ipc.Address.IP, netConf.SnatIP)
if err := snat.Snat4(netConf.NodeIP, ipc.Address.IP, chain, comment, netConf.RandomizeSNAT); err != nil {
Expand All @@ -332,9 +339,9 @@ func cmdAdd(args *skel.CmdArgs) error {
}
}

//Copy interfaces over to result, but not IPs.
// Copy interfaces over to result, but not IPs.
result.Interfaces = append(result.Interfaces, tmpResult.Interfaces...)
//Note: Useful for debug, will do away with the below log prior to release
// Note: Useful for debug, will do away with the below log prior to release
for _, v := range result.IPs {
log.Debugf("Interface Name: %v; IP: %s", v.Interface, v.Address)
}
Expand All @@ -349,7 +356,7 @@ func cmdDel(args *skel.CmdArgs) error {
return fmt.Errorf("failed to parse config: %v", err)
}

//We only need this plugin to kick in if v6 is enabled
// We only need this plugin to kick in if v6 is enabled
if netConf.Enabled == "false" {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/aws/amazon-vpc-cni-k8s

go 1.18
go 1.19

require (
github.com/apparentlymart/go-cidr v1.0.1
Expand Down Expand Up @@ -168,4 +168,4 @@ replace golang.org/x/crypto => golang.org/x/crypto v0.1.0

// Containerd package 1.6.x has a dependency of containernetworking/cni > 1.0.0 and which also has a CNI change spec 1.0.0
// To keep it backward compatible to the spec 0.4.0, we will pin it to v1.5.x
replace github.com/containerd/containerd => github.com/containerd/containerd v1.5.16
replace github.com/containerd/containerd => github.com/containerd/containerd v1.5.18
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ github.com/Masterminds/squirrel v1.5.3/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA4
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg=
github.com/Microsoft/hcsshim v0.8.24 h1:jP+GMeRXIR1sH1kG4lJr9ShmSjVrua5jmFZDtfYGkn4=
github.com/Microsoft/hcsshim v0.8.25 h1:fRMwXiwk3qDwc0P05eHnh+y2v07JdtsfQ1fuAc69m9g=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down Expand Up @@ -152,8 +152,8 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/containerd/cgroups v1.0.3 h1:ADZftAkglvCiD44c77s5YmMqaP2pzVCFZvBmAlBdAP4=
github.com/containerd/containerd v1.5.16 h1:WsTS9tV0vQmRxkWAiiaoasHJ20jqVxVA15s93Bs4GIU=
github.com/containerd/containerd v1.5.16/go.mod h1:bVZZA+0blg2Lw6+I4xDml7L3gum0LsFKe3TnFELlSFw=
github.com/containerd/containerd v1.5.18 h1:doHr6cNxfOLTotWmZs6aZF6LrfJFcjmYFcWlRmQgYPM=
github.com/containerd/containerd v1.5.18/go.mod h1:7IN9MtIzTZH4WPEmD1gNH8bbTQXVX68yd3ZXxSHYCis=
github.com/containernetworking/cni v0.8.0/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
github.com/containernetworking/cni v0.8.1 h1:7zpDnQ3T3s4ucOuJ/ZCLrYBxzkg0AELFfII3Epo9TmI=
github.com/containernetworking/cni v0.8.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
Expand Down

0 comments on commit fdd1a42

Please sign in to comment.