Skip to content

Commit

Permalink
store disk type and performance level as slice
Browse files Browse the repository at this point in the history
  • Loading branch information
huww98 committed Oct 23, 2023
1 parent 5418c04 commit d91820b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
7 changes: 2 additions & 5 deletions pkg/disk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ func getDiskType(diskVol *diskVolumeArgs) ([]string, []string, error) {
}

provisionDiskTypes := []string{}
allTypes := deleteEmpty(strings.Split(diskVol.Type, ","))
allTypes := deleteEmpty(diskVol.Type)
if len(nodeSupportDiskType) != 0 {
provisionDiskTypes = intersect(nodeSupportDiskType, allTypes)
if len(provisionDiskTypes) == 0 {
Expand All @@ -996,10 +996,7 @@ func getDiskType(diskVol *diskVolumeArgs) ([]string, []string, error) {
} else {
provisionDiskTypes = allTypes
}
provisionPerformanceLevel := []string{}
if diskVol.PerformanceLevel != "" {
provisionPerformanceLevel = strings.Split(diskVol.PerformanceLevel, ",")
}
provisionPerformanceLevel := diskVol.PerformanceLevel
return provisionDiskTypes, provisionPerformanceLevel, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/disk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ type controllerServer struct {

// Alicloud disk parameters
type diskVolumeArgs struct {
Type string
Type []string
RegionID string
ZoneID string
FsType string
ReadOnly bool
MultiAttach string
Encrypted bool
KMSKeyID string
PerformanceLevel string
PerformanceLevel []string
ResourceGroupID string
StorageClusterID string
DiskTags map[string]string
Expand Down Expand Up @@ -200,7 +200,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
requestGB = MinimumDiskSizeInGB
volSizeBytes = MinimumDiskSizeInBytes
}
sharedDisk := diskVol.Type == DiskSharedEfficiency || diskVol.Type == DiskSharedSSD
sharedDisk := len(diskVol.Type) == 1 && (diskVol.Type[0] == DiskSharedEfficiency || diskVol.Type[0] == DiskSharedSSD)

diskType, diskID, diskPL, err := createDisk(req.GetName(), snapshotID, requestGB, diskVol, req.Parameters[TenantUserUID])
if err != nil {
Expand Down
29 changes: 14 additions & 15 deletions pkg/disk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ func getDiskVolumeOptions(req *csi.CreateVolumeRequest) (*diskVolumeArgs, error)
// disk Type
diskType, err := validateDiskType(volOptions)
if err != nil {
return nil, fmt.Errorf("Illegal required parameter type: " + diskVolArgs.Type)
return nil, fmt.Errorf("Illegal required parameter type: " + volOptions["type"])
}
diskVolArgs.Type = diskType
pls, err := validateDiskPerformaceLevel(volOptions)
Expand Down Expand Up @@ -963,7 +963,7 @@ func getDiskVolumeOptions(req *csi.CreateVolumeRequest) (*diskVolumeArgs, error)
}

if diskVolArgs.StorageClusterID != "" {
if diskVolArgs.PerformanceLevel == "" {
if len(diskVolArgs.PerformanceLevel) == 0 {
return nil, fmt.Errorf("performaceLevel is necessary when storageClusterID: '%s' specified", diskVolArgs.StorageClusterID)
}
}
Expand Down Expand Up @@ -1019,9 +1019,9 @@ func getDiskVolumeOptions(req *csi.CreateVolumeRequest) (*diskVolumeArgs, error)
return diskVolArgs, nil
}

func validateDiskType(opts map[string]string) (diskType string, err error) {
func validateDiskType(opts map[string]string) (diskType []string, err error) {
if value, ok := opts["type"]; !ok || (ok && value == DiskHighAvail) {
diskType = strings.Join([]string{DiskSSD, DiskEfficiency}, ",")
diskType = []string{DiskSSD, DiskEfficiency}
return
}
if strings.Contains(opts["type"], ",") {
Expand All @@ -1033,34 +1033,33 @@ func validateDiskType(opts map[string]string) (diskType string, err error) {
return diskType, fmt.Errorf("Illegal required parameter type: " + cusType)
}
}
diskType = strings.Join(orderedList, ",")
diskType = orderedList
return
}
for _, t := range AvailableDiskTypes {
if opts["type"] == t {
diskType = t
diskType = []string{t}
}
}
if diskType == "" {
if len(diskType) == 0 {
return diskType, fmt.Errorf("Illegal required parameter type: " + opts["type"])
}
return
}

func validateDiskPerformaceLevel(opts map[string]string) (performaceLevel string, err error) {
func validateDiskPerformaceLevel(opts map[string]string) (performaceLevel []string, err error) {
pl, ok := opts[ESSD_PERFORMANCE_LEVEL]
if !ok || pl == "" {
return "", nil
return
}
log.Infof("validateDiskPerformaceLevel: pl: %v", pl)
if strings.Contains(pl, ",") {
for _, cusPer := range strings.Split(pl, ",") {
if _, ok := CustomDiskPerfermance[cusPer]; !ok {
return "", fmt.Errorf("Illegal performace level type: %s", cusPer)
}
performaceLevel = strings.Split(pl, ",")
for _, cusPer := range performaceLevel {
if _, ok := CustomDiskPerfermance[cusPer]; !ok {
return nil, fmt.Errorf("illegal performace level type: %s", cusPer)
}
}
return pl, nil
return
}

func checkDeviceAvailable(devicePath, volumeID, targetPath string) error {
Expand Down

0 comments on commit d91820b

Please sign in to comment.