Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node Publish volume changes for the nfs support #192

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3bcd44b
indentation fixed for controller.yaml
khareRajshree May 7, 2023
39e88c6
NFS storage class yaml updated
khareRajshree May 7, 2023
e7304c8
create NFS volume implemented
khareRajshree May 7, 2023
45e9e5c
go.mod and go.sum updated
khareRajshree May 8, 2023
d62f5a1
update controller publish volume for nfs.
VamsiSiddu-7 May 8, 2023
4178044
Merge branch 'nfs-create-volume' of https://github.com/dell/csi-power…
VamsiSiddu-7 May 8, 2023
16731eb
hardcoded volume name for testing.
VamsiSiddu-7 May 8, 2023
8134973
add debug.
VamsiSiddu-7 May 8, 2023
628f423
files updated
khareRajshree May 9, 2023
c9e6068
add debug.
VamsiSiddu-7 May 10, 2023
7e56707
Merge branch 'nfs-create-volume' of https://github.com/dell/csi-power…
VamsiSiddu-7 May 10, 2023
2d7fd6c
removed debug statements
khareRajshree May 10, 2023
cf0b1ea
add debug.
VamsiSiddu-7 May 10, 2023
3417c10
fixed error.
VamsiSiddu-7 May 10, 2023
7071293
fix the panic.
VamsiSiddu-7 May 10, 2023
678d3de
add debug.
VamsiSiddu-7 May 10, 2023
46dba71
fixed the nil panic.
VamsiSiddu-7 May 10, 2023
df0ed72
fixed the nfs export.
VamsiSiddu-7 May 10, 2023
3f6b779
fix nfs export error.
VamsiSiddu-7 May 10, 2023
e6a7083
files updated
khareRajshree May 10, 2023
065864b
Merge branch 'nfs-create-volume' of https://github.com/dell/csi-power…
VamsiSiddu-7 May 11, 2023
8fbdd07
updated files.
VamsiSiddu-7 May 11, 2023
a0e9f92
files updated
khareRajshree May 11, 2023
2e5888a
Merge branch 'nfs-create-volume' of https://github.com/dell/csi-power…
VamsiSiddu-7 May 11, 2023
0bc1ba6
removed debug logs.
VamsiSiddu-7 May 11, 2023
f004983
remove debug logs.
VamsiSiddu-7 May 11, 2023
2be908c
Merge branch 'nfs-support' of https://github.com/dell/csi-powerflex i…
VamsiSiddu-7 May 11, 2023
331a1c0
add debug.
VamsiSiddu-7 May 11, 2023
3e3ea6c
add debug.
VamsiSiddu-7 May 11, 2023
c7ce0f5
add debug3.
VamsiSiddu-7 May 11, 2023
1ebf863
fixed a mistake.
VamsiSiddu-7 May 11, 2023
850e772
add debug.
VamsiSiddu-7 May 11, 2023
ffd1a2a
fixed th idempotency.
VamsiSiddu-7 May 12, 2023
1182759
remove debug logs.
VamsiSiddu-7 May 12, 2023
1d65ccd
removed the hardcoded name.
VamsiSiddu-7 May 12, 2023
34b1d73
Merge branch 'nfs-support' of https://github.com/dell/csi-powerflex i…
VamsiSiddu-7 May 12, 2023
0c29740
node publish volume nfs changes.
VamsiSiddu-7 May 13, 2023
a26665b
modified the dockerfile.
VamsiSiddu-7 May 13, 2023
ec50237
fixed the path to send to nfs mount.
VamsiSiddu-7 May 13, 2023
6d1eb26
added fileinterface functionality.
VamsiSiddu-7 May 13, 2023
7f5b27d
fixed a small mistake.
VamsiSiddu-7 May 13, 2023
eaedc7e
update controller.go
VamsiSiddu-7 May 15, 2023
aeb733b
files updated.
VamsiSiddu-7 May 15, 2023
5d91e31
updated nfs storageclass.
VamsiSiddu-7 May 15, 2023
0201314
fixed the debug log.
VamsiSiddu-7 May 15, 2023
b1379f0
updated files.
VamsiSiddu-7 May 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ RUN microdnf update -y && \
kmod \
libaio \
numactl \
nfs-utils \
xfsprogs && \
microdnf clean all
ENTRYPOINT ["/csi-vxflexos.sh"]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/dell/dell-csi-extensions/volumeGroupSnapshot v1.2.2
github.com/dell/gocsi v1.7.0
github.com/dell/gofsutil v1.12.0
github.com/dell/goscaleio v1.10.1-0.20230502150156-f467d3984623
github.com/dell/goscaleio v1.10.1-0.20230515095359-d145e54cb0fe
github.com/fsnotify/fsnotify v1.5.1
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ github.com/dell/gocsi v1.7.0 h1:fMQO2zwAXCaIsUoPCcnnuPMwfQMoaI1/0aqkQVndlxU=
github.com/dell/gocsi v1.7.0/go.mod h1:X/8Ll8qqKAKCenmd1gPJMUvUmgY8cK0LiS8Pck12UaU=
github.com/dell/gofsutil v1.12.0 h1:oo2YHfGFKHvHS1urtqjOIKpaHwcdyqacwKHLXzUg33M=
github.com/dell/gofsutil v1.12.0/go.mod h1:mGMN5grVDtHv2imNw5+gFr2RmCqeyYgBFBldUbHtV78=
github.com/dell/goscaleio v1.10.1-0.20230502150156-f467d3984623 h1:PQwO9B6aI5IF1NI9KjxRZCFm5Mk2YkB21b9SEcytmgI=
github.com/dell/goscaleio v1.10.1-0.20230502150156-f467d3984623/go.mod h1:dMTrHnXSsPus+Kd9mrs0JuyrCndoKvFP/bbEdc21Bi8=
github.com/dell/goscaleio v1.10.1-0.20230515095359-d145e54cb0fe h1:xG7XkoRorM/I9RhbQrFxDOdy5m9TLfYAZhaAX9vH138=
github.com/dell/goscaleio v1.10.1-0.20230515095359-d145e54cb0fe/go.mod h1:dMTrHnXSsPus+Kd9mrs0JuyrCndoKvFP/bbEdc21Bi8=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
Expand Down
2 changes: 1 addition & 1 deletion samples/storageclass/storageclass-nfs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ allowedTopologies:
- matchLabelExpressions:
- key: csi-vxflexos.dellemc.com/<SYSTEM_ID>-nfs # Insert System ID
values:
- csi-vxflexos.dellemc.com
- "true"
112 changes: 112 additions & 0 deletions service/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,118 @@ func publishVolume(
return nil
}

