Skip to content

Commit cc017a2

Browse files
author
tytv2
committed
[build][enhance] implement zone conversion functions for CreateVolume and NodeGetInfo
1 parent 6348ec4 commit cc017a2

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

pkg/driver/controller.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ func (s *controllerService) CreateVolume(pctx lctx.Context, preq *lcsi.CreateVol
9191
volName := preq.GetName() // get the name of the volume, always in the format of pvc-<random-uuid>
9292
volCap := preq.GetVolumeCapabilities() // get volume capabilities
9393
multiAttach := isMultiAttach(volCap) // check if the volume is multi-attach, true if multi-attach, false otherwise
94-
zone := pickAvailabilityZone(preq.GetAccessibilityRequirements())
95-
if zone == "AZ01" {
96-
zone = "HCM03-1A"
97-
}
94+
zone := lsutil.ConvertVMZoneToPortalZone(pickAvailabilityZone(preq.GetAccessibilityRequirements()))
95+
9896
llog.V(5).InfoS("[INFO] - CreateVolume: zone info", "zone", zone)
9997

10098
// Validate volume size, if volume size is less than the default volume size of cloud provider, set it to the default volume size

pkg/driver/node.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"encoding/json"
66
"fmt"
77
lcsi "github.com/container-storage-interface/spec/lib/go/csi"
8+
lscloud "github.com/vngcloud/vngcloud-blockstorage-csi-driver/pkg/cloud"
9+
lsinternal "github.com/vngcloud/vngcloud-blockstorage-csi-driver/pkg/driver/internal"
10+
lsutil "github.com/vngcloud/vngcloud-blockstorage-csi-driver/pkg/util"
811
lsdkClientV2 "github.com/vngcloud/vngcloud-go-sdk/v2/client"
912
computev2 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/compute/v2"
1013
lsdkPortalSvcV1 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/portal/v1"
@@ -25,9 +28,6 @@ import (
2528
"strconv"
2629
"strings"
2730
"time"
28-
29-
lscloud "github.com/vngcloud/vngcloud-blockstorage-csi-driver/pkg/cloud"
30-
lsinternal "github.com/vngcloud/vngcloud-blockstorage-csi-driver/pkg/driver/internal"
3131
)
3232

3333
type JSONPatch struct {
@@ -556,10 +556,7 @@ func (s *nodeService) NodeGetInfo(_ lctx.Context, _ *lcsi.NodeGetInfoRequest) (*
556556
klog.ErrorS(sdkErr.GetError(), "[ERROR] - GetServerByID: ", "nodeUUID", nodeUUID)
557557
return nil, sdkErr.GetError()
558558
}
559-
zone = server.ZoneId
560-
if zone == "HCM03-1A" {
561-
zone = "AZ01"
562-
}
559+
zone = lsutil.ConvertPortalZoneToVMZone(server.ZoneId)
563560
klog.InfoS("[INFO] - NodeGetInfo: Get the server info successfully",
564561
"nodeId", nodeUUID, "zone", zone, "projectId", projectID)
565562
} else {

pkg/util/util.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,37 @@ func RoundUpGiB(volumeSizeBytes int64) int64 {
6262
func GiBToBytes(volumeSizeGiB int64) int64 {
6363
return volumeSizeGiB * GiB
6464
}
65+
66+
func ConvertPortalZoneToVMZone(zone string) string {
67+
switch zone {
68+
case "HCM03-1A":
69+
return "AZ01"
70+
case "HCM03-1B":
71+
return "HCM-1B"
72+
case "HCM03-1C":
73+
return "HCM-1C"
74+
case "BKK-01":
75+
return "BKK01"
76+
case "HAN-01":
77+
return "az01"
78+
default:
79+
return zone
80+
}
81+
}
82+
83+
func ConvertVMZoneToPortalZone(zone string) string {
84+
switch zone {
85+
case "AZ01":
86+
return "HCM03-1A"
87+
case "HCM-1B":
88+
return "HCM03-1B"
89+
case "HCM-1C":
90+
return "HCM03-1C"
91+
case "BKK01":
92+
return "BKK-01"
93+
case "az01":
94+
return "HAN-01"
95+
default:
96+
return zone
97+
}
98+
}

0 commit comments

Comments
 (0)