mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #89722 from feiskyer/fix-89721
Ensure Azure availability zone is always in lower cases
This commit is contained in:
commit
8ae26096f7
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ package azure
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
|
||||
@ -253,6 +254,7 @@ func TestGetZoneByNodeName(t *testing.T) {
|
||||
scaleSet string
|
||||
vmList []string
|
||||
nodeName string
|
||||
location string
|
||||
zone string
|
||||
faultDomain int32
|
||||
expected string
|
||||
@ -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",
|
||||
@ -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 {
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user