Skip to content

Commit 774d37d

Browse files
committed
Add support for static uid/gid from storage class for dir-mode provisioning
and fix obvious typo while checking gid in ap-mode.
1 parent 428fe26 commit 774d37d

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

pkg/driver/provisioner_ap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (a AccessPointProvisioner) Provision(ctx context.Context, req *csi.CreateVo
132132
if err != nil {
133133
return nil, status.Errorf(codes.InvalidArgument, "Failed to parse invalid %v: %v", Gid, err)
134134
}
135-
if uid < 0 {
135+
if gid < 0 {
136136
return nil, status.Errorf(codes.InvalidArgument, "%v must be greater or equal than 0", Gid)
137137
}
138138
}

pkg/driver/provisioner_dir.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package driver
22

33
import (
44
"context"
5+
"math"
56
"os"
67
"path"
78
"strconv"
@@ -78,10 +79,38 @@ func (d DirectoryProvisioner) Provision(ctx context.Context, req *csi.CreateVolu
7879
}
7980
}
8081

81-
klog.V(5).Infof("Provisioning directory with permissions %s", perms)
82+
var uid int64
83+
if value, ok := volumeParams[Uid]; ok {
84+
uid, err = strconv.ParseInt(value, 10, 64)
85+
if err != nil {
86+
return nil, status.Errorf(codes.InvalidArgument, "Failed to parse invalid %v: %v", Uid, err)
87+
}
88+
if uid < 0 {
89+
return nil, status.Errorf(codes.InvalidArgument, "%v must be greater or equal than 0", Uid)
90+
}
91+
if uid > math.MaxInt {
92+
return nil, status.Errorf(codes.InvalidArgument, "%v must be lesser than math.MaxInt", Uid)
93+
}
94+
}
95+
96+
var gid int64
97+
if value, ok := volumeParams[Gid]; ok {
98+
gid, err = strconv.ParseInt(value, 10, 64)
99+
if err != nil {
100+
return nil, status.Errorf(codes.InvalidArgument, "Failed to parse invalid %v: %v", Gid, err)
101+
}
102+
if gid < 0 {
103+
return nil, status.Errorf(codes.InvalidArgument, "%v must be greater or equal than 0", Gid)
104+
}
105+
if gid > math.MaxInt {
106+
return nil, status.Errorf(codes.InvalidArgument, "%v must be lesser than math.MaxInt", Gid)
107+
}
108+
}
109+
110+
klog.V(5).Infof("Provisioning directory with permissions %s, uid %d, gid %d", perms, uid, gid)
82111

83112
provisionedDirectory := path.Join(target, provisionedPath)
84-
err = d.osClient.MkDirAllWithPermsNoOwnership(provisionedDirectory, perms)
113+
err = d.osClient.MkDirAllWithPerms(provisionedDirectory, perms, int(uid), int(gid))
85114
if err != nil {
86115
return nil, status.Errorf(codes.Internal, "Could not provision directory: %v", err)
87116
}

0 commit comments

Comments
 (0)