Skip to content

Commit 999b3a2

Browse files
authored
Merge pull request #527 from andyzhangx/removeSMBMappingDuringUnmount-switch
feat: add removeSMBMappingDuringUnmount config in chart config
2 parents eb9ddbc + 05f9162 commit 999b3a2

File tree

13 files changed

+78
-69
lines changed

13 files changed

+78
-69
lines changed

charts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The following table lists the configurable parameters of the latest SMB CSI Driv
103103
| `linux.resources.smb.requests.memory` | smb-csi-driver memory requests limits | `20Mi`
104104
| `windows.enabled` | whether enable windows feature | `false` |
105105
| `windows.dsName` | name of driver daemonset on windows | `csi-smb-node-win` |
106+
| `windows.removeSMBMappingDuringUnmount` | remove SMBMapping during unmount on Windows node windows | `true` |
106107
| `windows.resources.livenessProbe.limits.memory` | liveness-probe memory limits | `200Mi` |
107108
| `windows.resources.livenessProbe.requests.cpu` | liveness-probe cpu requests limits | `10m` |
108109
| `windows.resources.livenessProbe.requests.memory` | liveness-probe memory requests limits | `20Mi` |
65 Bytes
Binary file not shown.

charts/latest/csi-driver-smb/templates/csi-smb-node-windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ spec:
102102
- --nodeid=$(KUBE_NODE_NAME)
103103
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
104104
- "--enable-get-volume-stats={{ .Values.feature.enableGetVolumeStats }}"
105+
- "--remove-smb-mapping-during-unmount={{ .Values.windows.removeSMBMappingDuringUnmount }}"
105106
ports:
106107
- containerPort: {{ .Values.node.livenessProbe.healthPort }}
107108
name: healthz

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ windows:
115115
enabled: false
116116
dsName: csi-smb-node-win # daemonset name
117117
kubelet: 'C:\var\lib\kubelet'
118+
removeSMBMappingDuringUnmount: true
118119
tolerations:
119120
- key: "node.kubernetes.io/os"
120121
operator: "Exists"

cmd/smbplugin/main.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ func init() {
3636
}
3737

3838
var (
39-
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
40-
nodeID = flag.String("nodeid", "", "node id")
41-
driverName = flag.String("drivername", smb.DefaultDriverName, "name of the driver")
42-
ver = flag.Bool("ver", false, "Print the version and exit.")
43-
metricsAddress = flag.String("metrics-address", "0.0.0.0:29644", "export the metrics")
44-
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
45-
enableGetVolumeStats = flag.Bool("enable-get-volume-stats", true, "allow GET_VOLUME_STATS on agent node")
46-
workingMountDir = flag.String("working-mount-dir", "/tmp", "working directory for provisioner to mount smb shares temporarily")
39+
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
40+
nodeID = flag.String("nodeid", "", "node id")
41+
driverName = flag.String("drivername", smb.DefaultDriverName, "name of the driver")
42+
ver = flag.Bool("ver", false, "Print the version and exit.")
43+
metricsAddress = flag.String("metrics-address", "0.0.0.0:29644", "export the metrics")
44+
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
45+
enableGetVolumeStats = flag.Bool("enable-get-volume-stats", true, "allow GET_VOLUME_STATS on agent node")
46+
removeSMBMappingDuringUnmount = flag.Bool("remove-smb-mapping-during-unmount", true, "remove SMBMapping during unmount on Windows node")
47+
workingMountDir = flag.String("working-mount-dir", "/tmp", "working directory for provisioner to mount smb shares temporarily")
4748
)
4849