func publishNFS(ctx context.Context, req *csi.NodePublishVolumeRequest, nfsExportUrl string) error {
volCap := req.GetVolumeCapability()

if volCap == nil {
return status.Error(codes.InvalidArgument,
"Volume Capability is required")
}

am := volCap.GetAccessMode()

if am == nil {
return status.Error(codes.InvalidArgument,
"Volume Access Mode is required")
}

mountVol := volCap.GetMount()

if mountVol == nil {
return status.Error(codes.InvalidArgument, "Invalid access type")
}

var mntOptions []string
mntOptions = mountVol.GetMountFlags()
Log.Infof("The mountOptions received are: %s", mntOptions)

target := req.GetTargetPath()
if target == "" {
return status.Error(codes.InvalidArgument,
"Target Path is required")
}

// make sure target is created
_, err := mkdir(target)

if err != nil {
return status.Error(codes.FailedPrecondition, fmt.Sprintf("Could not create '%s': '%s'", target, err.Error()))
}
roFlag := req.GetReadonly()
rwOption := "rw"
if roFlag {
rwOption = "ro"
}

mntOptions = append(mntOptions, rwOption)

fields := map[string]interface{}{
"ID": req.VolumeId,
"TargetPath": target,
"ExportPath": nfsExportUrl,
"AccessMode": am.GetMode(),
}
Log.WithFields(fields).Info("Node publish volume params ")

mnts, err := gofsutil.GetMounts(ctx)
if err != nil {
return status.Errorf(codes.Internal,
"could not reliably determine existing mount status: '%s'",
err.Error())
}

if len(mnts) != 0 {
for _, m := range mnts {
// check for idempotency
//same volume
if m.Device == nfsExportUrl {
if m.Path == target {
//as per specs, T1=T2, P1=P2 - return OK
if contains(m.Opts, rwOption) {
Log.WithFields(fields).Debug(
"mount already in place with same options")
return nil
}
//T1=T2, P1!=P2 - return AlreadyExists
Log.WithFields(fields).Error("Mount point already in use by device with different options")
return status.Error(codes.AlreadyExists, "Mount point already in use by device with different options")
}
//T1!=T2, P1==P2 || P1 != P2 - return FailedPrecondition for single node
if am.GetMode() == csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER ||
am.GetMode() == csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY ||
am.GetMode() == csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER {
Log.WithFields(fields).Error("Mount point already in use for same device")
return status.Error(codes.FailedPrecondition, "Mount point already in use for same device")
}
}
}
}

Log.Infof("The mountOptions being used for mount are: %s", mntOptions)
if err := gofsutil.Mount(context.Background(), nfsExportUrl, target, "nfs", mntOptions...); err != nil {
var count = 0
var errmsg = err.Error()
//Both substring validation is for NFSv3 and NFSv4 errors resp.
for (strings.Contains(strings.ToLower(errmsg), "access denied by server while mounting") || (strings.Contains(strings.ToLower(errmsg), "no such file or directory"))) && count < 5 {
time.Sleep(2 * time.Second)
Log.Infof("Mount re-trial attempt-%d", count)
err = gofsutil.Mount(context.Background(), nfsExportUrl, target, "nfs", mntOptions...)
if err != nil {
errmsg = err.Error()
} else {
break
}
count++
}
if err != nil {
Log.Errorf("%v", err)
return err
}
}
return nil

}

