Skip to content

Commit

Permalink
Make isVolumeNotFound recursive and fix the problem in both locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakan Memisoglu committed Aug 13, 2019
1 parent 45d3bbb commit 138f344
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 6 additions & 3 deletions pkg/blockstorage/awsefs/awsefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ func (e *efs) SnapshotGet(ctx context.Context, id string) (*blockstorage.Snapsho
return nil, errors.Wrap(err, "Failed to get volume ID from recovery point ARN")
}
vol, err := e.VolumeGet(ctx, volID, "")
if err != nil {
return nil, errors.Wrap(err, "Failed to get originating volume")
if err != nil && !isVolumeNotFound(err) {
return nil, errors.Wrap(err, "Failed to get filesystem")
}
return snapshotFromRecoveryPoint(resp, vol, e.region)
}
Expand Down Expand Up @@ -455,7 +455,10 @@ func (e *efs) snapshotsFromRecoveryPoints(ctx context.Context, rps []*backup.Rec
}
// VolumeGet might return error since originating filesystem might have
// been deleted.
vol, _ := e.VolumeGet(ctx, volID, "")
vol, err := e.VolumeGet(ctx, volID, "")
if err != nil && !isVolumeNotFound(err) {
return nil, errors.Wrap(err, "Failed to get filesystem")
}
snap, err := snapshotFromRecoveryPointByVault(rp, vol, tags, e.region)
if err != nil {
return nil, errors.Wrap(err, "Failed to get snapshot from the vault")
Expand Down
6 changes: 5 additions & 1 deletion pkg/blockstorage/awsefs/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ func snapshotFromRecoveryPoint(rp *backup.DescribeRecoveryPointOutput, volume *b
if rp.RecoveryPointArn == nil {
return nil, errors.New("Recovery point has no RecoveryPointArn")
}
encrypted := false
if volume != nil {
encrypted = volume.Encrypted
}
return &blockstorage.Snapshot{
ID: *rp.RecoveryPointArn,
CreationTime: blockstorage.TimeStamp(*rp.CreationDate),
Size: bytesInGiB(*rp.BackupSizeInBytes),
Region: region,
Type: blockstorage.TypeEFS,
Volume: volume,
Encrypted: volume.Encrypted,
Encrypted: encrypted,
Tags: nil,
}, nil
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/blockstorage/awsefs/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/backup"
awsefs "github.com/aws/aws-sdk-go/service/efs"
"github.com/pkg/errors"
)

func isVolumeNotFound(err error) bool {
if awsErr, ok := err.(awserr.Error); ok {
return awsErr.Code() == awsefs.ErrCodeFileSystemNotFound
switch errV := err.(type) {
case awserr.Error:
return errV.Code() == awsefs.ErrCodeFileSystemNotFound
case errors.Causer:
return isVolumeNotFound(errV.Cause())
default:
return false
}
return false
}

func isBackupVaultAlreadyExists(err error) bool {
Expand Down

0 comments on commit 138f344

Please sign in to comment.