Skip to content

Commit

Permalink
setupRootDevice (AKA add delete-on-termination to root)
Browse files Browse the repository at this point in the history
  • Loading branch information
medwards committed Sep 6, 2016
1 parent ee0f919 commit e2da95f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Expand Up @@ -457,6 +457,7 @@ private EC2AbstractSlave provisionOndemand(TaskListener listener, Label required

riRequest.setEbsOptimized(ebsOptimized);

setupRootDevice(riRequest.getBlockDeviceMappings());
if (useEphemeralDevices) {
setupEphemeralDeviceMapping(riRequest);
} else {
Expand Down Expand Up @@ -627,6 +628,27 @@ private EC2AbstractSlave provisionOndemand(TaskListener listener, Label required
}
}

private void setupRootDevice(List<BlockDeviceMapping> deviceMappings) {
if (deleteRootOnTermination && getImage().getRootDeviceType().equals("ebs")) {
// Capture all the devices named in the AMI
// use this later to ensure we only set flags on root devices
// therefore this can be skipped if we guarantee that setupRootDevice is run before all
// other mapping related stuff
final List<BlockDeviceMapping> rootDeviceMappings = getAmiBlockDeviceMappings();
final Set<String> rootDeviceNames = new HashSet<String>();
for (final BlockDeviceMapping rootMapping : rootDeviceMappings) {
rootDeviceNames.add(rootMapping.getDeviceName());
}

// Go through the mappings in the request, update only the root devices
for (final BlockDeviceMapping mapping : deviceMappings) {
if (rootDeviceNames.contains(mapping.getDeviceName())) {
mapping.getEbs().setDeleteOnTermination(Boolean.TRUE);
}
}
}
}

private List<BlockDeviceMapping> getNewEphemeralDeviceMapping() {

final List<BlockDeviceMapping> oldDeviceMapping = getAmiBlockDeviceMappings();
Expand Down Expand Up @@ -808,6 +830,7 @@ private EC2AbstractSlave provisionSpot(TaskListener listener) throws AmazonClien
launchSpecification.setIamInstanceProfile(new IamInstanceProfileSpecification().withArn(getIamInstanceProfile()));
}

setupRootDevice(launchSpecification.getBlockDeviceMappings());
if (useEphemeralDevices) {
setupEphemeralDeviceMapping(launchSpecification);
} else {
Expand Down

0 comments on commit e2da95f

Please sign in to comment.