Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.31] feat: pick region when zonal node pool is in different region #2656

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
return nil, status.Error(codes.InvalidArgument, "After round-up, volume size exceeds the limit specified")
}

if diskParams.Location == "" {
diskParams.Location = d.cloud.Location
}

localCloud := d.cloud
localDiskController := d.diskController

Expand Down Expand Up @@ -188,6 +184,14 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}

diskZone := azureutils.PickAvailabilityZone(req.GetAccessibilityRequirements(), diskParams.Location, topologyKey)
if diskParams.Location == "" {
diskParams.Location = d.cloud.Location
region := azureutils.GetRegionFromAvailabilityZone(diskZone)
if region != "" && region != d.cloud.Location {
klog.V(2).Infof("got a different region from zone %s for disk %s", diskZone, diskParams.DiskName)
diskParams.Location = region
}
}
accessibleTopology := []*csi.Topology{}

if d.enableDiskCapacityCheck {
Expand Down
9 changes: 9 additions & 0 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,15 @@ func IsValidAvailabilityZone(zone, region string) bool {
return strings.HasPrefix(zone, fmt.Sprintf("%s-", region))
}

// GetRegionFromAvailabilityZone returns region from availability zone if it's in format of <region>-<zone-id>
func GetRegionFromAvailabilityZone(zone string) string {
parts := strings.Split(zone, "-")
if len(parts) == 2 {
return parts[0]
}
return ""
}

func IsValidDiskURI(diskURI string) error {
if strings.Index(strings.ToLower(diskURI), "/subscriptions/") != 0 {
return fmt.Errorf("invalid DiskURI: %v, correct format: %v", diskURI, diskURISupportedManaged)
Expand Down
19 changes: 19 additions & 0 deletions pkg/azureutils/azure_disk_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,25 @@ func TestIsAvailabilityZone(t *testing.T) {
}
}

func TestGetRegionFromAvailabilityZone(t *testing.T) {
tests := []struct {
desc string
zone string
expected string
}{
{"empty string", "", ""},
{"invallid zone", "1", ""},
{"valid zone", "eastus-2", "eastus"},
}

for _, test := range tests {
result := GetRegionFromAvailabilityZone(test.zone)
if result != test.expected {
t.Errorf("test [%q] got unexpected result: %v != %v", test.desc, result, test.expected)
}
}
}

func TestIsAzureStackCloud(t *testing.T) {
tests := []struct {
cloud string
Expand Down
Loading