func handlePrivFSMount(
ctx context.Context,
accMode *csi.VolumeCapability_AccessMode,
Expand Down
43 changes: 43 additions & 0 deletions service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ func (s *service) NodePublishVolume(
}
Log.Printf("[NodePublishVolume] csiVolID: %s", csiVolID)

// Check for NFS protocol
fsType := volumeContext[KeyFsType]
isNFS := false
if fsType == "nfs" {
isNFS = true
}

volID := getVolumeIDFromCsiVolumeID(csiVolID)
Log.Printf("[NodePublishVolume] volumeID: %s", volID)

Expand Down Expand Up @@ -170,6 +177,42 @@ func (s *service) NodePublishVolume(

}

if isNFS {
fsID := getFilesystemIDFromCsiVolumeID(csiVolID)

fs, err := s.getFilesystemByID(fsID, systemID)
if err != nil {
if strings.EqualFold(err.Error(), sioGatewayVolumeNotFound) || strings.Contains(err.Error(), "must be a hexadecimal number") {
return nil, status.Error(codes.NotFound,
"filesystem not found")
}
return nil, status.Errorf(codes.Internal,
"failure checking filesystem status before controller publish: %s",
err.Error())
}

client := s.adminClients[systemID]

NFSExport, err := s.getNFSExport(fs, client)

if err != nil {
return nil, err
}

fileInterface, err := s.getFileInterface(systemID, fs, client)
if err != nil {
return nil, err
}

path := fmt.Sprintf("%s:%s", fileInterface.IPAddress, NFSExport.Path)

if err := publishNFS(ctx, req, path); err != nil {
return nil, err
}

return &csi.NodePublishVolumeResponse{}, nil
}

sdcMappedVol, err := s.getSDCMappedVol(volID, systemID, publishGetMappedVolMaxRetry)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
Expand Down
41 changes: 40 additions & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,45 @@ func getFilesystemIDFromCsiVolumeID(csiVolID string) string {
return ""
}

func (s *service) getNFSExport(fs *siotypes.FileSystem, client *goscaleio.Client) (*siotypes.NFSExport, error) {

nfsExportList, err := client.GetNFSExport()

if err != nil {
return nil, err
}

for _, nfsExport := range nfsExportList {
if nfsExport.FileSystemID == fs.ID {
return &nfsExport, nil
}
}

return nil, status.Errorf(codes.NotFound, "NFS Export for the file system: %s not found", fs.Name)

}

func (s *service) getFileInterface(systemID string, fs *siotypes.FileSystem, client *goscaleio.Client) (*siotypes.FileInterface, error) {
system, err := client.FindSystem(systemID, "", "")

if err != nil {
return nil, err
}

nas, err := system.GetNASByIDName(fs.NasServerID, "")

if err != nil {
return nil, err
}

fileInterface, err := system.GetFileInterface(nas.CurrentPreferredIPv4InterfaceID)

if err != nil {
return nil, err
}
return fileInterface, err
}

// getSystemIDFromCsiVolumeId returns PowerFlex volume ID from CSI volume ID
func (s *service) getSystemIDFromCsiVolumeID(csiVolID string) string {
containsHyphen := strings.Contains(csiVolID, "/")
Expand Down Expand Up @@ -952,7 +991,7 @@ func (s *service) exportFilesystem(ctx context.Context, req *csi.ControllerPubli

// Create NFS export if it doesn't exist
if !nfsExportExists {
Log.Debugf("NFS Export does not exist for fs: %s ,proceeding to create NFS Export", fs)
Log.Debugf("NFS Export does not exist for fs: %s ,proceeding to create NFS Export", fs.Name)
resp, err := client.CreateNFSExport(&siotypes.NFSExportCreate{
Name: nfsExportName,
FileSystemID: fs.ID,
Expand Down