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

Stop task on signal #383

Merged
merged 11 commits into from
Aug 18, 2024
Merged

Stop task on signal #383

merged 11 commits into from
Aug 18, 2024

Conversation

yonran
Copy link
Contributor

@yonran yonran commented Jan 27, 2023

feat: Include fractional seconds in the log messages

feat: Use Session to create Credentials (to support more credential resolutions such as sso_account_id in ~/.aws/config)

feat: Stop task on timeout or signal. Previously, when the --timeout was hit or ecs-task was interrupted, it exited immediately without cleaning anything up. This commit makes ecs-task call StopTask, followed by waiting up to 1 minute for the task to complete, followed by waiting 10 seconds for any additional logs.

session.New is deprecated because errors are not caught until the first service request is made.
When ecs.RunTask is called with Count unset, then there should always be exactly 1 task. This commit simplifies the code under that assumption so that we do not need an array of tasks. Also I don't think some of the functions worked anyway with multiple tasks (e.g. waitExitTasks returned when the first task finished instead of the last task).
We accidentally discarded the cancel when timeout is enabled, although at this point Cancel was unused
Pass a mostly empty aws.Config{} to session.NewSession (instead of defaults.Get().Config). The defaults package “shouldn't be used directly, but session.Session instead” (https://github.com/aws/aws-sdk-go/blob/v1.44.14/aws/defaults/defaults.go#L4-L5) When we called defaults.Get(), then Config.Credentials was set to a CredChain instead of AnonymousCredentials, which prevented Session from resolving credentials (https://github.com/aws/aws-sdk-go/blob/v1.44.14/aws/session/session.go#L783-L785).

Changes in behavior:

* Read the profile name from the AWS_PROFILE environment variable instead of the nonstandard AWS_DEFAULT_PROFILE
* Read the additional fields in ~/.aws/config that credentials.resolveCredsFromProfile understands but SharedCredentialsProvider does not:
  * source_profile
  * credential_source
  * web_identity_token_file, role_arn, role_session_name
  * sso_account_id, sso_region, sso_role_name, sso_start_url
  * credential_process
  * role_arn
* Read the "default" profile as a fallback if the given profile does not work
When the Context is Done (e.g. timeout), cancel the AWS requests immediately rather than waiting for them to complete.
Previously, when the --timeout was hit or ecs-task was interrupted, it exited immediately without cleaning anything up. This commit makes ecs-task call StopTask, followed by waiting up to 1 minute for the task to complete, followed by waiting 10 seconds for any additional logs.
Fix tests: mock the *WithContext methods now that we are using those instead
@h3poteto h3poteto self-requested a review August 17, 2024 15:32
Copy link
Owner

@h3poteto h3poteto left a comment

Choose a reason for hiding this comment

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

LGTM

@h3poteto h3poteto merged commit 5344068 into h3poteto:master Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants