Skip to content

Commit

Permalink
Merge pull request #413 from mowangdk/nas_new_feature_fix
Browse files Browse the repository at this point in the history
Fix nas quota issue
  • Loading branch information
fredkan committed Mar 10, 2021
2 parents 1fa5b4e + 79faaab commit 52fb244
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
16 changes: 13 additions & 3 deletions pkg/nas/controllerserver.go
Expand Up @@ -817,11 +817,21 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
) (*csi.ControllerExpandVolumeResponse, error) {
log.Infof("ControllerExpandVolume: starting to expand nas volume with %v", req)
volSizeBytes := int64(req.GetCapacityRange().GetRequiredBytes())
err := setNasVolumeCapacityWithID(req.VolumeId, volSizeBytes)
pvObj, err := getPvObj(req.VolumeId)
if err != nil {
log.Errorf("ControllerExpandVolume: nas volume(%s) expand error: %s", req.VolumeId, err.Error())
return nil, fmt.Errorf("ControllerExpandVolume: nas volume(%s) expand error: %s", req.VolumeId, err.Error())
}
log.Infof("ControllerExpandVolume: Successful expand nas volume(%s) to size %d", req.VolumeId, volSizeBytes)
if _, ok := pvObj.Spec.CSI.VolumeAttributes["volumeCapacity"]; ok {
err = setNasVolumeCapacityWithID(pvObj, volSizeBytes)
if err != nil {
log.Errorf("ControllerExpandVolume: nas volume(%s) expand error: %s", req.VolumeId, err.Error())
return nil, fmt.Errorf("ControllerExpandVolume: nas volume(%s) expand error: %s", req.VolumeId, err.Error())
}
log.Infof("ControllerExpandVolume: Successful expand nas quota volume(%s) to size %d", req.VolumeId, volSizeBytes)
} else if mountType, ok := pvObj.Spec.CSI.VolumeAttributes["mountType"]; ok && mountType == "losetup" {
log.Infof("ControllerExpandVolume: Successful expand nas losetup volume(%s) to size %d", req.VolumeId, volSizeBytes)
} else {
return nil, fmt.Errorf("ControllerExpandVolume: nas volume(%s) not support expand", req.VolumeId)
}
return &csi.ControllerExpandVolumeResponse{CapacityBytes: volSizeBytes, NodeExpansionRequired: true}, nil
}
15 changes: 7 additions & 8 deletions pkg/nas/utils.go
Expand Up @@ -320,23 +320,22 @@ func setNasVolumeCapacity(nfsServer, nfsPath string, volSizeBytes int64) error {
quotaRequest.RegionId = GetMetaData(RegionTag)
_, err := nasClient.SetDirQuota(quotaRequest)
if err != nil {
if strings.Contains(err.Error(), "The specified FileSystem does not exist.") {
return fmt.Errorf("extreme did not support quota, please change %s to General Purpose NAS", nfsServer)
}
return fmt.Errorf("volume set nas quota with error: %s", err.Error())
}
return nil
}

func setNasVolumeCapacityWithID(volumeID string, volSizeBytes int64) error {
pvObj, err := getPvObj(volumeID)
if err != nil {
return err
}
func setNasVolumeCapacityWithID(pvObj *v1.PersistentVolume, volSizeBytes int64) error {
if pvObj.Spec.CSI == nil {
return fmt.Errorf("Volume %s is not CSI type %v ", volumeID, pvObj)
return fmt.Errorf("Volume %s is not CSI type %v ", pvObj.Name, pvObj)
}

// Check Pv volume parameters
if _, ok := pvObj.Spec.CSI.VolumeAttributes["volumeCapacity"]; !ok {
return fmt.Errorf("Volume %s not contain volumeCapacity parameters, not support expand, PV: %v ", volumeID, pvObj)
if value, ok := pvObj.Spec.CSI.VolumeAttributes["volumeCapacity"]; ok && value == "false" {
return fmt.Errorf("Volume %s not contain volumeCapacity parameters, not support expand, PV: %v ", pvObj.Name, pvObj)
}
nfsServer, nfsPath := "", ""
if value, ok := pvObj.Spec.CSI.VolumeAttributes["server"]; ok {
Expand Down

0 comments on commit 52fb244

Please sign in to comment.