Skip to content

Commit

Permalink
Rebase with the dev branch in upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
chienhanlin committed Feb 27, 2023
2 parents 69495e9 + cea7a56 commit 4876121
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 43 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Changelog

## 1.69.0
* Enhancement - Use T.TempDir to create temporary test directory [#3159](https://github.com/aws/amazon-ecs-agent/pull/3159) and [#3560](https://github.com/aws/amazon-ecs-agent/pull/3560)
* Enhancement - remove set-output GitHub action command [#3487](https://github.com/aws/amazon-ecs-agent/pull/3487)
* Enhancement - periodically disconnect from ACS [#3586](https://github.com/aws/amazon-ecs-agent/pull/3586)
* Bug - Fixed a bug that incorrectly advertised the gMSA and fsx capability [#3540](https://github.com/aws/amazon-ecs-agent/pull/3540)
* Bug - Remove fallback to Docker for host port ranges assignment [#3569](https://github.com/aws/amazon-ecs-agent/pull/3569)
* Bug - fix ecs-init log message [#3577](https://github.com/aws/amazon-ecs-agent/pull/3577)
* Bug - Update CNI plugin versions, IMDS access works properly over IPv6 [#3581](https://github.com/aws/amazon-ecs-agent/pull/3581)

## 1.68.2
* Enhancement: Skip sending STSC events for internal tasks [#3541](https://github.com/aws/amazon-ecs-agent/pull/3541) and [#3559](https://github.com/aws/amazon-ecs-agent/pull/3559)
* Enhancement: Update go version in module file, update most vendored build dependencies to latest library [#3534](https://github.com/aws/amazon-ecs-agent/pull/3534) and [#3551](https://github.com/aws/amazon-ecs-agent/pull/3551)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.68.2
1.69.0
19 changes: 15 additions & 4 deletions agent/tcs/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package tcsclient

import (
"context"
"fmt"
"math/rand"
"strconv"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/aws/amazon-ecs-agent/agent/tcs/model/ecstcs"
"github.com/aws/amazon-ecs-agent/agent/wsclient"
mock_wsconn "github.com/aws/amazon-ecs-agent/agent/wsclient/wsconn/mock"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -574,6 +576,7 @@ func TestMetricsDisabled(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

ctx, cancel := context.WithCancel(context.TODO())
conn := mock_wsconn.NewMockWebsocketConn(ctrl)
mockStatsEngine := mock_stats.NewMockEngine(ctrl)

Expand All @@ -583,10 +586,12 @@ func TestMetricsDisabled(t *testing.T) {
cs.SetConnection(conn)

published := make(chan struct{})
readed := make(chan struct{})
read := make(chan struct{})

// stats engine should only be called for getting health metrics
mockStatsEngine.EXPECT().GetPublishMetricsTicker().Return(time.NewTicker(config.DefaultContainerMetricsPublishInterval)).MinTimes(1)
mockStatsEngine.EXPECT().GetPublishMetricsTicker().Do(func() {
cancel()
}).Return(time.NewTicker(config.DefaultContainerMetricsPublishInterval)).Times(1)
mockStatsEngine.EXPECT().GetTaskHealthMetrics().Return(&ecstcs.HealthMetadata{
Cluster: aws.String("TestMetricsDisabled"),
ContainerInstance: aws.String("container_instance"),
Expand All @@ -595,7 +600,7 @@ func TestMetricsDisabled(t *testing.T) {
}, []*ecstcs.TaskHealth{{}}, nil).MinTimes(1)
conn.EXPECT().SetReadDeadline(gomock.Any()).Return(nil).MinTimes(1)
conn.EXPECT().ReadMessage().Do(func() {
readed <- struct{}{}
read <- struct{}{}
}).Return(1, nil, nil).MinTimes(1)
conn.EXPECT().SetWriteDeadline(gomock.Any()).Return(nil).MinTimes(1)
conn.EXPECT().WriteMessage(gomock.Any(), gomock.Any()).Do(func(messageType int, data []byte) {
Expand All @@ -607,7 +612,13 @@ func TestMetricsDisabled(t *testing.T) {
assert.NoError(t, err)
}()
<-published
<-readed
<-read

// Wait for the context to be cancelled. This ensures that the publishMetrics() go routine started by cs.Serve()
// always runs and GetPublishMetricsTicker mock call is triggered.
select {
case <-ctx.Done():
}
}

func TestCreatePublishHealthRequestsEmpty(t *testing.T) {
Expand Down
73 changes: 43 additions & 30 deletions agent/utils/ephemeral_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

log "github.com/cihub/seelog"
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"
)

// From https://www.kernel.org/doc/html/latest//networking/ip-sysctl.html#ip-variables
Expand All @@ -40,7 +41,8 @@ const (

var (
// Injection point for UTs
randIntFunc = rand.Intn
randIntFunc = rand.Intn
isPortAvailableFunc = isPortAvailable
// portLock is a mutex lock used to prevent two concurrent tasks to get the same host ports.
portLock sync.Mutex
)
Expand Down Expand Up @@ -177,36 +179,12 @@ func getNumOfHostPorts(numberOfPorts int, protocol, dynamicHostPortRange string)
func getHostPortRange(numberOfPorts, start, end int, protocol string) (string, int, error) {
var resultStartPort, resultEndPort, n int
for port := start; port <= end; port++ {
portStr := strconv.Itoa(port)
// check if port is available
if protocol == "tcp" {
// net.Listen announces on the local tcp network
ln, err := net.Listen(protocol, ":"+portStr)
// either port is unavailable or some error occurred while listening, we proceed to the next port
if err != nil {
log.Debugf(portUnavailableMsg, portStr, protocol)
continue
}
// let's close the listener first
err = ln.Close()
if err != nil {
continue
}
} else if protocol == "udp" {
// net.ListenPacket announces on the local udp network
ln, err := net.ListenPacket(protocol, ":"+portStr)
// either port is unavailable or some error occurred while listening, we proceed to the next port
if err != nil {
log.Debugf(portUnavailableMsg, portStr, protocol)
continue
}
// let's close the listener first
err = ln.Close()
if err != nil {
continue
}
isAvailable, err := isPortAvailableFunc(port, protocol)
if !isAvailable || err != nil {
// either port is unavailable or some error occurred while listening or closing the listener,
// we proceed to the next port
continue
}

// check if current port is contiguous relative to lastPort
if port-resultEndPort != 1 {
resultStartPort = port
Expand Down Expand Up @@ -262,3 +240,38 @@ func verifyPortsWithinRange(actualPortRange, expectedPortRange string) bool {

return false
}

// isPortAvailable checks if a port is available
func isPortAvailable(port int, protocol string) (bool, error) {
portStr := strconv.Itoa(port)
switch protocol {
case "tcp":
// net.Listen announces on the local tcp network
ln, err := net.Listen(protocol, ":"+portStr)
if err != nil {
log.Debugf(portUnavailableMsg, portStr, protocol)
return false, err
}
// let's close the listener first
err = ln.Close()
if err != nil {
return false, err
}
return true, nil
case "udp":
// net.ListenPacket announces on the local udp network
ln, err := net.ListenPacket(protocol, ":"+portStr)
if err != nil {
log.Debugf(portUnavailableMsg, portStr, protocol)
return false, err
}
// let's close the listener first
err = ln.Close()
if err != nil {
return false, err
}
return true, nil
default:
return false, errors.New("invalid protocol")
}
}
26 changes: 24 additions & 2 deletions agent/utils/ephemeral_ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestGetHostPortRange(t *testing.T) {
testDynamicHostPortRange string
protocol string
expectedLastAssignedPort []int
isPortAvailableFunc func(port int, protocol string) (bool, error)
numberOfRequests int
expectedError error
}{
Expand All @@ -88,6 +89,7 @@ func TestGetHostPortRange(t *testing.T) {
testDynamicHostPortRange: "40001-40080",
protocol: testTCPProtocol,
expectedLastAssignedPort: []int{40010},
isPortAvailableFunc: func(port int, protocol string) (bool, error) { return true, nil },
numberOfRequests: 1,
expectedError: nil,
},
Expand All @@ -97,6 +99,7 @@ func TestGetHostPortRange(t *testing.T) {
testDynamicHostPortRange: "40001-40080",
protocol: testUDPProtocol,
expectedLastAssignedPort: []int{40040},
isPortAvailableFunc: func(port int, protocol string) (bool, error) { return true, nil },
numberOfRequests: 1,
expectedError: nil,
},
Expand All @@ -106,6 +109,7 @@ func TestGetHostPortRange(t *testing.T) {
testDynamicHostPortRange: "40001-40080",
protocol: testTCPProtocol,
expectedLastAssignedPort: []int{40060, 40000},
isPortAvailableFunc: func(port int, protocol string) (bool, error) { return true, nil },
numberOfRequests: 2,
expectedError: nil,
},
Expand All @@ -115,24 +119,42 @@ func TestGetHostPortRange(t *testing.T) {
testDynamicHostPortRange: "40001-40080",
protocol: testUDPProtocol,
expectedLastAssignedPort: []int{40015},
isPortAvailableFunc: func(port int, protocol string) (bool, error) { return true, nil },
numberOfRequests: 1,
expectedError: nil,
},
{
testName: "contiguous hostPortRange not found",
testName: "contiguous hostPortRange not found, numberOfPorts more than available",
numberOfPorts: 20,
testDynamicHostPortRange: "40001-40005",
protocol: testTCPProtocol,
isPortAvailableFunc: func(port int, protocol string) (bool, error) { return true, nil },
numberOfRequests: 1,
expectedError: errors.New("20 contiguous host ports are unavailable"),
},
{
testName: "contiguous hostPortRange not found, no ports available on the host",
numberOfPorts: 5,
testDynamicHostPortRange: "40001-40005",
protocol: testTCPProtocol,
isPortAvailableFunc: func(port int, protocol string) (bool, error) { return false, nil },
numberOfRequests: 1,
expectedError: errors.New("5 contiguous host ports unavailable"),
},
}

// mock isPortAvailable() for unit test
// this ensures that the test doesn't rely on the runtime port availability on the host
isPortAvailableFuncTmp := isPortAvailableFunc
defer func() {
isPortAvailableFunc = isPortAvailableFuncTmp
}()

for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
for i := 0; i < tc.numberOfRequests; i++ {
isPortAvailableFunc = tc.isPortAvailableFunc
if tc.expectedError == nil {

hostPortRange, err := GetHostPortRange(tc.numberOfPorts, tc.protocol, tc.testDynamicHostPortRange)
assert.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions agent/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ package version
// repository. Only the 'Version' const should change in checked-in source code

// Version is the version of the Agent
const Version = "1.68.2"
const Version = "1.69.0"

// GitDirty indicates the cleanliness of the git repo when this agent was built
const GitDirty = true

// GitShortHash is the short hash of this agent build
const GitShortHash = "8188bcc0"
const GitShortHash = "0fe21da1"
2 changes: 1 addition & 1 deletion ecs-init/ECSVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.68.2
1.69.0
2 changes: 1 addition & 1 deletion ecs-init/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
// DefaultAgentVersion is the version of the agent that will be
// fetched if required. This should look like v1.2.3 or an
// 8-character sha, as is downloadable from S3.
DefaultAgentVersion = "v1.68.2"
DefaultAgentVersion = "v1.69.0"

// AgentPartitionBucketName is the name of the paritional s3 bucket that stores the agent
AgentPartitionBucketName = "amazon-ecs-agent"
Expand Down
5 changes: 4 additions & 1 deletion packaging/amazon-linux-ami-integrated/ecs-agent.spec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
%global agent_image ecs-agent-v%{version}.tar

Name: ecs-init
Version: 1.68.2
Version: 1.69.0
Release: 1%{?dist}
License: Apache 2.0
Summary: Amazon Elastic Container Service initialization application
Expand Down Expand Up @@ -269,6 +269,9 @@ fi
%endif

%changelog
* Fri Feb 24 2023 Yash Kulshrestha <kulshres@amazon.com> - 1.69.0-1
- Cache Agent version 1.69.0

* Wed Feb 08 2023 Prateek Chaudhry <ptchau@amazon.com> - 1.68.2-1
- Cache Agent version 1.68.2

Expand Down
6 changes: 6 additions & 0 deletions packaging/generic-deb-integrated/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
amazon-ecs-init (1.69.0-1) stable; urgency=medium

* Cache Agent version 1.69.0

-- Yash Kulshrestha <kulshres@amazon.com> Fri, 24 Feb 2023 18:00:00 +0000

amazon-ecs-init (1.68.2-1) stable; urgency=medium

* Cache Agent version 1.68.2
Expand Down
5 changes: 4 additions & 1 deletion packaging/generic-rpm-integrated/amazon-ecs-init.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%global agent_image ecs-agent-v%{version}.tar

Name: amazon-ecs-init
Version: 1.68.2
Version: 1.69.0
Release: 1
License: Apache 2.0
Summary: Amazon Elastic Container Service initialization application
Expand Down Expand Up @@ -92,6 +92,9 @@ ln -sf %{basename:%{agent_image}} %{_cachedir}/ecs/ecs-agent.tar
%systemd_postun_with_restart amazon-ecs-volume-plugin

%changelog
* Fri Feb 24 2023 Yash Kulshrestha <kulshres@amazon.com> - 1.69.0-1
- Cache Agent version 1.69.0

* Wed Feb 08 2023 Prateek Chaudhry <ptchau@amazon.com> - 1.68.2-1
- Cache Agent version 1.68.2

Expand Down
4 changes: 4 additions & 0 deletions packaging/suse/amazon-ecs-init.changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
-------------------------------------------------------------------
Fri Feb 24, 18:00:00 UTC 2023 - kulshres@amazon.com - 1.69.0-1

- Cache Agent version 1.69.0
-------------------------------------------------------------------
Wed Feb 08, 18:00:00 UTC 2023 - ptchau@amazon.com - 1.68.2-1

- Cache Agent version 1.68.2
Expand Down
5 changes: 5 additions & 0 deletions scripts/changelog/CHANGELOG_MASTER
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.69.0-1
Yash Kulshrestha <kulshres@amazon.com>
2023-02-24T10:00:00-08:00
Cache Agent version 1.69.0

1.68.2-1
Prateek Chaudhry <ptchau@amazon.com>
2023-02-08T10:00:00-08:00
Expand Down

0 comments on commit 4876121

Please sign in to comment.