Skip to content

Commit 5ae2584

Browse files
authored
Merge pull request #263 from andyzhangx/workingMountDir
feat: add workingMountDir in chart config
2 parents 5423797 + 405a69c commit 5ae2584

File tree

13 files changed

+112
-101
lines changed

13 files changed

+112
-101
lines changed

.github/workflows/linux.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Set up Go 1.x
1414
uses: actions/setup-go@v2
1515
with:
16-
go-version: ^1.16
16+
go-version: ^1.17
1717
id: go
1818

1919
- name: Check out code into the Go module directory

charts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The following table lists the configurable parameters of the latest NFS CSI Driv
5858
| `controller.replicas` | the replicas of csi-nfs-controller | `2` |
5959
| `controller.runOnMaster` | run controller on master node | `false` |
6060
| `controller.logLevel` | controller driver log level |`5` |
61+
| `controller.workingMountDir` | working directory for provisioner to mount nfs shares temporarily | `/tmp` |
6162
| `controller.tolerations` | controller pod tolerations | |
6263
| `controller.resources.csiProvisioner.limits.memory` | csi-provisioner memory limits | 100Mi |
6364
| `controller.resources.csiProvisioner.requests.cpu` | csi-provisioner cpu requests limits | 10m |
27 Bytes
Binary file not shown.

charts/latest/csi-driver-nfs/templates/csi-nfs-controller.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ spec:
7373
- "--endpoint=$(CSI_ENDPOINT)"
7474
- "--drivername={{ .Values.driver.name }}"
7575
- "--mount-permissions={{ .Values.driver.mountPermissions }}"
76+
- "--working-mount-dir={{ .Values.controller.workingMountDir }}"
7677
env:
7778
- name: NODE_ID
7879
valueFrom:

charts/latest/csi-driver-nfs/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rbac:
2626

2727
driver:
2828
name: nfs.csi.k8s.io
29-
mountPermissions: "0777"
29+
mountPermissions: 0777
3030

3131
feature:
3232
enableFSGroupPolicy: false
@@ -38,6 +38,7 @@ controller:
3838
livenessProbe:
3939
healthPort: 29652
4040
logLevel: 5
41+
workingMountDir: "/tmp"
4142
tolerations:
4243
- key: "node-role.kubernetes.io/master"
4344
operator: "Exists"

cmd/nfsplugin/main.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ package main
1818

1919
import (
2020
"flag"
21-
"fmt"
2221
"os"
23-
"strconv"
2422

2523
"github.com/kubernetes-csi/csi-driver-nfs/pkg/nfs"
2624

2725
"k8s.io/klog/v2"
2826
)
2927

3028
var (
31-
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
32-
nodeID = flag.String("nodeid", "", "node id")
33-
perm = flag.String("mount-permissions", "0777", "mounted folder permissions")
34-
driverName = flag.String("drivername", nfs.DefaultDriverName, "name of the driver")
29+
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
30+
nodeID = flag.String("nodeid", "", "node id")
31+
mountPermissions = flag.Uint64("mount-permissions", 0777, "mounted folder permissions")
32+
driverName = flag.String("drivername", nfs.DefaultDriverName, "name of the driver")
33+
workingMountDir = flag.String("working-mount-dir", "/tmp", "working directory for provisioner to mount nfs shares temporarily")
3534
)
3635

