Skip to content

Commit

Permalink
Add ability to discover the name of the AZ the Kubernetes node is in …
Browse files Browse the repository at this point in the history
…and use that when mounting the EFS filesystem (if requested via 'discoverAzName')
  • Loading branch information
multimac committed Apr 11, 2024
1 parent 0ea48a3 commit 704cafc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
DefaultGidMax = DefaultGidMin + cloud.AccessPointPerFsLimit
DefaultTagKey = "efs.csi.aws.com/cluster"
DefaultTagValue = "true"
DiscoverAzName = "discoverAzName"
DirectoryPerms = "directoryPerms"
EnsureUniqueDirectory = "ensureUniqueDirectory"
FsId = "fileSystemId"
Expand Down Expand Up @@ -129,6 +130,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
roleArn string
uid int64
crossAccountDNSEnabled bool
discoverAzNameEnabled bool
)

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

if value, ok := volumeParams[DiscoverAzName]; ok {
discoverAzNameEnabled, err = strconv.ParseBool(value)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "Failed to parse invalid %v: %v", DiscoverAzName, err)
}
}

// Create tags
tags := map[string]string{
DefaultTagKey: DefaultTagValue,
Expand Down Expand Up @@ -348,6 +357,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}
}

if discoverAzNameEnabled {
volContext[DiscoverAzName] = strconv.FormatBool(true)
}

return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
CapacityBytes: volSize,
Expand Down
9 changes: 9 additions & 0 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
if err != nil {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Volume context property %q must be a boolean value: %v", k, err))
}
case strings.ToLower(DiscoverAzName):
discoverAzNameEnabled, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Volume context property %q must be a boolean value: %v", k, err))
}
if discoverAzNameEnabled {
az := d.cloud.GetMetadata().GetAvailabilityZone()
mountOptions = append(mountOptions, "az="+az)
}
default:
return nil, status.Errorf(codes.InvalidArgument, "Volume context property %s not supported.", k)
}
Expand Down

0 comments on commit 704cafc

Please sign in to comment.