Skip to content

Commit 09bb239

Browse files
authored
Merge pull request #1463 from vincepri/remove-get-rootdevicesize
⚠️ Remove check for root volume size
2 parents 9991024 + 938b413 commit 09bb239

File tree

2 files changed

+0
-124
lines changed

2 files changed

+0
-124
lines changed

pkg/cloud/services/ec2/instances.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -541,28 +541,6 @@ func (s *Service) getImageRootDevice(imageID string) (*string, error) {
541541
return output.Images[0].RootDeviceName, nil
542542
}
543543

544-
func (s *Service) getInstanceRootDeviceSize(instance *ec2.Instance) (*int64, error) {
545-
for _, bdm := range instance.BlockDeviceMappings {
546-
if aws.StringValue(bdm.DeviceName) == aws.StringValue(instance.RootDeviceName) {
547-
input := &ec2.DescribeVolumesInput{
548-
VolumeIds: []*string{bdm.Ebs.VolumeId},
549-
}
550-
551-
out, err := s.scope.EC2.DescribeVolumes(input)
552-
if err != nil {
553-
return nil, err
554-
}
555-
556-
if len(out.Volumes) == 0 {
557-
return nil, errors.Errorf("no volumes found for id %q", aws.StringValue(bdm.Ebs.VolumeId))
558-
}
559-
560-
return out.Volumes[0].Size, nil
561-
}
562-
}
563-
return nil, errors.Errorf("no root volume found for EC2 instance %q", *instance.InstanceId)
564-
}
565-
566544
// SDKToInstance converts an AWS EC2 SDK instance to the CAPA instance type.
567545
// SDKToInstance populates all instance fields except for rootVolumeSize,
568546
// because EC2.DescribeInstances does not return the size of storage devices. An
@@ -599,12 +577,6 @@ func (s *Service) SDKToInstance(v *ec2.Instance) (*infrav1.Instance, error) {
599577
i.Tags = converters.TagsToMap(v.Tags)
600578
}
601579

602-
rootSize, err := s.getInstanceRootDeviceSize(v)
603-
if err != nil {
604-
return nil, errors.Wrapf(err, "unable to get root volume size for instance: %q", aws.StringValue(v.InstanceId))
605-
}
606-
i.RootDeviceSize = aws.Int64Value(rootSize)
607-
608580
i.Addresses = s.getInstanceAddresses(v)
609581

610582
return i, nil

pkg/cloud/services/ec2/instances_test.go

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,6 @@ func TestInstanceIfExists(t *testing.T) {
102102
},
103103
}, nil)
104104

105-
m.DescribeVolumes(gomock.Eq(&ec2.DescribeVolumesInput{
106-
VolumeIds: []*string{aws.String("volume-1")},
107-
})).Return(&ec2.DescribeVolumesOutput{
108-
Volumes: []*ec2.Volume{
109-
{
110-
VolumeId: aws.String("volume-1"),
111-
Size: aws.Int64(60),
112-
},
113-
},
114-
}, nil)
115105
},
116106
check: func(instance *infrav1.Instance, err error) {
117107
if err != nil {
@@ -142,42 +132,6 @@ func TestInstanceIfExists(t *testing.T) {
142132
}
143133
},
144134
},
145-
{
146-
name: "instance without root volume, returns error",
147-
instanceID: "one",
148-
expect: func(m *mock_ec2iface.MockEC2APIMockRecorder) {
149-
m.DescribeInstances(&ec2.DescribeInstancesInput{
150-
InstanceIds: []*string{aws.String("one")},
151-
}).
152-
Return(&ec2.DescribeInstancesOutput{
153-
Reservations: []*ec2.Reservation{
154-
{
155-
Instances: []*ec2.Instance{
156-
{
157-
InstanceId: aws.String("id-1"),
158-
InstanceType: aws.String("m5.large"),
159-
SubnetId: aws.String("subnet-1"),
160-
ImageId: aws.String("ami-1"),
161-
IamInstanceProfile: &ec2.IamInstanceProfile{
162-
Arn: aws.String("arn:aws:iam::123456789012:instance-profile/foo"),
163-
},
164-
State: &ec2.InstanceState{
165-
Code: aws.Int64(16),
166-
Name: aws.String(ec2.StateAvailable),
167-
},
168-
RootDeviceName: aws.String("404-not-found"),
169-
},
170-
},
171-
},
172-
},
173-
}, nil)
174-
},
175-
check: func(i *infrav1.Instance, err error) {
176-
if err == nil {
177-
t.Fatalf("expected an error but got none.")
178-
}
179-
},
180-
},
181135
}
182136

