Skip to content

Commit

Permalink
add placeGroupID support for storageclass
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangzii committed Sep 11, 2024
1 parent ed830ac commit ef44f89
Show file tree
Hide file tree
Showing 8 changed files with 26 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.1-alpha
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
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 ef44f89

Please sign in to comment.