Skip to content

Commit

Permalink
support for more volumeName
Browse files Browse the repository at this point in the history
add a new disk tag csi.alibabacloud.com/volume-name
only set diskName if we are sure it is vaild

to comply with CSI spec and pass CSI-sanity test
  • Loading branch information
huww98 committed Jan 26, 2024
1 parent 268dc98 commit cc1bf3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ const (
// the external provisioner sidecar is started with --extra-create-metadata=true and
// thus provides such metadata to the CSI driver.
PVNameTag = "kubernetes.io/created-for/pv/name"

// VolumeNameTag is tag applied to provisioned alibaba cloud disk
// Disk name have many restrictions, so we use this tag to store the original name
VolumeNameTag = "csi.alibabacloud.com/volume-name"
)
10 changes: 9 additions & 1 deletion pkg/disk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/common"
log "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/log"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils"
perrors "github.com/pkg/errors"
Expand Down Expand Up @@ -817,6 +818,10 @@ func requestAndDeleteSnapshot(snapshotID string) (*ecs.DeleteSnapshotResponse, e
return response, nil
}

// Docs say Chinese characters are supported, but the exactly range is not clear.
// So we just assume they are not supported.
var vaildDiskNameRegexp = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9:_-]{1,127}$`)

func createDisk(diskName, snapshotID string, requestGB int, diskVol *diskVolumeArgs, tenantUID string) (string, string, string, error) {
// 需要配置external-provisioner启动参数--extra-create-metadata=true,然后ACK的external-provisioner才会将PVC的Annotations传过来
ecsClient, err := getEcsClientByID("", tenantUID)
Expand All @@ -825,7 +830,9 @@ func createDisk(diskName, snapshotID string, requestGB int, diskVol *diskVolumeA
}

createDiskRequest := ecs.CreateCreateDiskRequest()
createDiskRequest.DiskName = diskName
if vaildDiskNameRegexp.MatchString(diskName) {
createDiskRequest.DiskName = diskName
}
createDiskRequest.Size = requests.NewInteger(requestGB)
createDiskRequest.RegionId = diskVol.RegionID
createDiskRequest.ZoneId = diskVol.ZoneID
Expand All @@ -838,6 +845,7 @@ func createDisk(diskName, snapshotID string, requestGB int, diskVol *diskVolumeA
createDiskRequest.SnapshotId = snapshotID
}
diskTags := getDefaultDiskTags(diskVol)
diskTags = append(diskTags, ecs.CreateDiskTag{Key: common.VolumeNameTag, Value: diskName})
createDiskRequest.Tag = &diskTags

if strings.ToLower(diskVol.MultiAttach) == "true" || strings.ToLower(diskVol.MultiAttach) == "enabled" {
Expand Down
1 change: 1 addition & 0 deletions test/csi-sanity/csi-sanity-disk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ spec:
"--csi.mountdir", "/var/lib/kubelet/csi-sanity/csi-mount",
"--csi.stagingdir", "/var/lib/kubelet/csi-sanity/csi-staging",
"--csi.testvolumeparameters", "/etc/csi-test/volume-parameters.yaml",
"--csi.testnodevolumeattachlimit",
"--ginkgo.junit-report", "/var/lib/kubelet/csi-sanity/report.xml",
"--ginkgo.no-color",
"--ginkgo.v",
Expand Down

0 comments on commit cc1bf3d

Please sign in to comment.