-
Notifications
You must be signed in to change notification settings - Fork 618
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
Migrate ECS client to aws-sdk-go-v2 #4447
Open
tinnywang
wants to merge
18
commits into
aws:dev
Choose a base branch
from
tinnywang:aws-sdk-go-v2/ecs
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d763eee
migrate ecs-agent/api/ecs
tinnywang d7f7a27
migrate ecs-agent/utils
tinnywang e64f752
migrate ecs-agent/tmds/handlers/taskprotection/v1
tinnywang 99a016e
migrate agent module
tinnywang 98226e0
migrate ECS client credential provider
tinnywang bdce259
ecs-agent/api/errors package handles SDK v1 and v2 errors
tinnywang ac956e9
regenerate code
tinnywang c3cc11b
handle SDK v2 errors in task protection handlers
tinnywang bea4e89
fix tests
tinnywang 5124bd9
migrate remaining packages
tinnywang b7ab4bb
remove SDK v1 ECS client
tinnywang 76f9073
cleanup
tinnywang 50f1c9a
update more error handling
tinnywang c5bf057
fix windows test
tinnywang 447b0eb
fix after rebase
tinnywang 443e1d5
Merge branch 'dev' into aws-sdk-go-v2/ecs
Yiyuanzzz 029b479
Merge branch 'dev' into aws-sdk-go-v2/ecs
Yiyuanzzz 6b5700a
Merge branch 'dev' into aws-sdk-go-v2/ecs
Yiyuanzzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,12 @@ import ( | |
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachment" | ||
apicontainerstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/status" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs" | ||
ecsmodel "github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs/model/ecs" | ||
apitaskstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/task/status" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/logger" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/logger/field" | ||
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/utils" | ||
"github.com/aws/aws-sdk-go-v2/service/ecs/types" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/docker/go-connections/nat" | ||
|
@@ -327,7 +327,7 @@ func (c *ContainerStateChange) ToECSAgent() (*ecs.ContainerStateChange, error) { | |
Status: c.Status, | ||
ImageDigest: aws.StringValue(pl.ImageDigest), | ||
Reason: aws.StringValue(pl.Reason), | ||
ExitCode: utils.Int64PtrToIntPtr(pl.ExitCode), | ||
ExitCode: utils.Int32PtrToIntPtr(pl.ExitCode), | ||
NetworkBindings: pl.NetworkBindings, | ||
MetadataGetter: newContainerMetadataGetter(c.Container), | ||
}, nil | ||
|
@@ -424,11 +424,11 @@ func (change *TaskStateChange) ToECSAgent() (*ecs.TaskStateChange, error) { | |
|
||
for _, managedAgentEvent := range change.ManagedAgents { | ||
if mgspl := buildManagedAgentStateChangePayload(managedAgentEvent); mgspl != nil { | ||
output.ManagedAgents = append(output.ManagedAgents, mgspl) | ||
output.ManagedAgents = append(output.ManagedAgents, *mgspl) | ||
} | ||
} | ||
|
||
containerEvents := make([]*ecsmodel.ContainerStateChange, len(change.Containers)) | ||
containerEvents := make([]types.ContainerStateChange, len(change.Containers)) | ||
for i, containerEvent := range change.Containers { | ||
payload, err := buildContainerStateChangePayload(containerEvent) | ||
if err != nil { | ||
|
@@ -438,7 +438,7 @@ func (change *TaskStateChange) ToECSAgent() (*ecs.TaskStateChange, error) { | |
}) | ||
return nil, err | ||
} | ||
containerEvents[i] = payload | ||
containerEvents[i] = *payload | ||
} | ||
output.Containers = containerEvents | ||
|
||
|
@@ -481,7 +481,7 @@ func (AttachmentStateChange) GetEventType() statechange.EventType { | |
return statechange.AttachmentEvent | ||
} | ||
|
||
func buildManagedAgentStateChangePayload(change ManagedAgentStateChange) *ecsmodel.ManagedAgentStateChange { | ||
func buildManagedAgentStateChangePayload(change ManagedAgentStateChange) *types.ManagedAgentStateChange { | ||
if !change.Status.ShouldReportToBackend() { | ||
logger.Warn("Not submitting unsupported managed agent state", logger.Fields{ | ||
field.Status: change.Status.String(), | ||
|
@@ -490,19 +490,19 @@ func buildManagedAgentStateChangePayload(change ManagedAgentStateChange) *ecsmod | |
}) | ||
return nil | ||
} | ||
return &ecsmodel.ManagedAgentStateChange{ | ||
ManagedAgentName: aws.String(change.Name), | ||
return &types.ManagedAgentStateChange{ | ||
ManagedAgentName: types.ManagedAgentName(change.Name), | ||
ContainerName: aws.String(change.Container.Name), | ||
Status: aws.String(change.Status.String()), | ||
Reason: aws.String(change.Reason), | ||
} | ||
} | ||
|
||
func buildContainerStateChangePayload(change ContainerStateChange) (*ecsmodel.ContainerStateChange, error) { | ||
func buildContainerStateChangePayload(change ContainerStateChange) (*types.ContainerStateChange, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as this previous comment applies here too. |
||
if change.ContainerName == "" { | ||
return nil, fmt.Errorf("container state change has no container name") | ||
} | ||
statechange := &ecsmodel.ContainerStateChange{ | ||
statechange := types.ContainerStateChange{ | ||
ContainerName: aws.String(change.ContainerName), | ||
} | ||
if change.RuntimeID != "" { | ||
|
@@ -534,8 +534,8 @@ func buildContainerStateChangePayload(change ContainerStateChange) (*ecsmodel.Co | |
statechange.Status = aws.String(stat.BackendStatusString()) | ||
|
||
if change.ExitCode != nil { | ||
exitCode := int64(aws.IntValue(change.ExitCode)) | ||
statechange.ExitCode = aws.Int64(exitCode) | ||
exitCode := int32(aws.IntValue(change.ExitCode)) | ||
statechange.ExitCode = aws.Int32(exitCode) | ||
} | ||
|
||
networkBindings := getNetworkBindings(change) | ||
|
@@ -547,7 +547,7 @@ func buildContainerStateChangePayload(change ContainerStateChange) (*ecsmodel.Co | |
} | ||
statechange.NetworkBindings = networkBindings | ||
|
||
return statechange, nil | ||
return &statechange, nil | ||
} | ||
|
||
// ProtocolBindIP used to store protocol and bindIP information associated to a particular host port | ||
|
@@ -557,8 +557,8 @@ type ProtocolBindIP struct { | |
} | ||
|
||
// getNetworkBindings returns the list of networkingBindings, sent to ECS as part of the container state change payload | ||
func getNetworkBindings(change ContainerStateChange) []*ecsmodel.NetworkBinding { | ||
networkBindings := []*ecsmodel.NetworkBinding{} | ||
func getNetworkBindings(change ContainerStateChange) []types.NetworkBinding { | ||
networkBindings := []types.NetworkBinding{} | ||
// hostPortToProtocolBindIPMap is a map to store protocol and bindIP information associated to host ports | ||
// that belong to a range. This is used in case when there are multiple protocol/bindIP combinations associated to a | ||
// port binding. example: when both IPv4 and IPv6 bindIPs are populated by docker. | ||
|
@@ -571,22 +571,22 @@ func getNetworkBindings(change ContainerStateChange) []*ecsmodel.NetworkBinding | |
containerPortRangeMap := change.Container.GetContainerPortRangeMap() | ||
|
||
for _, binding := range change.PortBindings { | ||
hostPort := int64(binding.HostPort) | ||
containerPort := int64(binding.ContainerPort) | ||
containerPort := int32(binding.ContainerPort) | ||
bindIP := binding.BindIP | ||
protocol := binding.Protocol.String() | ||
|
||
// create network binding for each containerPort that exists in the singular ContainerPortSet | ||
// for container ports that belong to a range, we'll have 1 consolidated network binding for the range | ||
if _, ok := containerPortSet[int(containerPort)]; ok { | ||
networkBindings = append(networkBindings, &ecsmodel.NetworkBinding{ | ||
networkBindings = append(networkBindings, types.NetworkBinding{ | ||
BindIP: aws.String(bindIP), | ||
ContainerPort: aws.Int64(containerPort), | ||
HostPort: aws.Int64(hostPort), | ||
Protocol: aws.String(protocol), | ||
ContainerPort: aws.Int32(containerPort), | ||
HostPort: aws.Int32(int32(binding.HostPort)), | ||
Protocol: types.TransportProtocol(protocol), | ||
}) | ||
} else { | ||
// populate hostPortToProtocolBindIPMap – this is used below when we construct network binding for ranges. | ||
hostPort := int64(binding.HostPort) | ||
hostPortToProtocolBindIPMap[hostPort] = append(hostPortToProtocolBindIPMap[hostPort], | ||
ProtocolBindIP{ | ||
protocol: protocol, | ||
|
@@ -601,11 +601,11 @@ func getNetworkBindings(change ContainerStateChange) []*ecsmodel.NetworkBinding | |
hostPort, _, _ := nat.ParsePortRangeToInt(hostPortRange) | ||
if val, ok := hostPortToProtocolBindIPMap[int64(hostPort)]; ok { | ||
for _, v := range val { | ||
networkBindings = append(networkBindings, &ecsmodel.NetworkBinding{ | ||
networkBindings = append(networkBindings, types.NetworkBinding{ | ||
BindIP: aws.String(v.bindIP), | ||
ContainerPortRange: aws.String(containerPortRange), | ||
HostPortRange: aws.String(hostPortRange), | ||
Protocol: aws.String(v.protocol), | ||
Protocol: types.TransportProtocol(v.protocol), | ||
}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any specific reason why we don't just return type
types.ManagedAgentStateChange
here? Returning pointer type*types.ManagedAgentStateChange
here seems unnecessary to me (i.e., we just end up dereferencing on L427 anyway), but I may be missing something. It seems like in most other places in this pull request we replace*ecsmodel.<INSERT TYPE HERE>
withtypes.<INSERT TYPE HERE>
as opposed to*types.<INSERT TYPE HERE>
.