3736
func init() {
@@ -50,18 +49,13 @@ func main() {
5049
}
5150

5251
func handle() {
53-
// Converting string permission representation to *uint32
54-
var parsedPerm *uint32
55-
if perm != nil && *perm != "" {
56-
permu64, err := strconv.ParseUint(*perm, 8, 32)
57-
if err != nil {
58-
fmt.Fprintf(os.Stderr, "incorrect mount-permissions value: %q", *perm)
59-
os.Exit(1)
60-
}
61-
permu32 := uint32(permu64)
62-
parsedPerm = &permu32
52+
driverOptions := nfs.DriverOptions{
53+
NodeID: *nodeID,
54+
DriverName: *driverName,
55+
Endpoint: *endpoint,
56+
MountPermissions: *mountPermissions,
57+
WorkingMountDir: *workingMountDir,
6358
}
64-
65-
d := nfs.NewDriver(*nodeID, *driverName, *endpoint, parsedPerm)
59+
d := nfs.NewDriver(&driverOptions)
6660
d.Run(false)
6761
}

pkg/nfs/controllerserver.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import (
3434
// ControllerServer controller server setting
3535
type ControllerServer struct {
3636
Driver *Driver
37-
// Working directory for the provisioner to temporarily mount nfs shares at
38-
workingMountDir string
3937
}
4038

4139
// nfsVolume is an internal representation of a volume
@@ -98,10 +96,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
9896
}
9997
}()
10098

101-
fileMode := os.FileMode(0777)
102-
if cs.Driver.perm != nil {
103-
fileMode = os.FileMode(*cs.Driver.perm)
104-
}
99+
fileMode := os.FileMode(cs.Driver.mountPermissions)
105100
// Create subdirectory under base-dir
106101
internalVolumePath := cs.getInternalVolumePath(nfsVol)
107102
if err = os.Mkdir(internalVolumePath, fileMode); err != nil && !os.IsExist(err) {
@@ -140,7 +135,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
140135
}
141136
}
142137

143-
// Mount nfs base share so we can delete the subdirectory
138+
// mount nfs base share so we can delete the subdirectory
144139
if err = cs.internalMount(ctx, nfsVol, volCap); err != nil {
145140
return nil, status.Errorf(codes.Internal, "failed to mount nfs server: %v", err.Error())
146141
}
@@ -150,7 +145,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
150145
}
151146
}()
152147

153-
// Delete subdirectory under base-dir
148+
// delete subdirectory under base-dir
154149
internalVolumePath := cs.getInternalVolumePath(nfsVol)
155150

156151
klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath)
@@ -293,10 +288,7 @@ func (cs *ControllerServer) internalUnmount(ctx context.Context, vol *nfsVolume)
293288

