Skip to content

Commit 48dfb6c

Browse files
authored
Merge pull request #118 from pp511/avoid_paniv-with-missing-drive-type
PWX-27046: Avoid panic when drive type is not specified.
2 parents 5334d41 + 2fe5178 commit 48dfb6c

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

aws/aws.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewClient() (cloudops.Ops, error) {
6161
if err != nil {
6262
if awsErr, ok := err.(awserr.Error); ok {
6363
logrus.Infof("Code %v", awsErr.Code())
64-
}
64+
}
6565
}
6666
if err != nil {
6767
runningOnEc2 = false
@@ -517,13 +517,13 @@ var RatelimitingExponentialBackoff = wait.Backoff{
517517
Duration: 2 * time.Second, // the base duration
518518
Factor: 2.0, // Duration is multiplied by factor each iteration
519519
Jitter: 1.0, // The amount of jitter applied each iteration
520-
Steps: 5, // Exit with error after this many steps
520+
Steps: 5, // Exit with error after this many steps
521521
}
522522

523523
func helperWithTimeoutAndBackoff(metadata *ec2metadata.EC2Metadata, p string) (string, error) {
524524
var (
525525
origErr error
526-
result string
526+
result string
527527
)
528528
conditionFn := func() (bool, error) {
529529
ctx, cancelFn := context.WithTimeout(context.Background(), contextTimeout)
@@ -543,7 +543,7 @@ func helperWithTimeoutAndBackoff(metadata *ec2metadata.EC2Metadata, p string) (s
543543
expErr := wait.ExponentialBackoff(RatelimitingExponentialBackoff, conditionFn)
544544
if expErr == wait.ErrWaitTimeout {
545545
return "", cloudops.NewStorageError(cloudops.ErrExponentialTimeout, origErr.Error(), "")
546-
}
546+
}
547547
return result, origErr
548548
}
549549

@@ -573,7 +573,7 @@ func (s *awsOps) FreeDevices(
573573
continue
574574
}
575575

576-
devName, err := GetMetadataWithTimeoutAndBackoff(c, "block-device-mapping/" + device)
576+
devName, err := GetMetadataWithTimeoutAndBackoff(c, "block-device-mapping/"+device)
577577
if err != nil {
578578
return nil, err
579579
}
@@ -784,6 +784,10 @@ func (s *awsOps) Create(
784784
return nil, cloudops.NewStorageError(cloudops.ErrVolInval,
785785
"Invalid volume template given", "")
786786
}
787+
if vol.VolumeType == nil {
788+
return nil, cloudops.NewStorageError(cloudops.ErrVolInval,
789+
"Drive type not specified in the storage spec", "")
790+
}
787791

788792
req := &ec2.CreateVolumeInput{
789793
AvailabilityZone: vol.AvailabilityZone,

0 commit comments

Comments
 (0)