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

detach only detachable instances #96

Merged
merged 2 commits into from
Aug 7, 2024

Conversation

akihiro17
Copy link
Contributor

@akihiro17 akihiro17 commented Aug 6, 2024

InstanceDrainer sometimes detaches instances that are not in InService or Standby for some reason.

I believe AutoScalingGroupConfig#detach_instances should only detach detachable instances because InstanceDrainer calls detach_instances directly when it receives instance interruption warnings.

ref.

config.detach_instances(instance_ids: config_to_instance_ids[config], should_decrement_desired_capacity: false)

Additionally, I exclude pending instances from detachable instances because EC2 instances sometimes stay in the Pending state for more than 10 minutes.

Note

EcsDeploy detaches only detachable instances when it executes update_desired_capacity.

ref.

auto_scaling_group_instances = describe_detachable_instances

@akihiro17 akihiro17 self-assigned this Aug 6, 2024
Comment on lines 69 to 74
instance_ids.each_slice(MAX_DETACHABLE_INSTANCE_COUNT) do |ids|
# detach only detachable instances
auto_scaling_group_instances = describe_detachable_instances
detachable_instance_ids = instance_ids.select do |instance_id|
auto_scaling_group_instances.any? { |instance| instance.instance_id == instance_id }
end
Copy link
Contributor

Choose a reason for hiding this comment

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

How about this code?

detachable_instance_ids = instance_ids & describe_detachable_instances.map(&:instance_id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in e397ae7

@akihiro17 akihiro17 force-pushed the detach-only-detachable-instances branch from dc7d04f to e397ae7 Compare August 7, 2024 02:46
@akihiro17 akihiro17 requested a review from okkez August 7, 2024 02:50
@akihiro17 akihiro17 marked this pull request as draft August 7, 2024 03:27
@akihiro17 akihiro17 marked this pull request as ready for review August 7, 2024 04:34
@akihiro17 akihiro17 merged commit 7eaf9e0 into master Aug 7, 2024
12 checks passed
@akihiro17 akihiro17 deleted the detach-only-detachable-instances branch August 7, 2024 12:51
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.

3 participants