Skip to content

Commit

Permalink
added delete filesystem support in deletevolume (#212)
Browse files Browse the repository at this point in the history
Signed-off-by: Kshitija Kakde <Kshitija_Kakde@Dell.com>
  • Loading branch information
ashleyvjoy authored and KshitijaKakde committed Jun 27, 2023
1 parent b75d008 commit 1fe2594
Showing 1 changed file with 66 additions and 0 deletions.
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

0 comments on commit 1fe2594

Please sign in to comment.