fix update volume bugs, and volume type mem bugs

This commit is contained in:
凡羊羊 2019-12-13 11:31:08 +08:00
parent f0306df2cf
commit e9f5b0f456
3 changed files with 21 additions and 44 deletions

View File

@ -1446,11 +1446,7 @@ func (s *ServiceAction) UpdVolume(sid string, req *api_model.UpdVolumeReq) error
tx.Rollback()
}
}()
switch req.VolumeType {
case "config-file":
if req.VolumePath != "" {
v, err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).
GetVolumeByServiceIDAndName(sid, req.VolumeName)
v, err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).GetVolumeByServiceIDAndName(sid, req.VolumeName)
if err != nil {
tx.Rollback()
return err
@ -1460,10 +1456,8 @@ func (s *ServiceAction) UpdVolume(sid string, req *api_model.UpdVolumeReq) error
tx.Rollback()
return err
}
}
if req.FileContent != "" {
configfile, err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).
GetByVolumeName(sid, req.VolumeName)
if req.VolumeType == "config-file" {
configfile, err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).GetByVolumeName(sid, req.VolumeName)
if err != nil {
tx.Rollback()
return err
@ -1474,22 +1468,6 @@ func (s *ServiceAction) UpdVolume(sid string, req *api_model.UpdVolumeReq) error
return err
}
}
case dbmodel.ShareFileVolumeType.String(), dbmodel.LocalVolumeType.String():
v, err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).
GetVolumeByServiceIDAndName(sid, req.VolumeName)
if err != nil {
tx.Rollback()
return err
}
v.VolumePath = req.VolumePath
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).UpdateModel(v); err != nil {
tx.Rollback()
return err
}
default:
tx.Rollback()
return fmt.Errorf("unsupported volume type")
}
tx.Commit()
return nil
}

View File

@ -284,9 +284,9 @@ type V2DelVolumeDependencyStruct struct {
// UpdVolumeReq is a value struct holding request for updating volume.
type UpdVolumeReq struct {
VolumeName string `json:"volume_name" validate:"required"`
VolumeType string `json:"volume_type" validate:"volume_type|required|in:share-file,local,memoryfs,config-file,alicloud-disk"`
VolumeType string `json:"volume_type" validate:"volume_type|required"`
FileContent string `json:"file_content"`
VolumePath string `json:"volume_path"`
VolumePath string `json:"volume_path" validate:"volume_path|required"`
}
// VolumeWithStatusResp volume status

View File

@ -32,21 +32,20 @@ type MemoryFSVolume struct {
// CreateVolume memory fs volume create volume
func (v *MemoryFSVolume) CreateVolume(define *Define) error {
volumeMountName := fmt.Sprintf("mnt%d", v.svm.ID)
volumeMountName := fmt.Sprintf("manual%d", v.svm.ID)
volumeMountPath := v.svm.VolumePath
volumeReadOnly := false
if volumeMountPath != "" {
logrus.Warningf("service[%s]'s mount path is empty, skip it", v.version.ServiceID)
if volumeMountPath == "" {
logrus.Warningf("service[%s]'s mount path is empty, skip create memoryfs", v.version.ServiceID)
return nil
}
for _, m := range define.volumeMounts {
if m.MountPath == volumeMountPath {
logrus.Warningf("found the same mount path: %s, skip it", volumeMountPath)
logrus.Warningf("service[%s]'s found the same mount path: %s, skip create memoryfs", v.version.ServiceID, volumeMountPath)
return nil
}
}
name := fmt.Sprintf("manual%d", v.svm.ID)
vo := corev1.Volume{Name: name}
vo := corev1.Volume{Name: volumeMountName} // !!!: volumeMount name of k8s model must equal to volume name of k8s model
vo.EmptyDir = &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumMemory,
}