Skip to content

Commit 6c096c5

Browse files
authored
Merge pull request kubernetes#89879 from feiskyer/automated-cherry-pick-of-#89722-upstream-release-1.18
Automated cherry pick of kubernetes#89722: Ensure Azure availability zone is always in lower cases
2 parents a8701ff + f46ea4d commit 6c096c5

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ func (as *availabilitySet) GetZoneByNodeName(name string) (cloudprovider.Zone, e
490490
}
491491

492492
zone := cloudprovider.Zone{
493-
FailureDomain: failureDomain,
494-
Region: to.String(vm.Location),
493+
FailureDomain: strings.ToLower(failureDomain),
494+
Region: strings.ToLower(to.String(vm.Location)),
495495
}
496496
return zone, nil
497497
}

staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ func (ss *scaleSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) {
380380
}
381381

382382
return cloudprovider.Zone{
383-
FailureDomain: failureDomain,
384-
Region: to.String(vm.Location),
383+
FailureDomain: strings.ToLower(failureDomain),
384+
Region: strings.ToLower(to.String(vm.Location)),
385385
}, nil
386386
}
387387

staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package azure
2020

2121
import (
2222
"fmt"
23+
"strings"
2324
"testing"
2425

2526
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
@@ -253,6 +254,7 @@ func TestGetZoneByNodeName(t *testing.T) {
253254
scaleSet string
254255
vmList []string
255256
nodeName string
257+
location string
256258
zone string
257259
faultDomain int32
258260
expected string
@@ -275,6 +277,16 @@ func TestGetZoneByNodeName(t *testing.T) {
275277
faultDomain: 3,
276278
expected: "westus-2",
277279
},
280+
{
281+
description: "scaleSet should get availability zone in lower cases",
282+
scaleSet: "ss",
283+
vmList: []string{"vmssee6c2000000", "vmssee6c2000001"},
284+
nodeName: "vmssee6c2000000",
285+
location: "WestUS",
286+
zone: "2",
287+
faultDomain: 3,
288+
expected: "westus-2",
289+
},
278290
{
279291
description: "scaleSet should return error for non-exist nodes",
280292
scaleSet: "ss",
@@ -286,8 +298,14 @@ func TestGetZoneByNodeName(t *testing.T) {
286298
}
287299

288300
for _, test := range testCases {
289-
ss, err := newTestScaleSet(ctrl, test.scaleSet, test.zone, test.faultDomain, test.vmList)
301+
cloud := GetTestCloud(ctrl)
302+
if test.location != "" {
303+
cloud.Location = test.location
304+
}
305+
setTestVirtualMachineCloud(cloud, test.scaleSet, test.zone, test.faultDomain, test.vmList, "Running")
306+
scaleset, err := newScaleSet(cloud)
290307
assert.NoError(t, err, test.description)
308+
ss := scaleset.(*scaleSet)
291309

292310
real, err := ss.GetZoneByNodeName(test.nodeName)
293311
if test.expectError {
@@ -297,6 +315,7 @@ func TestGetZoneByNodeName(t *testing.T) {
297315

298316
assert.NoError(t, err, test.description)
299317
assert.Equal(t, test.expected, real.FailureDomain, test.description)
318+
assert.Equal(t, strings.ToLower(cloud.Location), real.Region, test.description)
300319
}
301320
}
302321

staging/src/k8s.io/legacy-cloud-providers/azure/azure_zones.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ func (az *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
7878
}
7979

8080
return cloudprovider.Zone{
81-
FailureDomain: zone,
82-
Region: location,
81+
FailureDomain: strings.ToLower(zone),
82+
Region: strings.ToLower(location),
8383
}, nil
8484
}
8585
// if UseInstanceMetadata is false, get Zone name by calling ARM

staging/src/k8s.io/legacy-cloud-providers/azure/azure_zones_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,35 @@ func TestGetZone(t *testing.T) {
8888
testcases := []struct {
8989
name string
9090
zone string
91+
location string
9192
faultDomain string
9293
expected string
9394
}{
9495
{
9596
name: "GetZone should get real zone if only node's zone is set",
9697
zone: "1",
98+
location: "eastus",
9799
expected: "eastus-1",
98100
},
99101
{
100102
name: "GetZone should get real zone if both node's zone and FD are set",
101103
zone: "1",
104+
location: "eastus",
102105
faultDomain: "99",
103106
expected: "eastus-1",
104107
},
105108
{
106109
name: "GetZone should get faultDomain if node's zone isn't set",
110+
location: "eastus",
107111
faultDomain: "99",
108112
expected: "99",
109113
},
114+
{
115+
name: "GetZone should get availability zone in lower cases",
116+
location: "EastUS",
117+
zone: "1",
118+
expected: "eastus-1",
119+
},
110120
}
111121

112122
for _, test := range testcases {
@@ -117,7 +127,7 @@ func TestGetZone(t *testing.T) {
117127

118128
mux := http.NewServeMux()
119129
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
120-
fmt.Fprint(w, fmt.Sprintf(`{"compute":{"zone":"%s", "platformFaultDomain":"%s", "location":"eastus"}}`, test.zone, test.faultDomain))
130+
fmt.Fprint(w, fmt.Sprintf(`{"compute":{"zone":"%s", "platformFaultDomain":"%s", "location":"%s"}}`, test.zone, test.faultDomain, test.location))
121131
}))
122132
go func() {
123133
http.Serve(listener, mux)

0 commit comments

Comments
 (0)