183137
for _, tc := range testCases {
@@ -394,16 +348,6 @@ func TestCreateInstance(t *testing.T) {
394348
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
395349
Return(nil)
396350

397-
m.DescribeVolumes(gomock.Eq(&ec2.DescribeVolumesInput{
398-
VolumeIds: []*string{aws.String("volume-1")},
399-
})).Return(&ec2.DescribeVolumesOutput{
400-
Volumes: []*ec2.Volume{
401-
{
402-
VolumeId: aws.String("volume-1"),
403-
Size: aws.Int64(60),
404-
},
405-
},
406-
}, nil)
407351
},
408352
check: func(instance *infrav1.Instance, err error) {
409353
if err != nil {
@@ -518,16 +462,6 @@ func TestCreateInstance(t *testing.T) {
518462
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
519463
Return(nil)
520464

521-
m.DescribeVolumes(gomock.Eq(&ec2.DescribeVolumesInput{
522-
VolumeIds: []*string{aws.String("volume-1")},
523-
})).Return(&ec2.DescribeVolumesOutput{
524-
Volumes: []*ec2.Volume{
525-
{
526-
VolumeId: aws.String("volume-1"),
527-
Size: aws.Int64(60),
528-
},
529-
},
530-
}, nil)
531465
},
532466
check: func(instance *infrav1.Instance, err error) {
533467
if err != nil {
@@ -655,16 +589,6 @@ func TestCreateInstance(t *testing.T) {
655589
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
656590
Return(nil)
657591

658-
m.DescribeVolumes(gomock.Eq(&ec2.DescribeVolumesInput{
659-
VolumeIds: []*string{aws.String("volume-1")},
660-
})).Return(&ec2.DescribeVolumesOutput{
661-
Volumes: []*ec2.Volume{
662-
{
663-
VolumeId: aws.String("volume-1"),
664-
Size: aws.Int64(60),
665-
},
666-
},
667-
}, nil)
668592
},
669593
check: func(instance *infrav1.Instance, err error) {
670594
if err != nil {
@@ -788,16 +712,6 @@ func TestCreateInstance(t *testing.T) {
788712
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
789713
Return(nil)
790714

791-
m.DescribeVolumes(gomock.Eq(&ec2.DescribeVolumesInput{
792-
VolumeIds: []*string{aws.String("volume-1")},
793-
})).Return(&ec2.DescribeVolumesOutput{
794-
Volumes: []*ec2.Volume{
795-
{
796-
VolumeId: aws.String("volume-1"),
797-
Size: aws.Int64(60),
798-
},
799-
},
800-
}, nil)
801715
},
802716
check: func(instance *infrav1.Instance, err error) {
803717
if err != nil {
@@ -922,16 +836,6 @@ func TestCreateInstance(t *testing.T) {
922836
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
923837
Return(nil)
924838

925-
m.DescribeVolumes(gomock.Eq(&ec2.DescribeVolumesInput{
926-
VolumeIds: []*string{aws.String("volume-1")},
927-
})).Return(&ec2.DescribeVolumesOutput{
928-
Volumes: []*ec2.Volume{
929-
{
930-
VolumeId: aws.String("volume-1"),
931-
Size: aws.Int64(60),
932-
},
933-
},
934-
}, nil)
935839
},
936840
check: func(instance *infrav1.Instance, err error) {
937841
if err != nil {

0 commit comments

Comments
 (0)