Skip to content

Commit 7313ee8

Browse files
committed
fix: deal with unsupported mounter
1 parent 8cf2b83 commit 7313ee8

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

pkg/mounter/cmd_mounter.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"time"
1010

11-
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/mounter/utils"
1211
"k8s.io/klog/v2"
1312
"k8s.io/mount-utils"
1413
)
@@ -57,12 +56,6 @@ func (m *OssCmdMounter) MountWithSecrets(source, target, fstype string, options
5756
}
5857
return nil
5958
}
60-
func saveOssSecretsToFileIfNeeded(authCfg *utils.AuthConfig) (string, error) {
61-
if authCfg == nil || authCfg.Secrets == nil {
62-
return "", nil
63-
}
64-
return saveOssSecretsToFile(authCfg.Secrets)
65-
}
6659

6760
func saveOssSecretsToFile(secrets map[string]string) (filePath string, err error) {
6861
passwd := secrets["passwd-ossfs"]

pkg/mounter/mounter.go

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

33
import (
44
"fmt"
5+
"strings"
56

67
mountutils "k8s.io/mount-utils"
78
)
@@ -16,3 +17,10 @@ type Mounter interface {
1617
func ErrNotImplemented(driver, mounterType, method string) error {
1718
return fmt.Errorf("%s(%s): %s not implemented", mounterType, driver, method)
1819
}
20+
21+
func IsNotImplementedErr(err error) bool {
22+
if err == nil {
23+
return false
24+
}
25+
return strings.Contains(err.Error(), "not implemented")
26+
}

pkg/oss/nodeserver.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
109109
if err := validateNodePublishVolumeRequest(req); err != nil {
110110
return nil, err
111111
}
112+
attachPath := mounterutils.GetAttachPath(req.VolumeId)
112113

113114
// parse options
114115
// ensure fuseType is not empty
@@ -176,11 +177,21 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
176177
}
177178
if !notMnt {
178179
klog.Infof("NodePublishVolume: %s already mounted", targetPath)
179-
if needRotateToken(opts, authCfg.Secrets) {
180-
err := ossfsMounter.RotateToken(targetPath, opts.FuseType, authCfg.Secrets)
180+
if !features.FunctionalMutableFeatureGate.Enabled(features.RundCSIProtocol3) && needRotateToken(opts, authCfg.Secrets) {
181+
// mountPath is the target path for mounter
182+
mountPath := attachPath
183+
if ns.skipAttach {
184+
mountPath = targetPath
185+
}
186+
err := ossfsMounter.RotateToken(mountPath, opts.FuseType, authCfg.Secrets)
181187
if err != nil {
188+
// if is mounter not supported, return unimplentederror to avoid retry
189+
if mounter.IsNotImplementedErr(err) {
190+
return nil, status.Error(codes.Unimplemented, err.Error())
191+
}
182192
return nil, status.Error(codes.Internal, err.Error())
183193
}
194+
klog.Infof("NodePublishVolume: %s already rotated token", targetPath)
184195
}
185196
return &csi.NodePublishVolumeResponse{}, nil
186197
}
@@ -200,7 +211,6 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
200211

201212
// When work as csi nodeserver, mount on the attach path under /run/fuse.ossfs and then perform the bind mount.
202213
// check whether the attach path is mounted
203-
attachPath := mounterutils.GetAttachPath(req.VolumeId)
204214
notMnt, err = isNotMountPoint(ns.rawMounter, attachPath)
205215
if err != nil {
206216
return nil, err

0 commit comments

Comments
 (0)