Skip to content

Commit

Permalink
EFS VolumesList implementation (#6097)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakan Memisoglu authored and Ilya Kislenko committed Jul 19, 2019
1 parent ad33ef7 commit 89b3566
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/blockstorage/awsefs/awsefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type efs struct {

var _ blockstorage.Provider = (*efs)(nil)

const (
dummyMarker = ""
)

// NewEFSProvider retuns a blockstorage provider for AWS EFS.
func NewEFSProvider(config map[string]string) (blockstorage.Provider, error) {
awsConfig, region, err := awsebs.GetConfig(config)
Expand Down Expand Up @@ -112,13 +116,29 @@ func (e *efs) SetTags(ctx context.Context, resource interface{}, tags map[string
}

func (e *efs) VolumesList(ctx context.Context, tags map[string]string, zone string) ([]*blockstorage.Volume, error) {
return nil, errors.New("Not implemented")
result := make([]*blockstorage.Volume, 0)
for resp, req := emptyResponseRequestForFilesystems(); resp.NextMarker != nil; req.Marker = resp.NextMarker {
var err error
resp, err = e.DescribeFileSystemsWithContext(ctx, req)
if err != nil {
return nil, err
}
availables := filterAvailable(filterWithTags(resp.FileSystems, tags))
result = append(result, volumesFromEFSDescriptions(availables, zone)...)
}
return result, nil
}

func (e *efs) SnapshotsList(ctx context.Context, tags map[string]string) ([]*blockstorage.Snapshot, error) {
return nil, errors.New("Not implemented")
}

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

func (e *efs) getFileSystemDescriptionWithID(ctx context.Context, id string) (*awsefs.FileSystemDescription, error) {
req := &awsefs.DescribeFileSystemsInput{}
req.SetFileSystemId(id)
Expand Down
12 changes: 12 additions & 0 deletions pkg/blockstorage/awsefs/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package awsefs

import (
awsefs "github.com/aws/aws-sdk-go/service/efs"

kantags "github.com/kanisterio/kanister/pkg/blockstorage/tags"
)

func filterAvailable(descriptions []*awsefs.FileSystemDescription) []*awsefs.FileSystemDescription {
Expand All @@ -13,3 +15,13 @@ func filterAvailable(descriptions []*awsefs.FileSystemDescription) []*awsefs.Fil
}
return result
}

func filterWithTags(descriptions []*awsefs.FileSystemDescription, tags map[string]string) []*awsefs.FileSystemDescription {
result := make([]*awsefs.FileSystemDescription, 0)
for i, desc := range descriptions {
if kantags.IsSubset(convertFromEFSTags(desc.Tags), tags) {
result = append(result, descriptions[i])
}
}
return result
}

0 comments on commit 89b3566

Please sign in to comment.