4950
func main() {
@@ -67,10 +68,11 @@ func main() {
6768

6869
func handle() {
6970
driverOptions := smb.DriverOptions{
70-
NodeID: *nodeID,
71-
DriverName: *driverName,
72-
EnableGetVolumeStats: *enableGetVolumeStats,
73-
WorkingMountDir: *workingMountDir,
71+
NodeID: *nodeID,
72+
DriverName: *driverName,
73+
EnableGetVolumeStats: *enableGetVolumeStats,
74+
RemoveSMBMappingDuringUnmount: *removeSMBMappingDuringUnmount,
75+
WorkingMountDir: *workingMountDir,
7476
}
7577
driver := smb.NewDriver(&driverOptions)
7678
driver.Run(*endpoint, *kubeconfig, false)

deploy/csi-smb-node-windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ spec:
8989
- --endpoint=$(CSI_ENDPOINT)
9090
- --nodeid=$(KUBE_NODE_NAME)
9191
- "--metrics-address=0.0.0.0:29645"
92+
- "--remove-smb-mapping-during-unmount=true"
9293
ports:
9394
- containerPort: 29643
9495
name: healthz

pkg/csi-common/server_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ func TestNewNonBlockingGRPCServer(t *testing.T) {
3333
func TestStart(t *testing.T) {
3434
s := NewNonBlockingGRPCServer()
3535
// sleep a while to avoid race condition in unit test
36-
time.Sleep(time.Millisecond * 2000)
36+
time.Sleep(time.Millisecond * 500)
3737
s.Start("tcp://127.0.0.1:0", nil, nil, nil, true)
38+
time.Sleep(time.Millisecond * 500)
3839
}
3940

4041
func TestServe(t *testing.T) {

pkg/mounter/safe_mounter_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
utilexec "k8s.io/utils/exec"
2525
)
2626

27-
func NewSafeMounter() (*mount.SafeFormatAndMount, error) {
27+
func NewSafeMounter(removeSMBMappingDuringUnmount bool) (*mount.SafeFormatAndMount, error) {
2828
return &mount.SafeFormatAndMount{
2929
Interface: mount.New(""),
3030
Exec: utilexec.New(),

pkg/mounter/safe_mounter_unix_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func TestNewSafeMounter(t *testing.T) {
26-
resp, err := NewSafeMounter()
26+
resp, err := NewSafeMounter(true)
2727
assert.NotNil(t, resp)
2828
assert.Nil(t, err)
2929
}

pkg/mounter/safe_mounter_windows.go

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ type CSIProxyMounter interface {
5555
var _ CSIProxyMounter = &csiProxyMounter{}
5656

5757
type csiProxyMounter struct {
58-
FsClient *fsclient.Client
59-
SMBClient *smbclient.Client
58+
FsClient *fsclient.Client
59+
SMBClient *smbclient.Client
60+
RemoveSMBMappingDuringUnmount bool
6061
}
6162

6263
func normalizeWindowsPath(path string) string {
@@ -101,12 +102,9 @@ func (mounter *csiProxyMounter) SMBMount(source, target, fsType string, mountOpt
101102
}
102103

103104
source = strings.Replace(source, "/", "\\", -1)
104-
if strings.HasSuffix(source, "\\") {
105-
source = strings.TrimSuffix(source, "\\")
106-
}
107-
105+
source = strings.TrimSuffix(source, "\\")
108106
mappingPath, err := getRootMappingPath(source)
109-
if err != nil {
107+
if mounter.RemoveSMBMappingDuringUnmount && err != nil {
110108
return fmt.Errorf("getRootMappingPath(%s) failed with error: %v", source, err)
111109
}
112110
unlock := lock(mappingPath)
@@ -119,16 +117,17 @@ func (mounter *csiProxyMounter) SMBMount(source, target, fsType string, mountOpt
119117
Username: mountOptions[0],
120118
Password: sensitiveMountOptions[0],
121119
}
122-
klog.V(2).Infof("begin to mount %s on %s", source, normalizedTarget)
120+
klog.V(2).Infof("begin to NewSmbGlobalMapping %s on %s", source, normalizedTarget)
123121
if _, err := mounter.SMBClient.NewSmbGlobalMapping(context.Background(), smbMountRequest); err != nil {
124-
return fmt.Errorf("smb mapping failed with error: %v", err)
122+
return fmt.Errorf("NewSmbGlobalMapping(%s, %s) failed with error: %v", source, normalizedTarget, err)
125123
}
126-
klog.V(2).Infof("mount %s on %s successfully", source, normalizedTarget)
124+
klog.V(2).Infof("NewSmbGlobalMapping %s on %s successfully", source, normalizedTarget)
127125

128-
if err = incementRemotePathReferencesCount(mappingPath, source); err != nil {
129-
klog.Warningf("incementMappingPathCount(%s, %s) failed with error: %v", mappingPath, source, err)
126+
if mounter.RemoveSMBMappingDuringUnmount {
127+
if err := incementRemotePathReferencesCount(mappingPath, source); err != nil {
128+
return fmt.Errorf("incementMappingPathCount(%s, %s) failed with error: %v", mappingPath, source, err)
129+
}
130130
}
131-
132131
return nil
133132
}
134133

@@ -138,35 +137,32 @@ func (mounter *csiProxyMounter) SMBUnmount(target string) error {
138137
if remotePath, err := os.Readlink(target); err != nil {
139138
klog.Warningf("SMBUnmount: can't get remote path: %v", err)
140139
} else {
141-
if strings.HasSuffix(remotePath, "\\") {
142-
remotePath = strings.TrimSuffix(remotePath, "\\")
143-
}
140+
remotePath = strings.TrimSuffix(remotePath, "\\")
144141
mappingPath, err := getRootMappingPath(remotePath)
145-
if err != nil {
146-
klog.Warningf("getRootMappingPath(%s) failed with error: %v", remotePath, err)
147-
} else {
148-
klog.V(4).Infof("SMBUnmount: remote path: %s, mapping path: %s", remotePath, mappingPath)
142+
if mounter.RemoveSMBMappingDuringUnmount && err != nil {
143+
return fmt.Errorf("getRootMappingPath(%s) failed with error: %v", remotePath, err)
144+
}
145+
klog.V(4).Infof("SMBUnmount: remote path: %s, mapping path: %s", remotePath, mappingPath)
149146

150-
unlock := lock(mappingPath)
151-
defer unlock()
147+
unlock := lock(mappingPath)
148+
defer unlock()
152149

150+
if mounter.RemoveSMBMappingDuringUnmount {
153151
if err := decrementRemotePathReferencesCount(mappingPath, remotePath); err != nil {
154-
klog.Warningf("decrementMappingPathCount(%s, %d) failed with error: %v", mappingPath, remotePath, err)
155-
} else {
156-
count := getRemotePathReferencesCount(mappingPath)
157-
if count == 0 {
158-
smbUnmountRequest := &smb.RemoveSmbGlobalMappingRequest{
159-
RemotePath: remotePath,
160-
}
161-
klog.V(2).Infof("begin to unmount %s on %s", remotePath, target)
162-
if _, err := mounter.SMBClient.RemoveSmbGlobalMapping(context.Background(), smbUnmountRequest); err != nil {
163-
return fmt.Errorf("smb unmapping failed with error: %v", err)
164-
} else {
165-
klog.V(2).Infof("unmount %s on %s successfully", remotePath, target)
166-
}
167-
} else {
168-
klog.Infof("SMBUnmount: found %f links to %s", count, mappingPath)
152+
return fmt.Errorf("decrementMappingPathCount(%s, %s) failed with error: %v", mappingPath, remotePath, err)
153+
}
154+
count := getRemotePathReferencesCount(mappingPath)
155+
if count == 0 {
156+
smbUnmountRequest := &smb.RemoveSmbGlobalMappingRequest{
157+
RemotePath: remotePath,
158+
}
159+
klog.V(2).Infof("begin to RemoveSmbGlobalMapping %s on %s", remotePath, target)
160+
if _, err := mounter.SMBClient.RemoveSmbGlobalMapping(context.Background(), smbUnmountRequest); err != nil {
161+
return fmt.Errorf("RemoveSmbGlobalMapping failed with error: %v", err)
169162
}
163+
klog.V(2).Infof("RemoveSmbGlobalMapping %s on %s successfully", remotePath, target)
164+
} else {
165+
klog.Infof("SMBUnmount: found %d links to %s", count, mappingPath)
170166
}
171167
}
172168
}
@@ -342,7 +338,7 @@ func (mounter *csiProxyMounter) MountSensitiveWithoutSystemdWithMountFlags(sourc
342338

343339
// NewCSIProxyMounter - creates a new CSI Proxy mounter struct which encompassed all the
344340
// clients to the CSI proxy - filesystem, disk and volume clients.
345-
func NewCSIProxyMounter() (*csiProxyMounter, error) {
341+
func NewCSIProxyMounter(removeSMBMappingDuringUnmount bool) (*csiProxyMounter, error) {
346342
fsClient, err := fsclient.NewClient()
347343
if err != nil {
348344
return nil, err
@@ -353,13 +349,14 @@ func NewCSIProxyMounter() (*csiProxyMounter, error) {
353349
}
354350

355351
return &csiProxyMounter{
356-
FsClient: fsClient,
357-
SMBClient: smbClient,
352+
FsClient: fsClient,
353+
SMBClient: smbClient,
354+
RemoveSMBMappingDuringUnmount: removeSMBMappingDuringUnmount,
358355
}, nil
359356
}
360357

361-
func NewSafeMounter() (*mount.SafeFormatAndMount, error) {
362-
csiProxyMounter, err := NewCSIProxyMounter()
358+
func NewSafeMounter(removeSMBMappingDuringUnmount bool) (*mount.SafeFormatAndMount, error) {
359+
csiProxyMounter, err := NewCSIProxyMounter(removeSMBMappingDuringUnmount)
363360
if err == nil {
364361
klog.V(2).Infof("using CSIProxyMounterV1, %s", csiProxyMounter.GetAPIVersions())
365362
return &mount.SafeFormatAndMount{

0 commit comments

Comments
 (0)