update volume type

This commit is contained in:
凡羊羊 2019-12-18 18:24:20 +08:00
parent da628f8b3f
commit ffa13eb67f
7 changed files with 42 additions and 33 deletions

View File

@ -373,7 +373,7 @@ func AddVolume(w http.ResponseWriter, r *http.Request) {
AllowExpansion: avs.Body.AllowExpansion,
}
// TODO VolumeCapacity AccessMode SharePolicy BackupPolicy ReclaimPolicy AllowExpansion 参数的校验
// TODO fanyangyang validate VolumeCapacity AccessMode SharePolicy BackupPolicy ReclaimPolicy AllowExpansion
if !strings.HasPrefix(avs.Body.VolumePath, "/") {
httputil.ReturnError(r, w, 400, "volume path is invalid,must begin with /")

View File

@ -140,7 +140,6 @@ func (vta *VolumeTypeAction) GetAllStorageClasses() ([]*pb.StorageClassDetail, e
// VolumeTypeAction open volme type or close it
func (vta *VolumeTypeAction) VolumeTypeAction(action, volumeTypeID string) error {
// TODO 开启驱动或者关闭驱动,关闭之前需要确定该驱动是否可以因为已经绑定了存储而不能直接关闭
return nil
}

View File

@ -479,24 +479,15 @@ func (b *BackupAPPRestore) restoreMetadata(appSnapshot *AppSnapshot) error {
case dbmodel.LocalVolumeType.String():
a.HostPath = fmt.Sprintf("%s/tenant/%s/service/%s%s", localPath, b.TenantID, a.ServiceID, a.VolumePath)
}
allVolumeTypes, err := db.GetManager().VolumeTypeDao().GetAllVolumeTypes() // TODO fanyangyang 20191218 用一条查询
volumeType, err := db.GetManager().VolumeTypeDao().GetVolumeTypeByType(a.VolumeType)
if err != nil {
logrus.Warnf("get volumeTypes error : %s", err.Error())
// TODO fanyangyang 20191218 return
logrus.Warnf("get volumeType error : %s", err.Error())
return err
}
if allVolumeTypes != nil {
exist := false
for _, vt := range allVolumeTypes {
if vt.VolumeType == a.VolumeType {
exist = true
break
}
}
if !exist {
logrus.Warnf("service[%s] volumeType[%s] do not exists, use default volumeType[%s]", a.ServiceID, a.VolumeType, dbmodel.ShareFileVolumeType.String())
a.VolumeType = dbmodel.ShareFileVolumeType.String()
a.HostPath = fmt.Sprintf("%s/tenant/%s/service/%s%s", sharePath, b.TenantID, a.ServiceID, a.VolumePath)
}
if volumeType == nil {
logrus.Warnf("service[%s] volumeType[%s] do not exists, use default volumeType[%s]", a.ServiceID, a.VolumeType, dbmodel.ShareFileVolumeType.String())
a.VolumeType = dbmodel.ShareFileVolumeType.String()
a.HostPath = fmt.Sprintf("%s/tenant/%s/service/%s%s", sharePath, b.TenantID, a.ServiceID, a.VolumePath)
}
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).AddModel(a); err != nil {
tx.Rollback()

View File

@ -75,7 +75,6 @@ type Storer interface {
RegistPodUpdateListener(string, chan<- *corev1.Pod)
UnRegistPodUpdateListener(string)
InitOneThirdPartService(service *model.TenantServices) error
GetServiceClaims(tenantID, serviceID string) []corev1.PersistentVolumeClaim
}
// EventType type of event associated with an informer
@ -1245,13 +1244,3 @@ func (a *appRuntimeStore) UnRegistPodUpdateListener(name string) {
defer a.podUpdateListenerLock.Unlock()
delete(a.podUpdateListeners, name)
}
func (a *appRuntimeStore) GetServiceClaims(tenantID, serviceID string) []corev1.PersistentVolumeClaim {
// claims := as.GetClaims()// TODO fanyangyang 20191218 临时使用client直接获取PVC后续换成store中获取
claimList, err := a.clientset.CoreV1().PersistentVolumeClaims(tenantID).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("service_id=%s", serviceID)})
if err != nil {
logrus.Errorf("get claims error: %s", err.Error())
return nil
}
return claimList.Items
}

View File

@ -159,8 +159,8 @@ func TestListHPAEvents(t *testing.T) {
func getStoreForTest(t *testing.T) Storer {
ocfg := option.Config{
DBType: "mysql",
MysqlConnectionInfo: "ieZoo9:Maigoed0@tcp(192.168.2.108:3306)/region",
EtcdEndPoints: []string{"http://192.168.2.108:2379"},
MysqlConnectionInfo: "oc6Poh:noot6Mea@tcp(192.168.2.203:3306)/region",
EtcdEndPoints: []string{"http://192.168.2.203:2379"},
EtcdTimeout: 5,
KubeConfig: "/Users/fanyangyang/Documents/company/goodrain/admin.kubeconfig",
LeaderElectionNamespace: "rainbond",

View File

@ -22,7 +22,9 @@ import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/node/nodem/client"
workerutil "github.com/goodrain/rainbond/worker/util"
corev1 "k8s.io/api/core/v1"
)
@ -33,8 +35,14 @@ type OtherVolume struct {
// CreateVolume ceph rbd volume create volume
func (v *OtherVolume) CreateVolume(define *Define) error {
if v.svm.VolumeCapacity <= 0 { // TODO fanyangyang 文件系统是否支持0
return fmt.Errorf("volume capcacity is %d, must be greater than zero", v.svm.VolumeCapacity)
volumeType, err := db.GetManager().VolumeTypeDao().GetVolumeTypeByType(v.svm.VolumeType)
if err != nil {
logrus.Errorf("get volume type by type error: %s", err.Error())
return fmt.Errorf("validate volume capacity error")
}
if err := workerutil.ValidateVolumeCapacity(volumeType.CapacityValidation, v.svm.VolumeCapacity); err != nil {
logrus.Errorf("validate volume capacity[%v] error: %s", v.svm.VolumeCapacity, err.Error())
return err
}
volumeMountName := fmt.Sprintf("manual%d", v.svm.ID)
volumeMountPath := v.svm.VolumePath

View File

@ -64,3 +64,25 @@ func TransStorageClass2RBDVolumeType(sc *storagev1.StorageClass) *dbmodel.Tenant
}
return volumeType
}
// ValidateVolumeCapacity validate volume capacity
func ValidateVolumeCapacity(validation string, capacity int64) error {
validator := make(map[string]interface{})
if err := json.Unmarshal([]byte(validation), &validator); err != nil {
return err
}
if min, ok := validator["min"].(int64); ok {
if capacity < min {
return fmt.Errorf("volume capacity %v less than min value %v", capacity, min)
}
}
if max, ok := validator["max"].(int64); ok {
if capacity > max {
return fmt.Errorf("volume capacity %v more than max value %v", capacity, max)
}
}
return nil
}