Skip to content

Commit

Permalink
Add PVC and PV metadata as tags to EFS access points
Browse files Browse the repository at this point in the history
  • Loading branch information
edanc committed Mar 10, 2021
1 parent be9eddc commit 74e1e4e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
1 change: 1 addition & 0 deletions charts/aws-efs-csi-driver/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ spec:
- --v=5
- --feature-gates=Topology=true
- --leader-election
- --extra-create-metadata
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down
3 changes: 2 additions & 1 deletion deploy/kubernetes/base/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ spec:
periodSeconds: 10
failureThreshold: 5
- name: csi-provisioner
image: k8s.gcr.io/sig-storage/csi-provisioner:v2.0.2
image: k8s.gcr.io/sig-storage/csi-provisioner:v2.0.4
args:
- --csi-address=$(ADDRESS)
- --v=5
- --feature-gates=Topology=true
- --leader-election
- --extra-create-metadata
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down
15 changes: 15 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type AccessPointOptions struct {
Gid int64
DirectoryPerms string
DirectoryPath string
Tags map[string]string
}

// Efs abstracts efs client(https://docs.aws.amazon.com/sdk-for-go/api/service/efs/)
Expand Down Expand Up @@ -109,6 +110,7 @@ func (c *cloud) GetMetadata() MetadataService {
}

func (c *cloud) CreateAccessPoint(ctx context.Context, volumeName string, accessPointOpts *AccessPointOptions) (accessPoint *AccessPoint, err error) {
efsTags := parseEfsTags(accessPointOpts.Tags)
createAPInput := &efs.CreateAccessPointInput{
ClientToken: &volumeName,
FileSystemId: &accessPointOpts.FileSystemId,
Expand All @@ -124,6 +126,7 @@ func (c *cloud) CreateAccessPoint(ctx context.Context, volumeName string, access
},
Path: &accessPointOpts.DirectoryPath,
},
Tags: efsTags,
}

klog.V(5).Infof("Calling Create AP with input: %+v", *createAPInput)
Expand Down Expand Up @@ -234,3 +237,15 @@ func isAccessDenied(err error) bool {
}
return false
}
func parseEfsTags(tagMap map[string]string) []*efs.Tag {
efsTags := []*efs.Tag{}
for k, v := range tagMap {
key := k
value := v
efsTags = append(efsTags, &efs.Tag{
Key: &key,
Value: &value,
})
}
return efsTags
}
39 changes: 28 additions & 11 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ import (
)

const (
AccessPointMode = "efs-ap"
FsId = "fileSystemId"
GidMin = "gidRangeStart"
GidMax = "gidRangeEnd"
DirectoryPerms = "directoryPerms"
BasePath = "basePath"
ProvisioningMode = "provisioningMode"
DefaultGidMin = 50000
DefaultGidMax = 7000000
RootDirPrefix = "efs-csi-ap"
TempMountPathPrefix = "/var/lib/csi/pv"
AccessPointMode = "efs-ap"
FsId = "fileSystemId"
GidMin = "gidRangeStart"
GidMax = "gidRangeEnd"
DirectoryPerms = "directoryPerms"
BasePath = "basePath"
ProvisioningMode = "provisioningMode"
DefaultGidMin = 50000
DefaultGidMax = 7000000
RootDirPrefix = "efs-csi-ap"
TempMountPathPrefix = "/var/lib/csi/pv"
PVCNameParameter = "csi.storage.k8s.io/pvc/name"
PVCNameSpaceParameter = "csi.storage.k8s.io/pvc/namespace"
PVNameParameter = "csi.storage.k8s.io/pv/name"
)

var (
Expand Down Expand Up @@ -77,6 +80,9 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
basePath string
provisioningMode string
err error
pvcName string
pvcNamespace string
pvName string
)

//Parse parameters
Expand All @@ -92,8 +98,19 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
return nil, status.Errorf(codes.InvalidArgument, "Missing %v parameter", ProvisioningMode)
}

if value, ok := volumeParams[PVCNameParameter]; ok {
pvcName = value
}
if value, ok := volumeParams[PVCNameSpaceParameter]; ok {
pvcNamespace = value
}
if value, ok := volumeParams[PVNameParameter]; ok {
pvName = value
}
tags := map[string]string{PVCNameSpaceParameter: pvcNamespace, PVCNameParameter: pvcName, PVNameParameter: pvName}
accessPointsOptions := &cloud.AccessPointOptions{
CapacityGiB: volSize,
Tags: tags,
}

if value, ok := volumeParams[FsId]; ok {
Expand Down

0 comments on commit 74e1e4e

Please sign in to comment.