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

Nfs delete FileSystem #212

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
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
66 changes: 66 additions & 0 deletions service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ func (s *service) DeleteVolume(
return nil, status.Error(codes.InvalidArgument,
"volume ID is required")
}

isNFS := strings.Contains(csiVolID, "/")
//ensure no ambiguity if legacy vol
err := s.checkVolumesMap(csiVolID)
if err != nil {
Expand All @@ -735,6 +737,70 @@ func (s *service) DeleteVolume(

}

if isNFS {
// get systemID from req
systemID := s.getSystemIDFromCsiVolumeID(csiVolID)
if systemID == "" {
// use default system
systemID = s.opts.defaultSystemID
}

if systemID == "" {
return nil, status.Error(codes.InvalidArgument,
"systemID is not found in the request and there is no default system")
}

if err := s.requireProbe(ctx, systemID); err != nil {
return nil, err
}

s.logStatistics()
system, err := s.adminClients[systemID].FindSystem(systemID, "", "")
if err != nil {
return nil, err
}
fsID := getFilesystemIDFromCsiVolumeID(csiVolID)
toBeDeletedFS, err := system.GetFileSystemByIDName(fsID, "")
if err != nil {
if strings.Contains(err.Error(), sioGatewayFileSystemNotFound) {
Log.WithFields(logrus.Fields{"id": fsID}).Debug("File System does not exist", fsID)
return &csi.DeleteVolumeResponse{}, nil
}
}

fsName := toBeDeletedFS.Name

// Check if nfs export exists for the File system
client := s.adminClients[systemID]

nfsExport, err := s.getNFSExport(toBeDeletedFS, client)
if err != nil {
if !strings.Contains(err.Error(), "not found") {
return nil, status.Errorf(codes.Internal,
"error getting the NFS Export for the fs: %s", err.Error())
}

} else {
if nfsExport != nil {
return nil, status.Errorf(codes.FailedPrecondition, "Filesystem %s can not be deleted as it has associated NFS Export.", fsID)
}
}

Log.WithFields(logrus.Fields{"name": fsName, "id": fsID}).Info("Deleting FileSystem")
err = system.DeleteFileSystem(fsName)

if err != nil {
if strings.Contains(err.Error(), sioGatewayFileSystemNotFound) {
return &csi.DeleteVolumeResponse{}, nil
} else {
return nil, status.Errorf(codes.Internal,
"error removing filesystem: %s", err.Error())
}
}

return &csi.DeleteVolumeResponse{}, nil
}

// get systemID from req
systemID := s.getSystemIDFromCsiVolumeID(csiVolID)
if systemID == "" {
Expand Down