Skip to content

Commit

Permalink
Merge pull request #746 from JiaoDean/master
Browse files Browse the repository at this point in the history
support cpfs metrics
  • Loading branch information
fredkan authored Mar 18, 2023
2 parents 3b40597 + d8e0671 commit c27e0a9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pkg/nas/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
if strings.Contains(nfsServer, ".nas.aliyuncs.com") &&
!strings.Contains(nfsServer, ".extreme.nas.aliyuncs.com") &&
!strings.Contains(nfsServer, ".cpfs.nas.aliyuncs.com") {
fileSystemID = GetFsIDByServer(nfsServer)
fileSystemID = GetFsIDByNasServer(nfsServer)
if len(fileSystemID) != 0 {
//1、Does describe dir quota exist?
//2、If the dir quota exists, cancel the quota before deleting the subdirectory.
Expand Down
34 changes: 25 additions & 9 deletions pkg/nas/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const (
NasMntPoint = "/mnt/nasplugin.alibabacloud.com"
// MountProtocolNFS common nfs protocol
MountProtocolNFS = "nfs"
// MountProtocolCPFS common cpfs protocol
MountProtocolCPFSEAC = "cpfs-eac"
// MountProtocolCPFSNFS cpfs-nfs protocol
MountProtocolCPFSNFS = "cpfs-nfs"
// MountProtocolAliNas alinas protocal
Expand Down Expand Up @@ -163,6 +165,12 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
}
opt.Server = cnfs.Status.FsAttributes.Server
useEaClient = cnfs.Status.FsAttributes.UseElasticAccelerationClient
if cnfs.Status.FsAttributes.FilesystemType == "cpfs" {
opt.MountProtocol = MountProtocolCPFSNFS
if useEaClient == "true" {
opt.MountProtocol = MountProtocolCPFSEAC
}
}
}

if opt.LoopLock != "false" {
Expand Down Expand Up @@ -230,7 +238,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
doNfsPortCheck = false
}
if (opt.MountProtocol == MountProtocolNFS || opt.MountProtocol == MountProtocolAliNas) && doNfsPortCheck {
conn, err := net.DialTimeout("tcp", opt.Server+":"+NasPortnum, time.Second*time.Duration(3))
conn, err := net.DialTimeout("tcp", opt.Server+":"+NasPortnum, time.Second*time.Duration(30))
if err != nil {
log.Errorf("NAS: Cannot connect to nas host: %s", opt.Server)
return nil, errors.New("NAS: Cannot connect to nas host: " + opt.Server)
Expand All @@ -241,7 +249,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if opt.Path == "" {
opt.Path = "/"
}
// remove / if path end with /;
// if path end with /, remove /;
if opt.Path != "/" && strings.HasSuffix(opt.Path, "/") {
opt.Path = opt.Path[0 : len(opt.Path)-1]
}
Expand Down Expand Up @@ -279,7 +287,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis

// Create Mount Path
if err := utils.CreateDest(mountPath); err != nil {
return nil, errors.New("Nas, Mount error with create Path fail: " + mountPath)
return nil, errors.New("Create mount path is failed, mountPath: " + mountPath + ", err:" + err.Error())
}

// if volume set mountType as skipmount;
Expand Down Expand Up @@ -314,9 +322,9 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
checkSystemNasConfig()

//cpfs-nfs check valid
if opt.MountProtocol == MountProtocolCPFSNFS {
if opt.MountProtocol == MountProtocolCPFSNFS || opt.MountProtocol == MountProtocolCPFSEAC {
if !strings.HasPrefix(opt.Path, "/share") {
return nil, errors.New("The path to cpfs-nfs must start with /share.")
return nil, errors.New("The cpfs2.0 mount path must start with /share.")
}
}

Expand All @@ -331,11 +339,19 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
log.Errorf("Nas, Mount Nfs error: %s", err.Error())
return nil, errors.New("Nas, Mount Nfs error:" + err.Error())
}
if strings.Contains(opt.Server, ".nas.aliyuncs.com") && useEaClient == "true" {
fsID := GetFsIDByServer(opt.Server)
if len(fsID) != 0 {
utils.WriteMetricsInfo(metricsPathPrefix, req, "10", "eac", "nas", fsID)
if useEaClient == "true" {
if strings.Contains(opt.Server, ".nas.aliyuncs.com") {
fsID := GetFsIDByNasServer(opt.Server)
if len(fsID) != 0 {
utils.WriteMetricsInfo(metricsPathPrefix, req, "10", "eac", "nas", fsID)
}
} else {
fsID := GetFsIDByCpfsServer(opt.Server)
if len(fsID) != 0 {
utils.WriteMetricsInfo(metricsPathPrefix, req, "10", "eac", "cpfs", fsID)
}
}

}
// change the mode
if opt.Mode != "" && opt.Path != "/" {
Expand Down
54 changes: 38 additions & 16 deletions pkg/nas/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type RoleAuth struct {
// DoMount execute the mount command for nas dir
func DoMount(nfsProtocol, nfsServer, nfsPath, nfsVers, mountOptions, mountPoint, volumeID, podUID, useEaClient string) error {
if !utils.IsFileExisting(mountPoint) {
CreateDest(mountPoint)
_ = CreateDest(mountPoint)
}

if CheckNfsPathMounted(mountPoint, nfsPath) {
Expand All @@ -96,12 +96,13 @@ func DoMount(nfsProtocol, nfsServer, nfsPath, nfsVers, mountOptions, mountPoint,
var err error
//EAC Mount
if len(useEaClient) != 0 && useEaClient == "true" {
mntCmd = fmt.Sprintf("systemd-run --scope -- mount -t alinas -o eac -o bindtag=%s -o client_owner=%s -o %s %s:%s %s", volumeID, podUID, mountOptions, nfsServer, nfsPath, mountPoint)
if err := utils.DoMountInHost(mntCmd); err != nil {
return err
if nfsProtocol == MountProtocolCPFSEAC {
mntCmd = fmt.Sprintf("systemd-run --scope -- mount -t alinas -o eac -o protocol=nfs3 -o bindtag=%s -o client_owner=%s -o %s %s:%s %s", volumeID, podUID, mountOptions, nfsServer, nfsPath, mountPoint)
} else {
mntCmd = fmt.Sprintf("systemd-run --scope -- mount -t alinas -o eac -o bindtag=%s -o client_owner=%s -o %s %s:%s %s", volumeID, podUID, mountOptions, nfsServer, nfsPath, mountPoint)
}
} else {
//NFS Mount(Capacity/Performance Extreme Nas、Cpfs2.0, AliNas)
//NFS Mount(Capacdity/Performance Extreme Nas、Cpfs2.0, AliNas)
versStr := fmt.Sprintf("vers=%s", nfsVers)
if mountOptions == "" {
mountOptions = versStr
Expand All @@ -114,11 +115,17 @@ func DoMount(nfsProtocol, nfsServer, nfsPath, nfsVers, mountOptions, mountPoint,
}
_, err = utils.Run(mntCmd)

//Mount rootpath is failed, return err
//try mount nfsPath is successfully.
if err == nil {
log.Infof("DoMount: Mount is successfully with command: %s", mntCmd)
return nil
}

//mount root-path is failed, return error
if err != nil && nfsPath == "/" {
return err
}
//Mount subpath is failed, if subpath is not exist or cpfs don't output subpath
//mount sub-path is failed, if subpath is not exist or cpfs don't output subpath
if err != nil && nfsPath != "/" {
//Other errors
if !strings.Contains(err.Error(), "reason given by server: No such file or directory") && !strings.Contains(err.Error(), "access denied by server while mounting") {
Expand All @@ -128,13 +135,19 @@ func DoMount(nfsProtocol, nfsServer, nfsPath, nfsVers, mountOptions, mountPoint,
log.Errorf("DoMount: Create subpath is failed, err: %s", err.Error())
return err
}
if _, err := utils.Run(mntCmd); err != nil {
log.Errorf("DoMount: Mount %s is failed, err: %s", mntCmd, err.Error())
return err
}
}
}
log.Infof("DoMount: Mount nfs is successfully with command: %s", mntCmd)
//execute mount
if len(useEaClient) != 0 && useEaClient == "true" {
err = utils.DoMountInHost(mntCmd)
} else {
_, err = utils.Run(mntCmd)
}
if err != nil {
log.Errorf("DoMount: Mount %s is failed, err: %s", mntCmd, err.Error())
return err
}
log.Infof("DoMount: Mount is successfully with command: %s", mntCmd)
return nil
}

Expand Down Expand Up @@ -644,28 +657,37 @@ func getPvObj(volumeID string) (*v1.PersistentVolume, error) {

func isValidCnfsParameter(server string, cnfsName string) error {
if len(server) == 0 && len(cnfsName) == 0 {
msg := fmt.Sprintf("Server and ContainerNetworkFileSystem need to be configured at least one.")
msg := fmt.Sprintf("Server and Cnfs need to be configured at least one.")
log.Errorf(msg)
return errors.New(msg)
}

if len(server) != 0 && len(cnfsName) != 0 {
msg := fmt.Sprintf("Server and ContainerNetworkFileSystem can only be configured to use one.")
msg := fmt.Sprintf("Server and Cnfs can only be configured to use one.")
log.Errorf(msg)
return errors.New(msg)
}
return nil
}

// GetFsIDByServer func is get fsID from serverName
func GetFsIDByServer(server string) string {
// GetFsIDByNasServer func is get fsID from serverName
func GetFsIDByNasServer(server string) string {
if len(server) == 0 {
return ""
}
serverArray := strings.Split(server, "-")
return serverArray[0]
}

// GetFsIDByCpfsServer func is get fsID from serverName
func GetFsIDByCpfsServer(server string) string {
if len(server) == 0 {
return ""
}
serverArray := strings.Split(server, "-")
return serverArray[0] + "-" + serverArray[1]
}

func saveVolumeData(opt *Options, mountPath string) {
// save volume data to json file
if utils.IsKataInstall() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const (
fsckErrorsUncorrected = 4

// NsenterCmd is the nsenter command
NsenterCmd = "nsenter --mount=/proc/1/ns/mnt --ipc=/proc/1/ns/ipc --net=/proc/1/ns/net --uts=/proc/1/ns/uts "
NsenterCmd = "nsenter --mount=/proc/1/ns/mnt --ipc=/proc/1/ns/ipc --net=/proc/1/ns/net --uts=/proc/1/ns/uts"

// socketPath is path of connector sock
socketPath = "/host/etc/csi-tool/connector.sock"
Expand Down

0 comments on commit c27e0a9

Please sign in to comment.