Skip to content

Commit

Permalink
Fix handling of block devices with NoDevice=true
Browse files Browse the repository at this point in the history
Spot instances have been seen to fail to launch if this attribute is set to
true.

We can just skip the volume from the instance block device mappings if this
field is set, instead of actually propagating the true value that
eventually has the same result.
  • Loading branch information
cristim committed Jul 4, 2019
1 parent 8792748 commit 51dbac2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
9 changes: 4 additions & 5 deletions core/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,12 @@ func (i *instance) convertBlockDeviceMappings(lc *launchConfiguration) []*ec2.Bl
}
}

// it turns out that the noDevice field needs to be converted from bool to
// *string
if lcBDM.NoDevice != nil {
ec2BDM.NoDevice = aws.String(fmt.Sprintf("%t", *lcBDM.NoDevice))
// handle the noDevice field directly by skipping the device if set to true
if lcBDM.NoDevice != nil && *lcBDM.NoDevice {
continue
}

bds = append(bds, ec2BDM)

}
return bds
}
Expand Down
14 changes: 2 additions & 12 deletions core/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1367,36 +1367,28 @@ func Test_instance_convertBlockDeviceMappings(t *testing.T) {
want: []*ec2.BlockDeviceMapping{},
},
{
name: "instance-store only",
name: "instance-store only, skipping one of the volumes from the BDMs",
lc: &launchConfiguration{
LaunchConfiguration: &autoscaling.LaunchConfiguration{
BlockDeviceMappings: []*autoscaling.BlockDeviceMapping{
{
DeviceName: aws.String("/dev/ephemeral0"),
Ebs: nil,
NoDevice: aws.Bool(false),
NoDevice: aws.Bool(true),
VirtualName: aws.String("foo"),
},
{
DeviceName: aws.String("/dev/ephemeral1"),
Ebs: nil,
NoDevice: aws.Bool(false),
VirtualName: aws.String("bar"),
},
},
},
},
want: []*ec2.BlockDeviceMapping{
{
DeviceName: aws.String("/dev/ephemeral0"),
Ebs: nil,
NoDevice: aws.String("false"),
VirtualName: aws.String("foo"),
},
{
DeviceName: aws.String("/dev/ephemeral1"),
Ebs: nil,
NoDevice: aws.String("false"),
VirtualName: aws.String("bar"),
},
},
Expand All @@ -1410,7 +1402,6 @@ func Test_instance_convertBlockDeviceMappings(t *testing.T) {
{
DeviceName: aws.String("/dev/ephemeral0"),
Ebs: nil,
NoDevice: aws.Bool(false),
VirtualName: aws.String("foo"),
},
{
Expand All @@ -1436,7 +1427,6 @@ func Test_instance_convertBlockDeviceMappings(t *testing.T) {
{
DeviceName: aws.String("/dev/ephemeral0"),
Ebs: nil,
NoDevice: aws.String("false"),
VirtualName: aws.String("foo"),
},
{
Expand Down

0 comments on commit 51dbac2

Please sign in to comment.