Skip to content

Commit

Permalink
Implementation for SetTags
Browse files Browse the repository at this point in the history
Change Overview
EFS implementation for SetTags.

* Save tags as backup tags to recovery point if the resource type is a snapshot.
* Otherwise (a volume), save tags as AWS EFS tag to filesystem instance.
  • Loading branch information
Hakan Memisoglu committed Jul 29, 2019
1 parent 906d4cb commit c4df21b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
30 changes: 27 additions & 3 deletions pkg/blockstorage/awsefs/awsefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const (
defaultThroughputMode = burstingThroughputMode

k10BackupVaultName = "k10vault"

dummyMarker = ""
dummyMarker = ""
)

// NewEFSProvider retuns a blockstorage provider for AWS EFS.
Expand Down Expand Up @@ -148,7 +147,32 @@ func (e *efs) SnapshotGet(ctx context.Context, id string) (*blockstorage.Snapsho
}

func (e *efs) SetTags(ctx context.Context, resource interface{}, tags map[string]string) error {
return errors.New("Not implemented")
switch r := resource.(type) {
case *blockstorage.Volume:
return e.setEFSTags(ctx, r.ID, tags)
case *blockstorage.Snapshot:
return e.setBackupTags(ctx, r.ID, tags)
default:
return errors.New("Unsupported type for setting tags")
}
}

func (e *efs) setBackupTags(ctx context.Context, arn string, tags map[string]string) error {
req := &backup.TagResourceInput{
ResourceArn: &arn,
Tags: convertToBackupTags(tags),
}
_, err := e.TagResourceWithContext(ctx, req)
return err
}

func (e *efs) setEFSTags(ctx context.Context, id string, tags map[string]string) error {
req := &awsefs.CreateTagsInput{
FileSystemId: &id,
Tags: convertToEFSTags(tags),
}
_, err := e.CreateTagsWithContext(ctx, req)
return err
}

func (e *efs) VolumesList(ctx context.Context, tags map[string]string, zone string) ([]*blockstorage.Volume, error) {
Expand Down
13 changes: 12 additions & 1 deletion pkg/blockstorage/awsefs/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ func convertFromEFSTags(efsTags []*awsefs.Tag) map[string]string {
return tags
}

// convertToEFSTags converts a map to AWS EFS tags.
// 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)
for k, v := range tags {
vPtr := new(string)
*vPtr = v
backupTags[k] = vPtr
}
return backupTags
}

// convertToEFSTags converts a flattened map to AWS EFS tag structure.
func convertToEFSTags(tags map[string]string) []*awsefs.Tag {
efsTags := make([]*awsefs.Tag, 0, len(tags))
for k, v := range tags {
Expand Down

0 comments on commit c4df21b

Please sign in to comment.