Skip to content

Commit

Permalink
Merge pull request #215 from qiangzii/master
Browse files Browse the repository at this point in the history
add container conf id support for storageclass
  • Loading branch information
yongchuanzhou authored Jun 12, 2023
2 parents c16f035 + 19eade2 commit 7414b10
Show file tree
Hide file tree
Showing 8 changed files with 462 additions and 434 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.3.8
DISK_VERSION=v1.3.9
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) (volId string, err error)
CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string) (volId string, err error)
// DeleteVolume deletes volume by id.
// Return:
// nil: succeed to delete volume
Expand Down
5 changes: 3 additions & 2 deletions pkg/cloud/mock/mock_cloud_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package mock

import (
"fmt"
"time"

"github.com/yunify/qingcloud-csi/pkg/cloud"
"github.com/yunify/qingcloud-csi/pkg/common"
qcconfig "github.com/yunify/qingcloud-sdk-go/config"
qcservice "github.com/yunify/qingcloud-sdk-go/service"
"time"
)

var _ cloud.CloudManager = &MockCloudManager{}
Expand Down Expand Up @@ -159,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) (
func (m *MockCloudManager) CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string) (
volId string, err error) {
exVol, err := m.FindVolumeByName(volName)
if err != nil {
Expand Down
14 changes: 11 additions & 3 deletions pkg/cloud/qingcloud_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"

"github.com/yunify/qingcloud-csi/pkg/disk/driver"
qcclient "github.com/yunify/qingcloud-sdk-go/client"
qcconfig "github.com/yunify/qingcloud-sdk-go/config"
qcservice "github.com/yunify/qingcloud-sdk-go/service"
Expand Down Expand Up @@ -301,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) (
func (qm *qingCloudManager) CreateVolume(volName string, requestSize int, replicas int, volType int, zone string, containerConfID string) (
newVolId string, err error) {
// 0. Set CreateVolume args
// create volume count
Expand All @@ -318,9 +319,16 @@ func (qm *qingCloudManager) CreateVolume(volName string, requestSize int, replic
VolumeType: &volType,
Zone: &zone,
}
if volType == int(driver.ThirdPartyStorageType) {
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)
}

// 1. Create volume
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)
output, err := qm.volumeService.CreateVolumes(input)
if err != nil {
return "", err
Expand Down
7 changes: 4 additions & 3 deletions pkg/cloud/qingcloud_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ limitations under the License.
package cloud

import (
"github.com/yunify/qingcloud-csi/pkg/disk/driver"
"k8s.io/klog"
"os"
"path"
"testing"

"github.com/yunify/qingcloud-csi/pkg/disk/driver"
"k8s.io/klog"
)

const (
Expand Down Expand Up @@ -66,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
42 changes: 28 additions & 14 deletions pkg/disk/driver/storageclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@ import (
)

const (
StorageClassTypeName = "type"
StorageClassMaxSizeName = "maxSize"
StorageClassMinSizeName = "minSize"
StorageClassStepSizeName = "stepSize"
StorageClassFsTypeName = "fsType"
StorageClassReplicaName = "replica"
StorageClassTagsName = "tags"
StorageClassTypeName = "type"
StorageClassMaxSizeName = "maxSize"
StorageClassMinSizeName = "minSize"
StorageClassStepSizeName = "stepSize"
StorageClassFsTypeName = "fsType"
StorageClassReplicaName = "replica"
StorageClassTagsName = "tags"
StorageClassContainerConfID = "containerConfID"
)

type QingStorageClass struct {
diskType VolumeType
maxSize int
minSize int
stepSize int
fsType string
replica int
tags []string
diskType VolumeType
maxSize int
minSize int
stepSize int
fsType string
replica int
tags []string
containerConfID string
}

// NewDefaultQingStorageClassFromType create default qingStorageClass by specified volume type
Expand All @@ -67,6 +69,7 @@ func NewQingStorageClassFromMap(opt map[string]string, topology *Topology) (*Qin
maxSize, minSize, stepSize := -1, -1, -1
fsType := ""
replica := -1
containerConfID := ""
var tags []string
for k, v := range opt {
switch strings.ToLower(k) {
Expand Down Expand Up @@ -113,6 +116,8 @@ func NewQingStorageClassFromMap(opt map[string]string, topology *Topology) (*Qin
if len(v) > 0 {
tags = strings.Split(strings.ReplaceAll(v, " ", ""), ",")
}
case strings.ToLower(StorageClassContainerConfID):
containerConfID = v
}
}

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

Expand Down Expand Up @@ -173,6 +179,10 @@ func (sc QingStorageClass) GetTags() []string {
return sc.tags
}

func (sc QingStorageClass) GetContainerConfID() string {
return sc.containerConfID
}

func (sc *QingStorageClass) setFsType(fs string) error {
if !IsValidFileSystemType(fs) {
return fmt.Errorf("unsupported filesystem type %s", fs)
Expand Down Expand Up @@ -205,6 +215,10 @@ func (sc *QingStorageClass) setTags(tagsStr []string) {
sc.tags = tagsStr
}

func (sc *QingStorageClass) setContainerConfID(containerConfID string) {
sc.containerConfID = containerConfID
}

// FormatVolumeSize transfer to proper volume size
func (sc QingStorageClass) FormatVolumeSizeByte(sizeByte int64) int64 {
if sizeByte <= sc.GetMinSizeByte() {
Expand Down
15 changes: 9 additions & 6 deletions pkg/disk/rpcserver/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ var _ csi.ControllerServer = &ControllerServer{}
// 2. Restore volume from snapshot: CREATE_DELETE_VOLUME and CREATE_DELETE_SNAPSHOT
// 3. Clone volume: CREATE_DELETE_VOLUME and CLONE_VOLUME
// csi.CreateVolumeRequest: name +Required
// capability +Required
//
// capability +Required
func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse,
error) {
funcName := "CreateVolume"
Expand Down Expand Up @@ -161,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())
newVolId, err := cs.cloud.CreateVolume(volName, requiredSizeGib, sc.GetReplica(), sc.GetDiskType().Int(), top.GetZone(), sc.GetContainerConfID())
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 Expand Up @@ -395,9 +396,10 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
}

// csi.ControllerPublishVolumeRequest: volume id + Required
// node id + Required
// volume capability + Required
// readonly + Required (This field is NOT provided when requesting in Kubernetes)
//
// node id + Required
// volume capability + Required
// readonly + Required (This field is NOT provided when requesting in Kubernetes)
func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.
ControllerPublishVolumeResponse, error) {
funcName := "ControllerPublishVolume"
Expand Down Expand Up @@ -585,7 +587,8 @@ func (cs *ControllerServer) ControllerUnpublishVolume(ctx context.Context, req *

// This operation MUST be idempotent
// csi.ValidateVolumeCapabilitiesRequest: volume id + Required
// volume capability + Required
//
// volume capability + Required
func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.
ValidateVolumeCapabilitiesResponse, error) {
funcName := "ValidateVolumeCapabilities"
Expand Down
Loading

0 comments on commit 7414b10

Please sign in to comment.