Skip to content

Commit

Permalink
Exclude pending instances from detachable instances
Browse files Browse the repository at this point in the history
  • Loading branch information
akihiro17 committed Aug 7, 2024
1 parent e397ae7 commit c3c0d82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/ecs_deploy/auto_scaler/auto_scaling_group_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def describe_detachable_instances
client.describe_auto_scaling_groups({ auto_scaling_group_names: [name] }).auto_scaling_groups[0].instances.reject do |i|
# The lifecycle state of terminated instances becomes "Detaching", "Terminating", "Terminating:Wait", or "Terminating:Proceed",
# and we can't detach instances in such a state.
i.lifecycle_state.start_with?("Terminating") || i.lifecycle_state == "Detaching"
i.lifecycle_state.start_with?("Terminating") || i.lifecycle_state == "Detaching" ||
# EC2 instance sometimes stays in Pending state for more than 10 minutes
i.lifecycle_state == "Pending"
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/ecs_deploy/auto_scaler/auto_scaling_group_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@
launch_template: "launch_template",
protected_from_scale_in: true,
),
Aws::AutoScaling::Types::Instance.new(
instance_id: "i-444444",
availability_zone: "ap-notrheast-1c",
lifecycle_state: "Pending",
health_status: "",
launch_template: "launch_template",
protected_from_scale_in: true,
),
]
end

Expand Down

0 comments on commit c3c0d82

Please sign in to comment.