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

EC2 task networking for Windows: Build vpc-eni CNI plugin for Windows #2893

Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we remove the -v ?

Copy link
Contributor Author

@rawahars rawahars Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By removing this flag, we are able to remove the excess noise from the UTs during PR. We can very easily pin point the UT which failed and the corresponding error. For example - https://github.com/aws/amazon-ecs-agent/runs/2786834601?check_suite_focus=true

Also, this ensures that the behavior is same for Linux and Windows UT during PR build.
This change was implemented after discussion with @fenxiong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

4 changes: 0 additions & 4 deletions agent/ecscni/plugin_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 0 additions & 33 deletions agent/ecscni/plugin_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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))
}
62 changes: 62 additions & 0 deletions agent/ecscni/plugin_test.go
Original file line number Diff line number Diff line change
@@ -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 = "941c5280e8a3329194cd78454454332610333822"
)

// 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))
}
5 changes: 4 additions & 1 deletion agent/ecscni/plugin_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(&current.Result{}, errors.New("timeout")).Do(
func(ctx context.Context, net *libcni.NetworkConfig, rt *libcni.RuntimeConf) {
}).MaxTimes(3),
}).MaxTimes(setupNSMaxRetryCount),
)

config := getNetworkConfig()
Expand Down
10 changes: 7 additions & 3 deletions agent/ecscni/types_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion amazon-vpc-cni-plugins
Submodule amazon-vpc-cni-plugins updated 38 files
+15 −1 Makefile
+3 −0 network/netns/netns_linux.go
+112 −0 plugins/vpc-eni/config/netconfig.go
+39 −0 plugins/vpc-eni/main.go
+47 −0 plugins/vpc-eni/network/network.go
+37 −0 plugins/vpc-eni/network/network_linux.go
+420 −0 plugins/vpc-eni/network/network_windows.go
+168 −0 plugins/vpc-eni/plugin/commands.go
+69 −0 plugins/vpc-eni/plugin/plugin.go
+10 −0 plugins/vpc-eni/vpc-eni.conf
+0 −191 vendor/github.com/Microsoft/hcsshim/cmd/runhcs/LICENSE
+0 −22 vendor/github.com/Microsoft/hcsshim/cmd/runhcs/NOTICE
+150 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcn.go
+365 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcnendpoint.go
+95 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcnerrors.go
+81 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcnglobals.go
+312 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcnloadbalancer.go
+423 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcnnamespace.go
+334 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcnnetwork.go
+207 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcnpolicy.go
+64 −0 vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go
+613 −0 vendor/github.com/Microsoft/hcsshim/hcn/zsyscall_windows.go
+110 −0 vendor/github.com/Microsoft/hcsshim/internal/cni/registry.go
+287 −0 vendor/github.com/Microsoft/hcsshim/internal/regstate/regstate.go
+51 −0 vendor/github.com/Microsoft/hcsshim/internal/regstate/zsyscall_windows.go
+71 −0 vendor/github.com/Microsoft/hcsshim/internal/runhcs/container.go
+16 −0 vendor/github.com/Microsoft/hcsshim/internal/runhcs/util.go
+43 −0 vendor/github.com/Microsoft/hcsshim/internal/runhcs/vm.go
+0 −938 vendor/github.com/Microsoft/hcsshim/mksyscall_windows.go
+0 −201 vendor/github.com/Microsoft/hcsshim/pkg/go-runhcs/LICENSE
+0 −22 vendor/github.com/Microsoft/hcsshim/pkg/go-runhcs/NOTICE
+198 −0 vendor/golang.org/x/sys/windows/registry/key.go
+7 −0 vendor/golang.org/x/sys/windows/registry/mksyscall.go
+32 −0 vendor/golang.org/x/sys/windows/registry/syscall.go
+384 −0 vendor/golang.org/x/sys/windows/registry/value.go
+120 −0 vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go
+54 −4 vendor/golang.org/x/sys/windows/syscall_windows.go
+3 −1 vendor/golang.org/x/sys/windows/types_windows.go
3 changes: 1 addition & 2 deletions scripts/dockerfiles/Dockerfile.buildWindowsVPCCNIPlugins
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions scripts/local-save
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down