294289
// Convert VolumeCreate parameters to an nfsVolume
295290
func (cs *ControllerServer) newNFSVolume(name string, size int64, params map[string]string) (*nfsVolume, error) {
296-
var (
297-
server string
298-
baseDir string
299-
)
291+
var server, baseDir string
300292

301293
// validate parameters (case-insensitive)
302294
for k, v := range params {
@@ -310,7 +302,6 @@ func (cs *ControllerServer) newNFSVolume(name string, size int64, params map[str
310302
}
311303
}
312304

313-
// validate required parameters
314305
if server == "" {
315306
return nil, fmt.Errorf("%v is a required parameter", paramServer)
316307
}
@@ -331,11 +322,7 @@ func (cs *ControllerServer) newNFSVolume(name string, size int64, params map[str
331322

332323
// Get working directory for CreateVolume and DeleteVolume
333324
func (cs *ControllerServer) getInternalMountPath(vol *nfsVolume) string {
334-
// use default if empty
335-
if cs.workingMountDir == "" {
336-
cs.workingMountDir = "/tmp"
337-
}
338-
return filepath.Join(cs.workingMountDir, vol.subDir)
325+
return filepath.Join(cs.Driver.workingMountDir, vol.subDir)
339326
}
340327

341328
// Get internal path where the volume is created

pkg/nfs/controllerserver_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ var (
4747
)
4848

4949
func initTestController(t *testing.T) *ControllerServer {
50-
var perm *uint32
5150
mounter := &mount.FakeMounter{MountPoints: []mount.MountPoint{}}
52-
driver := NewDriver("", "", "", perm)
51+
driver := NewDriver(&DriverOptions{
52+
WorkingMountDir: "/tmp",
53+
MountPermissions: 0777,
54+
})
5355
driver.ns = NewNodeServer(driver, mounter)
5456
cs := NewControllerServer(driver)
55-
cs.workingMountDir = "/tmp"
5657
return cs
5758
}
5859

@@ -189,7 +190,7 @@ func TestCreateVolume(t *testing.T) {
189190
t.Errorf("test %q failed: got resp %+v, expected %+v", test.name, resp, test.resp)
190191
}
191192
if !test.expectErr {
192-
info, err := os.Stat(filepath.Join(cs.workingMountDir, test.req.Name, test.req.Name))
193+
info, err := os.Stat(filepath.Join(cs.Driver.workingMountDir, test.req.Name, test.req.Name))
193194
if err != nil {
194195
t.Errorf("test %q failed: couldn't find volume subdirectory: %v", test.name, err)
195196
}
@@ -227,8 +228,8 @@ func TestDeleteVolume(t *testing.T) {
227228
t.Run(test.desc, func(t *testing.T) {
228229
// Setup
229230
cs := initTestController(t)
230-
_ = os.MkdirAll(filepath.Join(cs.workingMountDir, testCSIVolume), os.ModePerm)
231-
_, _ = os.Create(filepath.Join(cs.workingMountDir, testCSIVolume, testCSIVolume))
231+
_ = os.MkdirAll(filepath.Join(cs.Driver.workingMountDir, testCSIVolume), os.ModePerm)
232+
_, _ = os.Create(filepath.Join(cs.Driver.workingMountDir, testCSIVolume, testCSIVolume))
232233

233234
// Run
234235
resp, err := cs.DeleteVolume(context.TODO(), test.req)
@@ -243,7 +244,7 @@ func TestDeleteVolume(t *testing.T) {
243244
if !reflect.DeepEqual(resp, test.resp) {
244245
t.Errorf("test %q failed: got resp %+v, expected %+v", test.desc, resp, test.resp)
245246
}
246-
if _, err := os.Stat(filepath.Join(cs.workingMountDir, testCSIVolume, testCSIVolume)); test.expectedErr == nil && !os.IsNotExist(err) {
247+
if _, err := os.Stat(filepath.Join(cs.Driver.workingMountDir, testCSIVolume, testCSIVolume)); test.expectedErr == nil && !os.IsNotExist(err) {
247248
t.Errorf("test %q failed: expected volume subdirectory deleted, it still exists", test.desc)
248249
}
249250
})

pkg/nfs/nfs.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,27 @@ limitations under the License.
1717
package nfs
1818

1919
import (
20-
"fmt"
21-
2220
"github.com/container-storage-interface/spec/lib/go/csi"
2321
"k8s.io/klog/v2"
2422
mount "k8s.io/mount-utils"
2523
)
2624

27-
type Driver struct {
28-
name string
29-
nodeID string
30-
version string
31-
32-
endpoint string
25+
// DriverOptions defines driver parameters specified in driver deployment
26+
type DriverOptions struct {
27+
NodeID string
28+
DriverName string
29+
Endpoint string
30+
MountPermissions uint64
31+
WorkingMountDir string
32+
}
3333

34-
perm *uint32
34+
type Driver struct {
35+
name string
36+
nodeID string
37+
version string
38+
endpoint string
39+
mountPermissions uint64
40+
workingMountDir string
3541

3642
//ids *identityServer
3743
ns *NodeServer
@@ -53,16 +59,17 @@ const (
5359
mountOptionsField = "mountoptions"
5460
)
5561

56-
func NewDriver(nodeID, driverName, endpoint string, perm *uint32) *Driver {
57-
klog.V(2).Infof("Driver: %v version: %v", driverName, driverVersion)
62+
func NewDriver(options *DriverOptions) *Driver {
63+
klog.V(2).Infof("Driver: %v version: %v", options.DriverName, driverVersion)
5864

5965
n := &Driver{
60-
name: driverName,
61-
version: driverVersion,
62-
nodeID: nodeID,
63-
endpoint: endpoint,
64-
cap: map[csi.VolumeCapability_AccessMode_Mode]bool{},
65-
perm: perm,
66+
name: options.DriverName,
67+
version: driverVersion,
68+
nodeID: options.NodeID,
69+
endpoint: options.Endpoint,
70+
mountPermissions: options.MountPermissions,
71+
workingMountDir: options.WorkingMountDir,
72+
cap: map[csi.VolumeCapability_AccessMode_Mode]bool{},
6673
}
6774

6875
vcam := []csi.VolumeCapability_AccessMode_Mode{
@@ -102,7 +109,7 @@ func (n *Driver) Run(testMode bool) {
102109
if err != nil {
103110
klog.Fatalf("%v", err)
104111
}
105-
klog.Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta)
112+
klog.V(2).Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta)
106113

107114
n.ns = NewNodeServer(n, mount.New(""))
108115
s := NewNonBlockingGRPCServer()
@@ -119,7 +126,6 @@ func (n *Driver) Run(testMode bool) {
119126
func (n *Driver) AddVolumeCapabilityAccessModes(vc []csi.VolumeCapability_AccessMode_Mode) []*csi.VolumeCapability_AccessMode {
120127
var vca []*csi.VolumeCapability_AccessMode
121128
for _, c := range vc {
122-
klog.Infof("Enabling volume access mode: %v", c.String())
123129
vca = append(vca, &csi.VolumeCapability_AccessMode{Mode: c})
124130
n.cap[c] = true
125131
}
@@ -128,26 +134,21 @@ func (n *Driver) AddVolumeCapabilityAccessModes(vc []csi.VolumeCapability_Access
128134

129135
func (n *Driver) AddControllerServiceCapabilities(cl []csi.ControllerServiceCapability_RPC_Type) {
130136
var csc []*csi.ControllerServiceCapability
131-
132137
for _, c := range cl {
133-
klog.Infof("Enabling controller service capability: %v", c.String())
134138
csc = append(csc, NewControllerServiceCapability(c))
135139
}
136-
137140
n.cscap = csc
138141
}
139142

140143
func (n *Driver) AddNodeServiceCapabilities(nl []csi.NodeServiceCapability_RPC_Type) {
141144
var nsc []*csi.NodeServiceCapability
142145
for _, n := range nl {
143-
klog.Infof("Enabling node service capability: %v", n.String())
144146
nsc = append(nsc, NewNodeServiceCapability(n))
145147
}
146148
n.nscap = nsc
147149
}
148150

149151
func IsCorruptedDir(dir string) bool {
150152
_, pathErr := mount.PathExists(dir)
151-
fmt.Printf("IsCorruptedDir(%s) returned with error: %v", dir, pathErr)
152153
return pathErr != nil && mount.IsCorruptedMnt(pathErr)
153154
}

pkg/nfs/nfs_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,27 @@ const (
3232

3333
func NewEmptyDriver(emptyField string) *Driver {
3434
var d *Driver
35-
var perm *uint32
3635
switch emptyField {
3736
case "version":
3837
d = &Driver{
3938
name: DefaultDriverName,
4039
version: "",
4140
nodeID: fakeNodeID,
4241
cap: map[csi.VolumeCapability_AccessMode_Mode]bool{},
43-
perm: perm,
4442
}
4543
case "name":
4644
d = &Driver{
4745
name: "",
4846
version: driverVersion,
4947
nodeID: fakeNodeID,
5048
cap: map[csi.VolumeCapability_AccessMode_Mode]bool{},
51-
perm: perm,
5249
}
5350
default:
5451
d = &Driver{
5552
name: DefaultDriverName,
5653
version: driverVersion,
5754
nodeID: fakeNodeID,
5855
cap: map[csi.VolumeCapability_AccessMode_Mode]bool{},
59-
perm: perm,
6056
}
6157
}
6258
d.volumeLocks = NewVolumeLocks()

0 commit comments

Comments
 (0)