Skip to content

Commit

Permalink
Support disk type check for wait for fist consume types
Browse files Browse the repository at this point in the history
  • Loading branch information
mowangdk committed Jan 29, 2021
1 parent 2fb0220 commit b3b1ced
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions deploy/ack/csi-provisioner-dedicate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ spec:
- "--strict-topology=true"
- "--timeout=150s"
- "--enable-leader-election=true"
- "--extra-create-metadata=true"
- "--leader-election-type=leases"
- "--retry-interval-start=500ms"
- "--v=5"
Expand Down
1 change: 1 addition & 0 deletions deploy/ack/csi-provisioner-managed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ spec:
- "--strict-topology=true"
- "--timeout=150s"
- "--enable-leader-election=true"
- "--extra-create-metadata=true"
- "--leader-election-type=leases"
- "--retry-interval-start=500ms"
- "--v=5"
Expand Down
2 changes: 1 addition & 1 deletion deploy/ack/upgrade/upgrade_csi-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ rules:
verbs: ["patch"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshots/status"]
verbs: ["update"]
Expand Down
1 change: 1 addition & 0 deletions deploy/ack/upgrade/upgrade_csi-provisioner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ spec:
- "--strict-topology=true"
- "--timeout=150s"
- "--enable-leader-election=true"
- "--extra-create-metadata=true"
- "--leader-election-type=leases"
- "--retry-interval-start=500ms"
- "--v=5"
Expand Down
1 change: 1 addition & 0 deletions deploy/disk/disk-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ spec:
- "--strict-topology=true"
- "--timeout=150s"
- "--enable-leader-election=true"
- "--extra-create-metadata=true"
- "--leader-election-type=leases"
- "--retry-interval-start=500ms"
- "--v=5"
Expand Down
33 changes: 30 additions & 3 deletions pkg/disk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"reflect"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -106,6 +107,7 @@ type diskVolumeArgs struct {
PerformanceLevel string `json:"performanceLevel"`
ResourceGroupID string `json:"resourceGroupId"`
DiskTags string `json:"diskTags"`
NodeSelected string `json:"nodeSelected"`
}

// Alicloud disk snapshot parameters
Expand Down Expand Up @@ -181,7 +183,22 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
volSizeBytes := int64(req.GetCapacityRange().GetRequiredBytes())
requestGB := int((volSizeBytes + 1024*1024*1024 - 1) / (1024 * 1024 * 1024))
sharedDisk := diskVol.Type == DiskSharedEfficiency || diskVol.Type == DiskSharedSSD

nodeSupportDiskType := []string{}
if diskVol.NodeSelected != "" {
ctx := context.Background()
client := GlobalConfigVar.ClientSet
nodeInfo, err := client.CoreV1().Nodes().Get(ctx, diskVol.NodeSelected, metav1.GetOptions{})
if err != nil {
return nil, status.Errorf(codes.Internal, "CreateVolume:: get node info error: %v", req.Name)
}
re := regexp.MustCompile(`node.csi.alibabacloud.com/disktype.(.*)`)
for key := range nodeInfo.Labels {
if result := re.FindStringSubmatch(key); len(result) != 0 {
nodeSupportDiskType = append(nodeSupportDiskType, result[1])
}
}
}
log.Infof("CreateVolume:: node support disk types: %v, nodeSelected: %v", nodeSupportDiskType, diskVol.NodeSelected)
// Step 2: Check whether volume is created
GlobalConfigVar.EcsClient = updateEcsClent(GlobalConfigVar.EcsClient)
disks, err := findDiskByName(req.GetName(), diskVol.ResourceGroupID, sharedDisk)
Expand Down Expand Up @@ -266,9 +283,19 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
var volumeResponse *ecs.CreateDiskResponse
var createdDiskType string
provisionerDiskTypes := []string{}
allTypes := deleteEmpty(strings.Split(diskVol.Type, ","))
log.Infof("CreateVolume: all disk types: %+v, len: %v", allTypes, len(allTypes))
for _, dType := range allTypes {
if len(nodeSupportDiskType) != 0 {
provisionerDiskTypes = intersect(nodeSupportDiskType, allTypes)
if len(provisionerDiskTypes) == 0 {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("CreateVolume:: node support type: [%v] is incompatible with provision disk type: [%s]", nodeSupportDiskType, allTypes))
}
} else {
provisionerDiskTypes = allTypes
}

log.Infof("CreateVolume: provision disk types: %+v, len: %v", provisionerDiskTypes, len(provisionerDiskTypes))
for _, dType := range provisionerDiskTypes {
if dType == "" {
continue
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/disk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ const (
DiskUUIDPath = "/host/etc/kubernetes/volumes/disk/uuid"
// ZoneID ...
ZoneID = "zoneId"
// NodeSchedueTag in annotations
NodeSchedueTag = "volume.kubernetes.io/selected-node"
)

var (
Expand Down Expand Up @@ -695,6 +697,7 @@ func getDiskVolumeOptions(req *csi.CreateVolumeRequest) (*diskVolumeArgs, error)
if !ok {
diskVolArgs.PerformanceLevel = PERFORMANCELEVELPL1
}
diskVolArgs.NodeSelected, _ = volOptions[NodeSchedueTag]

// fstype
// https://github.com/kubernetes-csi/external-provisioner/releases/tag/v1.0.1
Expand Down Expand Up @@ -885,3 +888,18 @@ func getDiskCapacity(devicePath string) (float64, error) {
}
return float64(capacity) / GBSIZE, nil
}

func intersect(slice1, slice2 []string) []string {
m := make(map[string]int)
nn := make([]string, 0)
for _, v := range slice1 {
m[v]++
}
for _, v := range slice2 {
times, _ := m[v]
if times == 1 {
nn = append(nn, v)
}
}
return nn
}

0 comments on commit b3b1ced

Please sign in to comment.