Skip to content

Commit

Permalink
Merge pull request #218 from qiangzii/master
Browse files Browse the repository at this point in the history
add instance type 1002 support; add placeGroupID support for storageclass
  • Loading branch information
yongchuanzhou authored Sep 13, 2024
2 parents e097d0e + ef44f89 commit 3cd87b7
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.PHONY: all disk

DISK_IMAGE_NAME=csiplugin/csi-qingcloud
DISK_VERSION=v1.4.0
DISK_VERSION=v1.4.1
ROOT_PATH=$(pwd)
PACKAGE_LIST=./cmd/... ./pkg/...

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/cloud_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type VolumeManager interface {
// Return:
// volume id, nil: succeed to create volume and return volume id
// nil, error: failed to create volume
CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg string) (volId string, err error)
CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg string, placeGroupID string) (volId string, err error)
// DeleteVolume deletes volume by id.
// Return:
// nil: succeed to delete volume
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/mock/mock_cloud_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (m *MockCloudManager) FindVolumeByName(volName string) (volInfo *qcservice.
return nil, nil
}

func (m *MockCloudManager) CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg string) (
func (m *MockCloudManager) CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg string, placeGroupPD string) (
volId string, err error) {
exVol, err := m.FindVolumeByName(volName)
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions pkg/cloud/qingcloud_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (cm *qingCloudManager) FindVolumeByName(name string) (volume *qcservice.Vol
// 1. format volume size
// 2. create volume
// 3. wait job
func (qm *qingCloudManager) CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg string) (
func (qm *qingCloudManager) CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg string, placeGroupID string) (
newVolId string, err error) {
// 0. Set CreateVolume args
// create volume count
Expand All @@ -326,9 +326,12 @@ func (qm *qingCloudManager) CreateVolume(volName string, requestSize int, replic
if (volType == driver.NeonSANVolumeType.Int() || volType == driver.NeonSANHDDVolumeType.Int() || volType == driver.NeonSANRDMAVolumeType.Int()) && rg != "" {
input.RG = &rg
}
if placeGroupID != "" {
input.PlaceGroupID = &placeGroupID
}

klog.Infof("Call IaaS CreateVolume request name: %s, size: %d GB, type: %d, zone: %s, count: %d, replica: %s, replica_count: %d, container_conf_id: %s, rg: %s",
*input.VolumeName, *input.Size, *input.VolumeType, *input.Zone, *input.Count, *input.Repl, *input.ReplicaCount, containerConfID, rg)
klog.Infof("Call IaaS CreateVolume request name: %s, size: %d GB, type: %d, zone: %s, count: %d, replica: %s, replica_count: %d, container_conf_id: %s, rg: %s, place_group_id: %s",
*input.VolumeName, *input.Size, *input.VolumeType, *input.Zone, *input.Count, *input.Repl, *input.ReplicaCount, containerConfID, rg, placeGroupID)

// 1. Create volume
output, err := qm.volumeService.CreateVolumes(input)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/qingcloud_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestQingCloudManager_CreateVolume(t *testing.T) {
}

for _, test := range tests {
volId, err := cfg.CreateVolume(test.volName, test.volSize, test.volRepl, test.volType, test.volZone, "", "")
volId, err := cfg.CreateVolume(test.volName, test.volSize, test.volRepl, test.volType, test.volZone, "", "", "")
if err != nil {
if !test.isError {
t.Errorf("testcase %s: expect error %t, but actually error: %s", test.name, test.isError, err)
Expand Down
14 changes: 14 additions & 0 deletions pkg/disk/driver/storageclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
StorageClassTagsName = "tags"
StorageClassContainerConfID = "containerConfID"
StorageClassRG = "rg"
StorageClassPlaceGroupID = "placeGroupID"
)

type QingStorageClass struct {
Expand All @@ -48,6 +49,7 @@ type QingStorageClass struct {
tags []string
containerConfID string
rg string
placeGroupID string
}

// NewDefaultQingStorageClassFromType create default qingStorageClass by specified volume type
Expand All @@ -73,6 +75,7 @@ func NewQingStorageClassFromMap(opt map[string]string, topology *Topology) (*Qin
replica := -1
containerConfID := ""
rg := ""
placeGroupID := ""
var tags []string
for k, v := range opt {
switch strings.ToLower(k) {
Expand Down Expand Up @@ -123,6 +126,8 @@ func NewQingStorageClassFromMap(opt map[string]string, topology *Topology) (*Qin
containerConfID = v
case strings.ToLower(StorageClassRG):
rg = v
case strings.ToLower(StorageClassPlaceGroupID):
placeGroupID = v
}
}

Expand Down Expand Up @@ -155,6 +160,7 @@ func NewQingStorageClassFromMap(opt map[string]string, topology *Topology) (*Qin
sc.setTags(tags)
sc.setContainerConfID(containerConfID)
sc.setRG(rg)
sc.setPlaceGroupID(placeGroupID)
return sc, nil
}

Expand Down Expand Up @@ -193,6 +199,10 @@ func (sc QingStorageClass) GetRG() string {
return sc.rg
}

func (sc QingStorageClass) GetPlaceGroupID() string {
return sc.placeGroupID
}

func (sc *QingStorageClass) setFsType(fs string) error {
if !IsValidFileSystemType(fs) {
return fmt.Errorf("unsupported filesystem type %s", fs)
Expand Down Expand Up @@ -233,6 +243,10 @@ func (sc *QingStorageClass) setRG(rg string) {
sc.rg = rg
}

func (sc *QingStorageClass) setPlaceGroupID(placeGroupID string) {
sc.placeGroupID = placeGroupID
}

// FormatVolumeSize transfer to proper volume size
func (sc QingStorageClass) FormatVolumeSizeByte(sizeByte int64) int64 {
if sizeByte <= sc.GetMinSizeByte() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/disk/driver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const (
TPSC3InstanceType InstanceType = 403
TPSC4InstanceType InstanceType = 404
TPSC5InstanceType InstanceType = 405
AMDFireProS7150InstanceType InstanceType = 1002
)

var InstanceTypeName = map[InstanceType]string{
Expand All @@ -208,6 +209,7 @@ var InstanceTypeName = map[InstanceType]string{
403: "TPSC3",
404: "TPSC4",
405: "TPSC5",
1002: "AMDFireProS7150",
}

var InstanceTypeValue = map[string]InstanceType{
Expand All @@ -228,6 +230,7 @@ var InstanceTypeValue = map[string]InstanceType{
"TPSC3": 403,
"TPSC4": 404,
"TPSC5": 405,
"AMDFireProS7150": 1002,
}

var InstanceTypeAttachPreferred = map[InstanceType]VolumeType{
Expand All @@ -248,6 +251,7 @@ var InstanceTypeAttachPreferred = map[InstanceType]VolumeType{
TPSC3InstanceType: ThirdPartyStorageType,
TPSC4InstanceType: ThirdPartyStorageType,
TPSC5InstanceType: ThirdPartyStorageType,
AMDFireProS7150InstanceType: NeonSANHDDVolumeType,
}

var VolumeTypeAttachConstraint = map[VolumeType][]InstanceType{
Expand All @@ -263,6 +267,7 @@ var VolumeTypeAttachConstraint = map[VolumeType][]InstanceType{
Enterprise2InstanceType,
PremiumInstanceType,
NvidiaAmpereG3InstanceType,
AMDFireProS7150InstanceType,
},
SuperHighPerformanceVolumeType: {
SuperHighPerformanceInstanceType,
Expand All @@ -282,6 +287,7 @@ var VolumeTypeAttachConstraint = map[VolumeType][]InstanceType{
EnterpriseCompute3InstanceType,
PremiumInstanceType,
NvidiaAmpereG3InstanceType,
AMDFireProS7150InstanceType,
},
NeonSANHDDVolumeType: {
HighPerformanceInstanceType,
Expand All @@ -295,6 +301,7 @@ var VolumeTypeAttachConstraint = map[VolumeType][]InstanceType{
EnterpriseCompute3InstanceType,
PremiumInstanceType,
NvidiaAmpereG3InstanceType,
AMDFireProS7150InstanceType,
},
NeonSANRDMAVolumeType: {
HighPerformanceInstanceType,
Expand All @@ -308,6 +315,7 @@ var VolumeTypeAttachConstraint = map[VolumeType][]InstanceType{
EnterpriseCompute3InstanceType,
PremiumInstanceType,
NvidiaAmpereG3InstanceType,
AMDFireProS7150InstanceType,
},
ThirdPartyStorageType: {
StandardInstanceType,
Expand Down
2 changes: 1 addition & 1 deletion pkg/disk/rpcserver/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
requiredSizeGib := common.ByteCeilToGib(requiredSizeByte)
klog.Infof("%s: Creating empty volume %s with %d Gib in zone %s...", hash, volName, requiredSizeGib,
top.GetZone())
newVolId, err := cs.cloud.CreateVolume(volName, requiredSizeGib, sc.GetReplica(), sc.GetDiskType().Int(), top.GetZone(), sc.GetContainerConfID(), sc.GetRG())
newVolId, err := cs.cloud.CreateVolume(volName, requiredSizeGib, sc.GetReplica(), sc.GetDiskType().Int(), top.GetZone(), sc.GetContainerConfID(), sc.GetRG(), sc.GetPlaceGroupID())
if err != nil {
klog.Errorf("%s: Failed to create volume %s, error: %v", hash, volName, err)
return nil, status.Error(codes.Internal, err.Error())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3cd87b7

Please sign in to comment.