feat(runners): support OnDemandOptions.AllocationStrategy in EC2 Fleet#5077
Open
piotrj wants to merge 5 commits intogithub-aws-runners:mainfrom
Open
feat(runners): support OnDemandOptions.AllocationStrategy in EC2 Fleet#5077piotrj wants to merge 5 commits intogithub-aws-runners:mainfrom
piotrj wants to merge 5 commits intogithub-aws-runners:mainfrom
Conversation
35e8f73 to
25c0704
Compare
Previously, createInstances always set SpotOptions.AllocationStrategy even for on-demand fleets, making instance_allocation_strategy and instance_types ordering meaningless for on-demand users wanting `prioritized`. Now the fleet request conditionally sets SpotOptions or OnDemandOptions based on targetCapacityType, and the spot-to- on-demand failover path maps spot-only strategies to `lowest-price`.
Add optional `instance_type_priorities` variable (map of instance type to priority number) to control EC2 Fleet override priorities. When not set, priorities default to the index position in `instance_types`, preserving the user's ordering. This makes the `prioritized` allocation strategy work correctly for both spot and on-demand fleets.
Move the prioritized strategy check into generateFleetOverrides itself rather than having the caller decide what to pass, making the logic more explicit and self-contained.
25c0704 to
73c147f
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Currently,
createInstancesalways setsSpotOptions.AllocationStrategyregardless of the fleet'stargetCapacityType. For on-demand fleets, AWS silently ignoresSpotOptionsand defaults tolowest-price, making theinstance_allocation_strategyvariable andinstance_typesordering meaningless for on-demand users who wantprioritized.This PR fixes that by conditionally setting
SpotOptionsorOnDemandOptionsbased ontargetCapacityType, so the allocation strategy is correctly applied for both spot and on-demand fleets.Why
instance_type_priorities?The
prioritizedallocation strategy doesn't simply use the array order of launch template overrides — it relies on an explicitPriorityfield on each override entry. Without settingPriority, all overrides have equal (lowest) priority andprioritizedeffectively behaves likelowest-price.We introduced the optional
instance_type_prioritiesvariable (map(number), e.g.{ "m5.large" = 1, "c5.large" = 2 }) as a non-breaking addition to give users explicit control over the priority assigned to each instance type. When not provided, priorities automatically fall back to the index position ininstance_types, so existing configurations continue to work unchanged — the first instance type in the list gets the highest priority (0), the second gets 1, and so on. This makesprioritizedwork correctly out of the box while still allowing fine-grained control when needed.Note: The
Priorityfield is only set on fleet overrides wheninstance_allocation_strategyis"prioritized". For all other allocation strategies, overrides remain unchanged — noPriorityis added. This ensures that existing setups using strategies likecapacity-optimizedorlowest-priceare completely unaffected by this change.What changed
Conditional
SpotOptions/OnDemandOptionscreateInstancesfunction now checkstargetCapacityTypeand setsSpotOptions(withMaxTotalPriceandAllocationStrategy) for spot fleets, orOnDemandOptions(withAllocationStrategy) for on-demand fleets."prioritized"is added to theinstance_allocation_strategyvalidation list in all Terraform variable definitions.Failover strategy mapping
capacity-optimized) are automatically mapped tolowest-priceto avoid passing invalid values toOnDemandOptions.Override priorities
generateFleetOverridessetsPriorityon each override only when the allocation strategy isprioritized. It usesinstance_type_prioritiesif provided, or the index ininstance_typesotherwise.instance_type_prioritiesvariable is threaded through the full chain: root Terraform variables → runners module → Lambda environment variables (INSTANCE_TYPE_PRIORITIESas JSON) →ec2instanceCriteria→generateFleetOverrides.