Skip to content

Commit f054e2c

Browse files
authored
Merge pull request #1226 from otorreno/reduce-calls-to-efs-api
Reduce calls to EFS API
2 parents 1f8bfcb + dbbc733 commit f054e2c

File tree

4 files changed

+157
-144
lines changed

4 files changed

+157
-144
lines changed

pkg/cloud/cloud.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ func (c *cloud) ListAccessPoints(ctx context.Context, fileSystemId string) (acce
302302
res, err := c.efs.DescribeAccessPointsWithContext(ctx, describeAPInput)
303303
if err != nil {
304304
if isAccessDenied(err) {
305-
return
305+
return nil, ErrAccessDenied
306306
}
307307
if isFileSystemNotFound(err) {
308-
return
308+
return nil, ErrNotFound
309309
}
310310
err = fmt.Errorf("List Access Points failed: %v", err)
311311
return

pkg/driver/controller.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const (
3838
AccessPointMode = "efs-ap"
3939
AzName = "az"
4040
BasePath = "basePath"
41-
DefaultGidMin = 50000
42-
DefaultGidMax = 7000000
41+
DefaultGidMin = int64(50000)
42+
DefaultGidMax = DefaultGidMin + cloud.AccessPointPerFsLimit
4343
DefaultTagKey = "efs.csi.aws.com/cluster"
4444
DefaultTagValue = "true"
4545
DirectoryPerms = "directoryPerms"
@@ -120,8 +120,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
120120
azName string
121121
basePath string
122122
gid int64
123-
gidMin int
124-
gidMax int
123+
gidMin int64
124+
gidMax int64
125125
localCloud cloud.Cloud
126126
provisioningMode string
127127
roleArn string
@@ -189,7 +189,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
189189
}
190190

191191
if value, ok := volumeParams[GidMin]; ok {
192-
gidMin, err = strconv.Atoi(value)
192+
gidMin, err = strconv.ParseInt(value, 10, 64)
193193
if err != nil {
194194
return nil, status.Errorf(codes.InvalidArgument, "Failed to parse invalid %v: %v", GidMin, err)
195195
}
@@ -203,7 +203,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
203203
if gidMin == 0 {
204204
return nil, status.Errorf(codes.InvalidArgument, "Missing %v parameter", GidMin)
205205
}
206-
gidMax, err = strconv.Atoi(value)
206+
gidMax, err = strconv.ParseInt(value, 10, 64)
207207
if err != nil {
208208
return nil, status.Errorf(codes.InvalidArgument, "Failed to parse invalid %v: %v", GidMax, err)
209209
}
@@ -241,20 +241,27 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
241241
return nil, err
242242
}
243243

244-
// Check if file system exists. Describe FS handles appropriate error codes
245-
if _, err = localCloud.DescribeFileSystem(ctx, accessPointsOptions.FileSystemId); err != nil {
244+
// Check if file system exists. Describe FS or List APs handle appropriate error codes
245+
// With dynamic uid/gid provisioning we can save a call to describe FS, as list APs fails if FS ID does not exist
246+
var accessPoints []*cloud.AccessPoint
247+
if uid == -1 || gid == -1 {
248+
accessPoints, err = localCloud.ListAccessPoints(ctx, accessPointsOptions.FileSystemId)
249+
} else {
250+
_, err = localCloud.DescribeFileSystem(ctx, accessPointsOptions.FileSystemId)
251+
}
252+
if err != nil {
246253
if err == cloud.ErrAccessDenied {
247254
return nil, status.Errorf(codes.Unauthenticated, "Access Denied. Please ensure you have the right AWS permissions: %v", err)
248255
}
249256
if err == cloud.ErrNotFound {
250257
return nil, status.Errorf(codes.InvalidArgument, "File System does not exist: %v", err)
251258
}
252-
return nil, status.Errorf(codes.Internal, "Failed to fetch File System info: %v", err)
259+
return nil, status.Errorf(codes.Internal, "Failed to fetch Access Points or Describe File System: %v", err)
253260
}
254261

255262
var allocatedGid int64
256263
if uid == -1 || gid == -1 {
257-
allocatedGid, err = d.gidAllocator.getNextGid(ctx, localCloud, accessPointsOptions.FileSystemId, gidMin, gidMax)
264+
allocatedGid, err = d.gidAllocator.getNextGid(accessPointsOptions.FileSystemId, accessPoints, gidMin, gidMax)
258265
if err != nil {
259266
return nil, err
260267
}

0 commit comments

Comments
 (0)