From 016ba2800c1270aace790b8b1957a4140ea07407 Mon Sep 17 00:00:00 2001 From: wanggangqiang Date: Mon, 9 Oct 2023 10:39:18 +0800 Subject: [PATCH] add rg support,add tpsc support --- Makefile | 4 +-- pkg/cloud/cloud_manager.go | 2 +- pkg/cloud/mock/mock_cloud_manager.go | 2 +- pkg/cloud/qingcloud_manager.go | 16 +++++----- pkg/cloud/qingcloud_manager_test.go | 2 +- pkg/disk/driver/storageclass.go | 14 +++++++++ pkg/disk/driver/types.go | 30 +++++++++++++++++++ pkg/disk/rpcserver/controllerserver.go | 2 +- .../yunify/qingcloud-sdk-go/service/volume.go | 1 + 9 files changed, 60 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 2d74f4c..da05308 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/pkg/cloud/cloud_manager.go b/pkg/cloud/cloud_manager.go index 212777c..ebc175a 100644 --- a/pkg/cloud/cloud_manager.go +++ b/pkg/cloud/cloud_manager.go @@ -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 diff --git a/pkg/cloud/mock/mock_cloud_manager.go b/pkg/cloud/mock/mock_cloud_manager.go index 9c61df2..101eba6 100644 --- a/pkg/cloud/mock/mock_cloud_manager.go +++ b/pkg/cloud/mock/mock_cloud_manager.go @@ -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 { diff --git a/pkg/cloud/qingcloud_manager.go b/pkg/cloud/qingcloud_manager.go index 8529c88..5948fc9 100644 --- a/pkg/cloud/qingcloud_manager.go +++ b/pkg/cloud/qingcloud_manager.go @@ -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 @@ -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) diff --git a/pkg/cloud/qingcloud_manager_test.go b/pkg/cloud/qingcloud_manager_test.go index 5804338..746f2fd 100644 --- a/pkg/cloud/qingcloud_manager_test.go +++ b/pkg/cloud/qingcloud_manager_test.go @@ -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) diff --git a/pkg/disk/driver/storageclass.go b/pkg/disk/driver/storageclass.go index 732aea2..1fe13c6 100644 --- a/pkg/disk/driver/storageclass.go +++ b/pkg/disk/driver/storageclass.go @@ -35,6 +35,7 @@ const ( StorageClassReplicaName = "replica" StorageClassTagsName = "tags" StorageClassContainerConfID = "containerConfID" + StorageClassRG = "rg" ) type QingStorageClass struct { @@ -46,6 +47,7 @@ type QingStorageClass struct { replica int tags []string containerConfID string + rg string } // NewDefaultQingStorageClassFromType create default qingStorageClass by specified volume type @@ -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) { @@ -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 } } @@ -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 } @@ -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) @@ -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() { diff --git a/pkg/disk/driver/types.go b/pkg/disk/driver/types.go index 14d5ce7..450101c 100644 --- a/pkg/disk/driver/types.go +++ b/pkg/disk/driver/types.go @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -287,6 +311,12 @@ var VolumeTypeAttachConstraint = map[VolumeType][]InstanceType{ }, ThirdPartyStorageType: { StandardInstanceType, + TPSCInstanceType, + TPSC1InstanceType, + TPSC2InstanceType, + TPSC3InstanceType, + TPSC4InstanceType, + TPSC5InstanceType, }, StandardVolumeType: { HighPerformanceInstanceType, diff --git a/pkg/disk/rpcserver/controllerserver.go b/pkg/disk/rpcserver/controllerserver.go index 192aa3c..30ea4d2 100644 --- a/pkg/disk/rpcserver/controllerserver.go +++ b/pkg/disk/rpcserver/controllerserver.go @@ -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()) diff --git a/vendor/github.com/yunify/qingcloud-sdk-go/service/volume.go b/vendor/github.com/yunify/qingcloud-sdk-go/service/volume.go index 41a86f1..a03f2b8 100644 --- a/vendor/github.com/yunify/qingcloud-sdk-go/service/volume.go +++ b/vendor/github.com/yunify/qingcloud-sdk-go/service/volume.go @@ -215,6 +215,7 @@ type CreateVolumesInput struct { // For VolumeType=5/6/7 to set replica count ReplicaCount *int `json:"replica_count" name:"replica_count" location:"params"` ContainerConfID *string `json:"container_conf_id" name:"container_conf_id" location:"params"` + RG *string `json:"rg" name:"rg" location:"params"` } func (v *CreateVolumesInput) Validate() error {