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

Automated cherry pick of #89722: Ensure Azure availability zone is always in lower cases #89879

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -490,8 +490,8 @@ func (as *availabilitySet) GetZoneByNodeName(name string) (cloudprovider.Zone, e
}

zone := cloudprovider.Zone{
FailureDomain: failureDomain,
Region: to.String(vm.Location),
FailureDomain: strings.ToLower(failureDomain),
Region: strings.ToLower(to.String(vm.Location)),
}
return zone, nil
}
Expand Down
4 changes: 2 additions & 2 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go
Expand Up @@ -380,8 +380,8 @@ func (ss *scaleSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) {
}

return cloudprovider.Zone{
FailureDomain: failureDomain,
Region: to.String(vm.Location),
FailureDomain: strings.ToLower(failureDomain),
Region: strings.ToLower(to.String(vm.Location)),
}, nil
}

Expand Down
Expand Up @@ -20,6 +20,7 @@ package azure

import (
"fmt"
"strings"
"testing"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
Expand Down Expand Up @@ -253,6 +254,7 @@ func TestGetZoneByNodeName(t *testing.T) {
scaleSet string
vmList []string
nodeName string
location string
zone string
faultDomain int32
expected string
Expand All @@ -275,6 +277,16 @@ func TestGetZoneByNodeName(t *testing.T) {
faultDomain: 3,
expected: "westus-2",
},
{
description: "scaleSet should get availability zone in lower cases",
scaleSet: "ss",
vmList: []string{"vmssee6c2000000", "vmssee6c2000001"},
nodeName: "vmssee6c2000000",
location: "WestUS",
zone: "2",
faultDomain: 3,
expected: "westus-2",
},
{
description: "scaleSet should return error for non-exist nodes",
scaleSet: "ss",
Expand All @@ -286,8 +298,14 @@ func TestGetZoneByNodeName(t *testing.T) {
}

for _, test := range testCases {
ss, err := newTestScaleSet(ctrl, test.scaleSet, test.zone, test.faultDomain, test.vmList)
cloud := GetTestCloud(ctrl)
if test.location != "" {
cloud.Location = test.location
}
setTestVirtualMachineCloud(cloud, test.scaleSet, test.zone, test.faultDomain, test.vmList, "Running")
scaleset, err := newScaleSet(cloud)
assert.NoError(t, err, test.description)
ss := scaleset.(*scaleSet)

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

assert.NoError(t, err, test.description)
assert.Equal(t, test.expected, real.FailureDomain, test.description)
assert.Equal(t, strings.ToLower(cloud.Location), real.Region, test.description)
}
}

Expand Down
Expand Up @@ -78,8 +78,8 @@ func (az *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
}

return cloudprovider.Zone{
FailureDomain: zone,
Region: location,
FailureDomain: strings.ToLower(zone),
Region: strings.ToLower(location),
}, nil
}
// if UseInstanceMetadata is false, get Zone name by calling ARM
Expand Down
Expand Up @@ -88,25 +88,35 @@ func TestGetZone(t *testing.T) {
testcases := []struct {
name string
zone string
location string
faultDomain string
expected string
}{
{
name: "GetZone should get real zone if only node's zone is set",
zone: "1",
location: "eastus",
expected: "eastus-1",
},
{
name: "GetZone should get real zone if both node's zone and FD are set",
zone: "1",
location: "eastus",
faultDomain: "99",
expected: "eastus-1",
},
{
name: "GetZone should get faultDomain if node's zone isn't set",
location: "eastus",
faultDomain: "99",
expected: "99",
},
{
name: "GetZone should get availability zone in lower cases",
location: "EastUS",
zone: "1",
expected: "eastus-1",
},
}

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

mux := http.NewServeMux()
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, fmt.Sprintf(`{"compute":{"zone":"%s", "platformFaultDomain":"%s", "location":"eastus"}}`, test.zone, test.faultDomain))
fmt.Fprint(w, fmt.Sprintf(`{"compute":{"zone":"%s", "platformFaultDomain":"%s", "location":"%s"}}`, test.zone, test.faultDomain, test.location))
}))
go func() {
http.Serve(listener, mux)
Expand Down