mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 19:57:42 +08:00
fix update volume bugs, and volume type mem bugs
This commit is contained in:
parent
f0306df2cf
commit
e9f5b0f456
@ -1446,49 +1446,27 @@ 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)
|
||||
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
|
||||
}
|
||||
}
|
||||
if req.FileContent != "" {
|
||||
configfile, err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).
|
||||
GetByVolumeName(sid, req.VolumeName)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
configfile.FileContent = req.FileContent
|
||||
if err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).UpdateModel(configfile); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
case dbmodel.ShareFileVolumeType.String(), dbmodel.LocalVolumeType.String():
|
||||
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
|
||||
}
|
||||
v.VolumePath = req.VolumePath
|
||||
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).UpdateModel(v); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
if req.VolumeType == "config-file" {
|
||||
configfile, err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).GetByVolumeName(sid, req.VolumeName)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
v.VolumePath = req.VolumePath
|
||||
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).UpdateModel(v); err != nil {
|
||||
configfile.FileContent = req.FileContent
|
||||
if err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).UpdateModel(configfile); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
default:
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("unsupported volume type")
|
||||
}
|
||||
tx.Commit()
|
||||
return nil
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user