Skip to content

Commit

Permalink
Merge pull request #216 from qiangzii/master
Browse files Browse the repository at this point in the history
add rg support,add tpsc support
  • Loading branch information
liangcd authored Oct 24, 2023
2 parents 7414b10 + 016ba28 commit e097d0e
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
.PHONY: all disk

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

disk: mod
disk:
docker build -t ${DISK_IMAGE_NAME}-builder:${DISK_VERSION} -f deploy/disk/docker/Dockerfile . --target builder

disk-container:
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) (volId string, err error)
CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg 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) (
func (m *MockCloudManager) CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg string) (
volId string, err error) {
exVol, err := m.FindVolumeByName(volName)
if err != nil {
Expand Down
16 changes: 9 additions & 7 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) (
func (qm *qingCloudManager) CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string, rg string) (
newVolId string, err error) {
// 0. Set CreateVolume args
// create volume count
Expand All @@ -319,14 +319,16 @@ func (qm *qingCloudManager) CreateVolume(volName string, requestSize int, replic
VolumeType: &volType,
Zone: &zone,
}
if volType == int(driver.ThirdPartyStorageType) {

if volType == driver.ThirdPartyStorageType.Int() && containerConfID != "" {
input.ContainerConfID = &containerConfID
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",
*input.VolumeName, *input.Size, *input.VolumeType, *input.Zone, *input.Count, *input.Repl, *input.ReplicaCount, *input.ContainerConfID)
} else {
klog.Infof("Call IaaS CreateVolume request name: %s, size: %d GB, type: %d, zone: %s, count: %d, replica: %s, replica_count: %d",
*input.VolumeName, *input.Size, *input.VolumeType, *input.Zone, *input.Count, *input.Repl, *input.ReplicaCount)
}
if (volType == driver.NeonSANVolumeType.Int() || volType == driver.NeonSANHDDVolumeType.Int() || volType == driver.NeonSANRDMAVolumeType.Int()) && rg != "" {
input.RG = &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",
*input.VolumeName, *input.Size, *input.VolumeType, *input.Zone, *input.Count, *input.Repl, *input.ReplicaCount, containerConfID, rg)

// 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 @@ -35,6 +35,7 @@ const (
StorageClassReplicaName = "replica"
StorageClassTagsName = "tags"
StorageClassContainerConfID = "containerConfID"
StorageClassRG = "rg"
)

type QingStorageClass struct {
Expand All @@ -46,6 +47,7 @@ type QingStorageClass struct {
replica int
tags []string
containerConfID string
rg string
}

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

Expand Down Expand Up @@ -149,6 +154,7 @@ func NewQingStorageClassFromMap(opt map[string]string, topology *Topology) (*Qin
_ = sc.setReplica(replica)
sc.setTags(tags)
sc.setContainerConfID(containerConfID)
sc.setRG(rg)
return sc, nil
}

Expand Down Expand Up @@ -183,6 +189,10 @@ func (sc QingStorageClass) GetContainerConfID() string {
return sc.containerConfID
}

func (sc QingStorageClass) GetRG() string {
return sc.rg
}

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

func (sc *QingStorageClass) setRG(rg string) {
sc.rg = rg
}

// FormatVolumeSize transfer to proper volume size
func (sc QingStorageClass) FormatVolumeSizeByte(sizeByte int64) int64 {
if sizeByte <= sc.GetMinSizeByte() {
Expand Down
30 changes: 30 additions & 0 deletions pkg/disk/driver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ const (
EnterpriseCompute3InstanceType InstanceType = 203
PremiumInstanceType InstanceType = 301
NvidiaAmpereG3InstanceType InstanceType = 1003
TPSCInstanceType InstanceType = 400
TPSC1InstanceType InstanceType = 401
TPSC2InstanceType InstanceType = 402
TPSC3InstanceType InstanceType = 403
TPSC4InstanceType InstanceType = 404
TPSC5InstanceType InstanceType = 405
)

var InstanceTypeName = map[InstanceType]string{
Expand All @@ -196,6 +202,12 @@ var InstanceTypeName = map[InstanceType]string{
203: "EnterpriseCompute3",
301: "Premium",
1003: "NvidiaAmpereG3",
400: "TPSC",
401: "TPSC1",
402: "TPSC2",
403: "TPSC3",
404: "TPSC4",
405: "TPSC5",
}

var InstanceTypeValue = map[string]InstanceType{
Expand All @@ -210,6 +222,12 @@ var InstanceTypeValue = map[string]InstanceType{
"EnterpriseCompute3": 203,
"Premium": 301,
"NvidiaAmpereG3": 1003,
"TPSC": 400,
"TPSC1": 401,
"TPSC2": 402,
"TPSC3": 403,
"TPSC4": 404,
"TPSC5": 405,
}

var InstanceTypeAttachPreferred = map[InstanceType]VolumeType{
Expand All @@ -224,6 +242,12 @@ var InstanceTypeAttachPreferred = map[InstanceType]VolumeType{
EnterpriseCompute3InstanceType: SSDEnterpriseVolumeType,
PremiumInstanceType: SSDEnterpriseVolumeType,
NvidiaAmpereG3InstanceType: NeonSANHDDVolumeType,
TPSCInstanceType: ThirdPartyStorageType,
TPSC1InstanceType: ThirdPartyStorageType,
TPSC2InstanceType: ThirdPartyStorageType,
TPSC3InstanceType: ThirdPartyStorageType,
TPSC4InstanceType: ThirdPartyStorageType,
TPSC5InstanceType: ThirdPartyStorageType,
}

var VolumeTypeAttachConstraint = map[VolumeType][]InstanceType{
Expand Down Expand Up @@ -287,6 +311,12 @@ var VolumeTypeAttachConstraint = map[VolumeType][]InstanceType{
},
ThirdPartyStorageType: {
StandardInstanceType,
TPSCInstanceType,
TPSC1InstanceType,
TPSC2InstanceType,
TPSC3InstanceType,
TPSC4InstanceType,
TPSC5InstanceType,
},
StandardVolumeType: {
HighPerformanceInstanceType,
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())
newVolId, err := cs.cloud.CreateVolume(volName, requiredSizeGib, sc.GetReplica(), sc.GetDiskType().Int(), top.GetZone(), sc.GetContainerConfID(), sc.GetRG())
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 e097d0e

Please sign in to comment.