From 066a763308950878af1290e5016a41d842678829 Mon Sep 17 00:00:00 2001 From: Harsh Rawat Date: Sat, 5 Jun 2021 12:05:12 -0700 Subject: [PATCH 1/6] Added CNI plugin version upgrade code to common file --- agent/ecscni/plugin_linux.go | 4 -- agent/ecscni/plugin_linux_test.go | 33 ---------------- agent/ecscni/plugin_test.go | 62 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 37 deletions(-) create mode 100644 agent/ecscni/plugin_test.go diff --git a/agent/ecscni/plugin_linux.go b/agent/ecscni/plugin_linux.go index 6d369d06a07..6fc0111da11 100644 --- a/agent/ecscni/plugin_linux.go +++ b/agent/ecscni/plugin_linux.go @@ -30,10 +30,6 @@ import ( ) const ( - // ECSCNIVersion, ECSCNIGitHash, VPCCNIGitHash needs to be updated every time CNI plugin is updated. - currentECSCNIVersion = "2020.09.0" - currentECSCNIGitHash = "55b2ae77ee0bf22321b14f2d4ebbcc04f77322e1" - currentVPCCNIGitHash = "a21d3a41f922e14c19387713df66be3e4ee1e1f6" vpcCNIPluginInterfaceType = "vlan" // vpcCNIPluginPath is the path of the cni plugin's log file. vpcCNIPluginPath = "/log/vpc-branch-eni.log" diff --git a/agent/ecscni/plugin_linux_test.go b/agent/ecscni/plugin_linux_test.go index d109827baa9..49273686a4d 100644 --- a/agent/ecscni/plugin_linux_test.go +++ b/agent/ecscni/plugin_linux_test.go @@ -20,11 +20,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "net" - "os/exec" - "path/filepath" - "strings" "testing" "time" @@ -616,32 +612,3 @@ func TestCNIPluginVersion(t *testing.T) { }) } } - -// Asserts that CNI plugin version matches the expected version -func TestCNIPluginVersionNumber(t *testing.T) { - versionStr := getCNIVersionString(t) - assert.Equal(t, versionStr, currentECSCNIVersion) -} - -// Asserts that CNI plugin version is upgraded when new commits are made to CNI plugin submodule -func TestCNIPluginVersionUpgrade(t *testing.T) { - versionStr := getCNIVersionString(t) - cmd := exec.Command("git", "submodule") - versionInfo, err := cmd.Output() - assert.NoError(t, err, "Error running the command: git submodule") - versionInfoStrList := strings.Split(string(versionInfo), "\n") - // If a new commit is added, version should be upgraded - if currentECSCNIGitHash != strings.Split(versionInfoStrList[0], " ")[1] { - assert.NotEqual(t, currentECSCNIVersion, versionStr) - } - assert.Equal(t, currentVPCCNIGitHash, strings.Split(versionInfoStrList[1], " ")[1]) -} - -// Returns the version in CNI plugin VERSION file as a string -func getCNIVersionString(t *testing.T) string { - // ../../amazon-ecs-cni-plugins/VERSION - versionFilePath := filepath.Clean(filepath.Join("..", "..", "amazon-ecs-cni-plugins", "VERSION")) - versionStr, err := ioutil.ReadFile(versionFilePath) - assert.NoError(t, err, "Error reading the CNI plugin version file") - return strings.TrimSpace(string(versionStr)) -} diff --git a/agent/ecscni/plugin_test.go b/agent/ecscni/plugin_test.go new file mode 100644 index 00000000000..dad386881f4 --- /dev/null +++ b/agent/ecscni/plugin_test.go @@ -0,0 +1,62 @@ +// +build unit + +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file 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 ecscni + +import ( + "io/ioutil" + "os/exec" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +const ( + // ECSCNIVersion, ECSCNIGitHash, VPCCNIGitHash needs to be updated every time CNI plugin is updated. + currentECSCNIVersion = "2020.09.0" + currentECSCNIGitHash = "55b2ae77ee0bf22321b14f2d4ebbcc04f77322e1" + currentVPCCNIGitHash = "a21d3a41f922e14c19387713df66be3e4ee1e1f6" +) + +// Asserts that CNI plugin version matches the expected version +func TestCNIPluginVersionNumber(t *testing.T) { + versionStr := getCNIVersionString(t) + assert.Equal(t, versionStr, currentECSCNIVersion) +} + +// Asserts that CNI plugin version is upgraded when new commits are made to CNI plugin submodule +func TestCNIPluginVersionUpgrade(t *testing.T) { + versionStr := getCNIVersionString(t) + cmd := exec.Command("git", "submodule") + versionInfo, err := cmd.Output() + assert.NoError(t, err, "Error running the command: git submodule") + versionInfoStrList := strings.Split(string(versionInfo), "\n") + // If a new commit is added, version should be upgraded + if currentECSCNIGitHash != strings.Split(versionInfoStrList[0], " ")[1] { + assert.NotEqual(t, currentECSCNIVersion, versionStr) + } + assert.Equal(t, currentVPCCNIGitHash, strings.Split(versionInfoStrList[1], " ")[1]) +} + +// Returns the version in CNI plugin VERSION file as a string +func getCNIVersionString(t *testing.T) string { + // ../../amazon-ecs-cni-plugins/VERSION + versionFilePath := filepath.Clean(filepath.Join("..", "..", "amazon-ecs-cni-plugins", "VERSION")) + versionStr, err := ioutil.ReadFile(versionFilePath) + assert.NoError(t, err, "Error reading the CNI plugin version file") + return strings.TrimSpace(string(versionStr)) +} From 8bfed630b6f1cda591146738ad0b37feee7c7163 Mon Sep 17 00:00:00 2001 From: Harsh Rawat Date: Mon, 17 May 2021 17:48:52 -0700 Subject: [PATCH 2/6] Build vpc-eni cni plugin for Windows --- scripts/dockerfiles/Dockerfile.buildWindowsVPCCNIPlugins | 3 +-- scripts/local-save | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/dockerfiles/Dockerfile.buildWindowsVPCCNIPlugins b/scripts/dockerfiles/Dockerfile.buildWindowsVPCCNIPlugins index 86514cb180e..92fb43eb985 100644 --- a/scripts/dockerfiles/Dockerfile.buildWindowsVPCCNIPlugins +++ b/scripts/dockerfiles/Dockerfile.buildWindowsVPCCNIPlugins @@ -19,10 +19,9 @@ ARG GOARCH ENV GOARCH ${GOARCH} ENV GOOS windows -ENV BUILD_FLAGS "-tags disablekubeapi" RUN mkdir -p /go/src/github.com/aws/ WORKDIR /go/src/github.com/aws/amazon-vpc-cni-plugins -CMD ["make", "vpc-shared-eni"] +CMD ["make", "vpc-eni"] diff --git a/scripts/local-save b/scripts/local-save index e95618f0afa..a86af105d24 100755 --- a/scripts/local-save +++ b/scripts/local-save @@ -31,10 +31,10 @@ stage_windows() { cp out/amazon-ecs-agent.exe "${ziproot}" cp -v misc/windows-deploy/*.ps1 "${ziproot}" - if [[ -f "${buildroot}/out/cni-plugins/vpc-shared-eni" ]] + if [[ -f "${buildroot}/out/cni-plugins/vpc-eni" ]] then mkdir "${ziproot}/cni" - mv "${buildroot}/out/cni-plugins/vpc-shared-eni" "${ziproot}/cni/vpc-shared-eni.exe" + mv "${buildroot}/out/cni-plugins/vpc-eni" "${ziproot}/cni/vpc-eni.exe" fi pushd "${ziproot}" From 11e03882bb180adaf0761a624c8bcdc80ec866b3 Mon Sep 17 00:00:00 2001 From: Harsh Rawat Date: Thu, 3 Jun 2021 17:48:39 -0700 Subject: [PATCH 3/6] Updated the git submodule for vpc-cni plugins --- agent/ecscni/plugin_test.go | 2 +- amazon-vpc-cni-plugins | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/ecscni/plugin_test.go b/agent/ecscni/plugin_test.go index dad386881f4..ff7bc3b0a30 100644 --- a/agent/ecscni/plugin_test.go +++ b/agent/ecscni/plugin_test.go @@ -29,7 +29,7 @@ const ( // ECSCNIVersion, ECSCNIGitHash, VPCCNIGitHash needs to be updated every time CNI plugin is updated. currentECSCNIVersion = "2020.09.0" currentECSCNIGitHash = "55b2ae77ee0bf22321b14f2d4ebbcc04f77322e1" - currentVPCCNIGitHash = "a21d3a41f922e14c19387713df66be3e4ee1e1f6" + currentVPCCNIGitHash = "504c22e7a39cfa982a78f3925feb5a434551e435" ) // Asserts that CNI plugin version matches the expected version diff --git a/amazon-vpc-cni-plugins b/amazon-vpc-cni-plugins index a21d3a41f92..504c22e7a39 160000 --- a/amazon-vpc-cni-plugins +++ b/amazon-vpc-cni-plugins @@ -1 +1 @@ -Subproject commit a21d3a41f922e14c19387713df66be3e4ee1e1f6 +Subproject commit 504c22e7a39cfa982a78f3925feb5a434551e435 From 8a845dca3b8887f7a7672ae50053284f29c6b289 Mon Sep 17 00:00:00 2001 From: Harsh Rawat Date: Sat, 5 Jun 2021 12:30:28 -0700 Subject: [PATCH 4/6] Disabled verbose option for Windows unit tests --- .github/workflows/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2ae6171d4a1..3c90c99fea8 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -20,4 +20,4 @@ jobs: $Env:GOPATH = "$Env:GITHUB_WORKSPACE" cd "$Env:GITHUB_WORKSPACE" cd "src/github.com/aws/amazon-ecs-agent" - go test -v -race -tags unit -timeout 40s ./agent/... + go test -race -tags unit -timeout 40s ./agent/... From f8ff4dc1b5153380c0d224684e1ac3d21382ce09 Mon Sep 17 00:00:00 2001 From: Harsh Rawat Date: Wed, 9 Jun 2021 11:41:31 -0700 Subject: [PATCH 5/6] Updated git submodule vpc-cni-plugins to latest release --- agent/ecscni/plugin_test.go | 2 +- amazon-vpc-cni-plugins | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/ecscni/plugin_test.go b/agent/ecscni/plugin_test.go index ff7bc3b0a30..6850ff6c456 100644 --- a/agent/ecscni/plugin_test.go +++ b/agent/ecscni/plugin_test.go @@ -29,7 +29,7 @@ const ( // ECSCNIVersion, ECSCNIGitHash, VPCCNIGitHash needs to be updated every time CNI plugin is updated. currentECSCNIVersion = "2020.09.0" currentECSCNIGitHash = "55b2ae77ee0bf22321b14f2d4ebbcc04f77322e1" - currentVPCCNIGitHash = "504c22e7a39cfa982a78f3925feb5a434551e435" + currentVPCCNIGitHash = "941c5280e8a3329194cd78454454332610333822" ) // Asserts that CNI plugin version matches the expected version diff --git a/amazon-vpc-cni-plugins b/amazon-vpc-cni-plugins index 504c22e7a39..941c5280e8a 160000 --- a/amazon-vpc-cni-plugins +++ b/amazon-vpc-cni-plugins @@ -1 +1 @@ -Subproject commit 504c22e7a39cfa982a78f3925feb5a434551e435 +Subproject commit 941c5280e8a3329194cd78454454332610333822 From 5b4a525c670fc687fc8710e947fd072c274a7cb1 Mon Sep 17 00:00:00 2001 From: Harsh Rawat Date: Wed, 9 Jun 2021 15:30:03 -0700 Subject: [PATCH 6/6] Updated values for max retry during network setup --- agent/ecscni/plugin_windows_test.go | 5 ++++- agent/ecscni/types_windows.go | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/agent/ecscni/plugin_windows_test.go b/agent/ecscni/plugin_windows_test.go index 09826b46299..d719864a812 100644 --- a/agent/ecscni/plugin_windows_test.go +++ b/agent/ecscni/plugin_windows_test.go @@ -103,6 +103,9 @@ func TestSetupNSTimeout(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() + // Override the maximum retry timeout for the tests + setupNSBackoffMax = setupNSBackoffMin + ecscniClient := NewClient("") libcniClient := mock_libcni.NewMockCNI(ctrl) ecscniClient.(*cniClient).libcni = libcniClient @@ -111,7 +114,7 @@ func TestSetupNSTimeout(t *testing.T) { // vpc-eni plugin will be called. libcniClient.EXPECT().AddNetwork(gomock.Any(), gomock.Any(), gomock.Any()).Return(¤t.Result{}, errors.New("timeout")).Do( func(ctx context.Context, net *libcni.NetworkConfig, rt *libcni.RuntimeConf) { - }).MaxTimes(3), + }).MaxTimes(setupNSMaxRetryCount), ) config := getNetworkConfig() diff --git a/agent/ecscni/types_windows.go b/agent/ecscni/types_windows.go index 029fc30d69b..46b0bbdb003 100644 --- a/agent/ecscni/types_windows.go +++ b/agent/ecscni/types_windows.go @@ -28,12 +28,16 @@ const ( ECSVPCENIPluginExecutable = "vpc-eni.exe" // ECSBridgeNetworkName is the name of the HNS network used as ecs-bridge. ECSBridgeNetworkName = "nat" - // Constants for creating backoff while retrying setupNS. +) + +var ( + // Values for creating backoff while retrying setupNS. + // These have not been made constant so that we can inject different values for unit tests. setupNSBackoffMin = time.Second * 4 setupNSBackoffMax = time.Minute setupNSBackoffJitter = 0.2 - setupNSBackoffMultiple = 1.3 - setupNSMaxRetryCount = 3 + setupNSBackoffMultiple = 2.0 + setupNSMaxRetryCount = 5 ) // VPCENIPluginConfig contains all the information required to invoke the vpc-eni plugin.