Skip to content

Commit

Permalink
EFS SnapshotGet (#6089)
Browse files Browse the repository at this point in the history
* SnapshotGet implementation

* Remove const

* Address comments

* Fix merge mistakes
  • Loading branch information
Hakan Memisoglu authored and Ilya Kislenko committed Jul 29, 2019
1 parent c4df21b commit 8824ba6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/blockstorage/awsefs/awsefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,26 @@ func (e *efs) SnapshotDelete(ctx context.Context, snapshot *blockstorage.Snapsho
}

func (e *efs) SnapshotGet(ctx context.Context, id string) (*blockstorage.Snapshot, error) {
return nil, errors.New("Not implemented")
req := &backup.DescribeRecoveryPointInput{}
req.SetBackupVaultName(k10BackupVaultName)
req.SetRecoveryPointArn(id)

resp, err := e.DescribeRecoveryPointWithContext(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "Failed to get recovery point information")
}
if resp.ResourceArn == nil {
return nil, errors.Wrap(err, "Resource ARN in recovery point is empty")
}
volID, err := efsIDFromResourceARN(*resp.ResourceArn)
if err != nil {
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")
}
return snapshotFromRecoveryPoint(resp, vol, e.region)
}

func (e *efs) SetTags(ctx context.Context, resource interface{}, tags map[string]string) error {
Expand Down
45 changes: 45 additions & 0 deletions pkg/blockstorage/awsefs/conversion.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package awsefs

import (
"strings"

"github.com/aws/aws-sdk-go/aws"
awsarn "github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/backup"
awsefs "github.com/aws/aws-sdk-go/service/efs"
"github.com/pkg/errors"

"github.com/kanisterio/kanister/pkg/blockstorage"
)
Expand All @@ -24,6 +29,46 @@ func convertFromEFSTags(efsTags []*awsefs.Tag) map[string]string {
return tags
}

// efsIDFromResourceARN gets EFS filesystem ID from an EFS resource ARN.
func efsIDFromResourceARN(arn string) (string, error) {
resourceARN, err := awsarn.Parse(arn)
if err != nil {
return "", errors.Wrap(err, "Failed to parse ARN")
}
// An example of resourceArn.Resource:
// "file-system/fs-87b1302c"
tokens := strings.Split(resourceARN.Resource, "/")
if len(tokens) != 2 {
return "", errors.New("Bad resource in ARN")
}
if tokens[0] != "file-system" {
return "", errors.New("Bad resource type in ARN")
}
return tokens[1], nil
}

func snapshotFromRecoveryPoint(rp *backup.DescribeRecoveryPointOutput, volume *blockstorage.Volume, region string) (*blockstorage.Snapshot, error) {
if rp.CreationDate == nil {
return nil, errors.New("Recovery point has no CreationDate")
}
if rp.BackupSizeInBytes == nil {
return nil, errors.New("Recovery point has no BackupSizeInBytes")
}
if rp.RecoveryPointArn == nil {
return nil, errors.New("Recovery point has no RecoveryPointArn")
}
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,
Tags: nil,
}, nil
}

// convertToBackupTags converts a flattened map to AWS Backup compliant tag structure.
func convertToBackupTags(tags map[string]string) map[string]*string {
backupTags := make(map[string]*string)
Expand Down

0 comments on commit 8824ba6

Please sign in to comment.