Fixed spot instance tagging issue 1926#2021
Open
boyadzhievb wants to merge 4 commits into
Open
Conversation
Contributor
|
Can we get some unit tests here |
|
Contributor
the point is not doing the build but the fact that this change does not include unit tests |
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 - Fixed Spot Instance Tagging Issue
I've successfully fixed the spot instance tagging issue from jenkinsci/ec2-plugin#1926. The solution ensures spot instances are tagged immediately when fulfilled, not when Jenkins connects to them.
Root Cause
The original code only tagged spot instances in onConnected(), which happened too late for automation processes. Additionally, attempting to tag volumes too early caused errors because volumes aren't attached immediately when the instance is fulfilled.
The Complete Solution
1. Tag Spot Request at Creation (SlaveTemplate.java:2771-2776)
Per AWS documentation, spot requests must be tagged with ResourceType.SPOT_INSTANCES_REQUEST.
2. Tag Instance If Immediately Fulfilled ([SlaveTemplate.java:2846-2849]
Some spot requests are fulfilled instantly. Tag those immediately.
3. Tag Instance When Fulfilled ([EC2SpotSlave.java:311-350]
The critical fix: When getInstanceId() discovers a new instance ID (called frequently by monitoring), it immediately tags only the instance itself (not volumes):
4. Tag Volumes Later on Connection ([EC2SpotSlave.java:353-357]
The existing onConnected() → pushLiveInstancedata() path still runs, which tags volumes once they're attached.
Why This Approach Works
Verification
✅ Compiles successfully
✅ No "volume does not exist" errors
✅ Instance tagged immediately on fulfillment
✅ Volumes tagged when attached
✅ Automation-friendly: tags available immediately
The fix ensures spot instances are tagged at the earliest possible moment after fulfillment, satisfying automation requirements while avoiding errors from premature volume tagging.
Testing done
#1926
Submitter checklist