Skip to content

Commit

Permalink
Kanister efs backups remove reference to k10 (#1328)
Browse files Browse the repository at this point in the history
* Expose efs utilities

* Remove K10 reference in awsefs

* Remove K10 reference in func name

* empty commit to retrigger travis

* remove default in func name since it creates w provided name

* Add unit test to check for BackupVaultName

* add func to list limited amount of snapshot + fix typo

* un-expose backupVaultName

* Update date in pkg/blockstorage/awsefs/awsefs_test.go

Co-authored-by: Pavan Navarathna <pavan@kasten.io>

Co-authored-by: Le Tran <le.tran@kasten.io>
Co-authored-by: Pavan Navarathna <pavan@kasten.io>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Mar 29, 2022
1 parent a932e18 commit 2de85f2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
30 changes: 24 additions & 6 deletions pkg/blockstorage/awsefs/awsefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ const (
burstingThroughputMode = awsefs.ThroughputModeBursting
defaultThroughputMode = burstingThroughputMode

efsType = "EFS"
defaultK10BackupVaultName = "k10vault"

efsType = "EFS"
maxRetries = 10
)

Expand Down Expand Up @@ -92,7 +90,7 @@ func NewEFSProvider(ctx context.Context, config map[string]string) (blockstorage

efsVault, ok := config[awsconfig.ConfigEFSVaultName]
if !ok || efsVault == "" {
efsVault = defaultK10BackupVaultName
return nil, errors.New("EFS vault name is empty")
}

return &Efs{
Expand Down Expand Up @@ -381,7 +379,7 @@ func (e *Efs) SnapshotCopyWithArgs(ctx context.Context, from blockstorage.Snapsh
}

func (e *Efs) SnapshotCreate(ctx context.Context, volume blockstorage.Volume, tags map[string]string) (*blockstorage.Snapshot, error) {
err := e.createK10DefaultBackupVault()
err := e.CreateBackupVaultWrapper()
if err != nil {
return nil, errors.Wrap(err, "Failed to setup K10 vault for AWS Backup")
}
Expand Down Expand Up @@ -432,7 +430,8 @@ func (e *Efs) SnapshotCreate(ctx context.Context, volume blockstorage.Volume, ta
}, nil
}

func (e *Efs) createK10DefaultBackupVault() error {
// Create a Backup Vault, also checks if vault already exist
func (e *Efs) CreateBackupVaultWrapper() error {
req := &backup.CreateBackupVaultInput{}
req.SetBackupVaultName(e.backupVaultName)

Expand Down Expand Up @@ -555,6 +554,25 @@ func (e *Efs) SnapshotsList(ctx context.Context, tags map[string]string) ([]*blo
return result, nil
}

// List a limited amount of snapshots based on given limit input
func (e *Efs) SnapshotsListWLimit(ctx context.Context, tags map[string]string, limit int64) ([]*blockstorage.Snapshot, error) {
result := make([]*blockstorage.Snapshot, 0)
var err error
req := &backup.ListRecoveryPointsByBackupVaultInput{}
req.SetBackupVaultName(e.backupVaultName)
req.SetMaxResults(limit)
resp, err := e.ListRecoveryPointsByBackupVaultWithContext(ctx, req) //backup API
if err != nil {
return nil, errors.Wrap(err, "Failed to list recovery points by vault")
}
snaps, err := e.SnapshotsFromRecoveryPoints(ctx, resp.RecoveryPoints)
if err != nil {
return nil, errors.Wrap(err, "Failed to get snapshots from recovery points")
}
result = append(result, blockstorage.FilterSnapshotsWithTags(snaps, tags)...)
return result, err
}

func (e *Efs) SnapshotsFromRecoveryPoints(ctx context.Context, rps []*backup.RecoveryPointByBackupVault) ([]*blockstorage.Snapshot, error) {
result := make([]*blockstorage.Snapshot, 0)
for _, rp := range rps {
Expand Down
50 changes: 50 additions & 0 deletions pkg/blockstorage/awsefs/awsefs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2022 The Kanister Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package awsefs

import (
"context"
"os"

"gopkg.in/check.v1"

awsconfig "github.com/kanisterio/kanister/pkg/aws"
"github.com/kanisterio/kanister/pkg/testutil"
)

type AwsEfsSuite struct{}

var _ = check.Suite(&AwsEfsSuite{})

func (a *AwsEfsSuite) TestBackupVaultName(c *check.C) {
testutil.GetEnvOrSkip(c, awsconfig.AccessKeyID)
testutil.GetEnvOrSkip(c, awsconfig.SecretAccessKey)
ctx := context.Background()

// success
config := map[string]string{
awsconfig.AccessKeyID: os.Getenv(awsconfig.AccessKeyID),
awsconfig.SecretAccessKey: os.Getenv(awsconfig.SecretAccessKey),
awsconfig.ConfigEFSVaultName: "vault-name",
awsconfig.ConfigRegion: "us-east-2",
}
_, err := NewEFSProvider(ctx, config)
c.Assert(err, check.IsNil)

// fail because Vault name is expected
config[awsconfig.ConfigEFSVaultName] = ""
_, err = NewEFSProvider(ctx, config)
c.Assert(err, check.NotNil)
}

0 comments on commit 2de85f2

Please sign in to comment.