Skip to content

Commit

Permalink
Adding a configurable env for EFS backup vault name (#1090)
Browse files Browse the repository at this point in the history
* Adding a configurable env for efs backup vault

* efs delete output prints

* Make it configurable through config

* remove unused function

* after vaibhavs review

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
bathina2 and mergify[bot] committed Sep 23, 2021
1 parent 822a6ef commit 7ae5cd0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
4 changes: 4 additions & 0 deletions pkg/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const (
// It is optional.
ConfigRole = "role"

// ConfigEFSVaultName represents the key for the EFS vault name in the map
// "config". It is optional.
ConfigEFSVaultName = "efsVaultName"

// AccessKeyID represents AWS Access key ID
AccessKeyID = "AWS_ACCESS_KEY_ID"
// SecretAccessKey represents AWS Secret Access Key
Expand Down
63 changes: 39 additions & 24 deletions pkg/blockstorage/awsefs/awsefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ import (
awsconfig "github.com/kanisterio/kanister/pkg/aws"
"github.com/kanisterio/kanister/pkg/blockstorage"
kantags "github.com/kanisterio/kanister/pkg/blockstorage/tags"
"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/log"
)

type efs struct {
*awsefs.EFS
*backup.Backup
accountID string
region string
role string
accountID string
region string
role string
backupVaultName string
}

var _ blockstorage.Provider = (*efs)(nil)
Expand All @@ -50,9 +53,8 @@ const (
burstingThroughputMode = awsefs.ThroughputModeBursting
defaultThroughputMode = burstingThroughputMode

efsType = "EFS"
k10BackupVaultName = "k10vault"
testMarker = ""
efsType = "EFS"
defaultK10BackupVaultName = "k10vault"

maxRetries = 10
)
Expand Down Expand Up @@ -87,12 +89,19 @@ func NewEFSProvider(ctx context.Context, config map[string]string) (blockstorage
accountID := *user.Account
efsCli := awsefs.New(s, aws.NewConfig().WithRegion(region).WithCredentials(awsConfig.Credentials).WithMaxRetries(maxRetries))
backupCli := backup.New(s, aws.NewConfig().WithRegion(region).WithCredentials(awsConfig.Credentials).WithMaxRetries(maxRetries))

efsVault, ok := config[awsconfig.ConfigEFSVaultName]
if !ok || efsVault == "" {
efsVault = defaultK10BackupVaultName
}

return &efs{
EFS: efsCli,
Backup: backupCli,
region: region,
accountID: accountID,
role: config[awsconfig.ConfigRole],
EFS: efsCli,
Backup: backupCli,
region: region,
accountID: accountID,
role: config[awsconfig.ConfigRole],
backupVaultName: efsVault,
}, nil
}

Expand Down Expand Up @@ -129,7 +138,7 @@ func (e *efs) VolumeCreate(ctx context.Context, volume blockstorage.Volume) (*bl

func (e *efs) VolumeCreateFromSnapshot(ctx context.Context, snapshot blockstorage.Snapshot, tags map[string]string) (*blockstorage.Volume, error) {
reqM := &backup.GetRecoveryPointRestoreMetadataInput{}
reqM.SetBackupVaultName(k10BackupVaultName)
reqM.SetBackupVaultName(e.backupVaultName)
reqM.SetRecoveryPointArn(snapshot.ID)

respM, err := e.GetRecoveryPointRestoreMetadataWithContext(ctx, reqM)
Expand Down Expand Up @@ -308,7 +317,10 @@ func (e *efs) VolumeDelete(ctx context.Context, volume *blockstorage.Volume) err

req := &awsefs.DeleteFileSystemInput{}
req.SetFileSystemId(volume.ID)
_, err = e.DeleteFileSystemWithContext(ctx, req)
output, err := e.DeleteFileSystemWithContext(ctx, req)
if err == nil {
log.Info().Print("Delete EFS output", field.M{"output": output.String()})
}
if isVolumeNotFound(err) {
return nil
}
Expand Down Expand Up @@ -368,7 +380,7 @@ func (e *efs) SnapshotCreate(ctx context.Context, volume blockstorage.Volume, ta
}

req := &backup.StartBackupJobInput{}
req.SetBackupVaultName(k10BackupVaultName)
req.SetBackupVaultName(e.backupVaultName)
req.SetIamRoleArn(awsDefaultServiceBackupRole(e.accountID))
req.SetResourceArn(resourceARNForEFS(e.region, *desc.OwnerId, *desc.FileSystemId))

Expand All @@ -391,7 +403,7 @@ func (e *efs) SnapshotCreate(ctx context.Context, volume blockstorage.Volume, ta
}

req2 := &backup.DescribeRecoveryPointInput{}
req2.SetBackupVaultName(k10BackupVaultName)
req2.SetBackupVaultName(e.backupVaultName)
req2.SetRecoveryPointArn(*resp.RecoveryPointArn)
describeRP, err := e.DescribeRecoveryPointWithContext(ctx, req2)
if err != nil {
Expand All @@ -411,7 +423,7 @@ func (e *efs) SnapshotCreate(ctx context.Context, volume blockstorage.Volume, ta

func (e *efs) createK10DefaultBackupVault() error {
req := &backup.CreateBackupVaultInput{}
req.SetBackupVaultName(k10BackupVaultName)
req.SetBackupVaultName(e.backupVaultName)

_, err := e.CreateBackupVault(req)
if isBackupVaultAlreadyExists(err) {
Expand All @@ -426,10 +438,13 @@ func (e *efs) SnapshotCreateWaitForCompletion(ctx context.Context, snapshot *blo

func (e *efs) SnapshotDelete(ctx context.Context, snapshot *blockstorage.Snapshot) error {
req := &backup.DeleteRecoveryPointInput{}
req.SetBackupVaultName(k10BackupVaultName)
req.SetBackupVaultName(e.backupVaultName)
req.SetRecoveryPointArn(snapshot.ID)

_, err := e.DeleteRecoveryPointWithContext(ctx, req)
output, err := e.DeleteRecoveryPointWithContext(ctx, req)
if err == nil {
log.Info().Print("Delete EFS snapshot", field.M{"output": output.String()})
}
if isResourceNotFoundException(err) {
return nil
}
Expand All @@ -438,7 +453,7 @@ func (e *efs) SnapshotDelete(ctx context.Context, snapshot *blockstorage.Snapsho

func (e *efs) SnapshotGet(ctx context.Context, id string) (*blockstorage.Snapshot, error) {
req := &backup.DescribeRecoveryPointInput{}
req.SetBackupVaultName(k10BackupVaultName)
req.SetBackupVaultName(e.backupVaultName)
req.SetRecoveryPointArn(id)

resp, err := e.DescribeRecoveryPointWithContext(ctx, req)
Expand Down Expand Up @@ -512,7 +527,7 @@ func (e *efs) SnapshotsList(ctx context.Context, tags map[string]string) ([]*blo
result := make([]*blockstorage.Snapshot, 0)
for resp, req := emptyResponseRequestForBackups(); resp.NextToken != nil; req.NextToken = resp.NextToken {
var err error
req.SetBackupVaultName(k10BackupVaultName)
req.SetBackupVaultName(e.backupVaultName)
resp, err = e.ListRecoveryPointsByBackupVaultWithContext(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "Failed to list recovery points by vault")
Expand Down Expand Up @@ -556,25 +571,25 @@ func (e *efs) snapshotsFromRecoveryPoints(ctx context.Context, rps []*backup.Rec
}

func emptyResponseRequestForBackups() (*backup.ListRecoveryPointsByBackupVaultOutput, *backup.ListRecoveryPointsByBackupVaultInput) {
resp := (&backup.ListRecoveryPointsByBackupVaultOutput{}).SetNextToken(testMarker)
resp := (&backup.ListRecoveryPointsByBackupVaultOutput{}).SetNextToken("")
req := &backup.ListRecoveryPointsByBackupVaultInput{}
return resp, req
}

func emptyResponseRequestForFilesystems() (*awsefs.DescribeFileSystemsOutput, *awsefs.DescribeFileSystemsInput) {
resp := (&awsefs.DescribeFileSystemsOutput{}).SetNextMarker(testMarker)
resp := (&awsefs.DescribeFileSystemsOutput{}).SetNextMarker("")
req := &awsefs.DescribeFileSystemsInput{}
return resp, req
}

func emptyResponseRequestForListTags() (*backup.ListTagsOutput, *backup.ListTagsInput) {
resp := (&backup.ListTagsOutput{}).SetNextToken(testMarker)
resp := (&backup.ListTagsOutput{}).SetNextToken("")
req := &backup.ListTagsInput{}
return resp, req
}

func emptyResponseRequestForMountTargets() (*awsefs.DescribeMountTargetsOutput, *awsefs.DescribeMountTargetsInput) {
resp := (&awsefs.DescribeMountTargetsOutput{}).SetNextMarker(testMarker)
resp := (&awsefs.DescribeMountTargetsOutput{}).SetNextMarker("")
req := &awsefs.DescribeMountTargetsInput{}
return resp, req
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/blockstorage/awsefs/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (e *efs) waitUntilFileSystemAvailable(ctx context.Context, id string) error
func (e *efs) waitUntilRecoveryPointCompleted(ctx context.Context, id string) error {
return poll.WaitWithRetries(ctx, maxNumErrorRetries, poll.IsAlwaysRetryable, func(ctx context.Context) (bool, error) {
req := &backup.DescribeRecoveryPointInput{}
req.SetBackupVaultName(k10BackupVaultName)
req.SetBackupVaultName(e.backupVaultName)
req.SetRecoveryPointArn(id)

desc, err := e.DescribeRecoveryPointWithContext(ctx, req)
Expand All @@ -74,7 +74,7 @@ func (e *efs) waitUntilRecoveryPointCompleted(ctx context.Context, id string) er
func (e *efs) waitUntilRecoveryPointVisible(ctx context.Context, id string) error {
return poll.WaitWithRetries(ctx, maxNumErrorRetries, poll.IsAlwaysRetryable, func(ctx context.Context) (bool, error) {
req := &backup.DescribeRecoveryPointInput{}
req.SetBackupVaultName(k10BackupVaultName)
req.SetBackupVaultName(e.backupVaultName)
req.SetRecoveryPointArn(id)

_, err := e.DescribeRecoveryPointWithContext(ctx, req)
Expand Down

0 comments on commit 7ae5cd0

Please sign in to comment.