mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +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{
|
zone := cloudprovider.Zone{
|
||||||
FailureDomain: failureDomain,
|
FailureDomain: strings.ToLower(failureDomain),
|
||||||
Region: to.String(vm.Location),
|
Region: strings.ToLower(to.String(vm.Location)),
|
||||||
}
|
}
|
||||||
return zone, nil
|
return zone, nil
|
||||||
}
|
}
|
||||||
|
@ -380,8 +380,8 @@ func (ss *scaleSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return cloudprovider.Zone{
|
return cloudprovider.Zone{
|
||||||
FailureDomain: failureDomain,
|
FailureDomain: strings.ToLower(failureDomain),
|
||||||
Region: to.String(vm.Location),
|
Region: strings.ToLower(to.String(vm.Location)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ package azure
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
|
"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
|
scaleSet string
|
||||||
vmList []string
|
vmList []string
|
||||||
nodeName string
|
nodeName string
|
||||||
|
location string
|
||||||
zone string
|
zone string
|
||||||
faultDomain int32
|
faultDomain int32
|
||||||
expected string
|
expected string
|
||||||
@ -275,6 +277,16 @@ func TestGetZoneByNodeName(t *testing.T) {
|
|||||||
faultDomain: 3,
|
faultDomain: 3,
|
||||||
expected: "westus-2",
|
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",
|
description: "scaleSet should return error for non-exist nodes",
|
||||||
scaleSet: "ss",
|
scaleSet: "ss",
|
||||||
@ -286,8 +298,14 @@ func TestGetZoneByNodeName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
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)
|
assert.NoError(t, err, test.description)
|
||||||
|
ss := scaleset.(*scaleSet)
|
||||||
|
|
||||||
real, err := ss.GetZoneByNodeName(test.nodeName)
|
real, err := ss.GetZoneByNodeName(test.nodeName)
|
||||||
if test.expectError {
|
if test.expectError {
|
||||||
@ -297,6 +315,7 @@ func TestGetZoneByNodeName(t *testing.T) {
|
|||||||
|
|
||||||
assert.NoError(t, err, test.description)
|
assert.NoError(t, err, test.description)
|
||||||
assert.Equal(t, test.expected, real.FailureDomain, 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{
|
return cloudprovider.Zone{
|
||||||
FailureDomain: zone,
|
FailureDomain: strings.ToLower(zone),
|
||||||
Region: location,
|
Region: strings.ToLower(location),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
// if UseInstanceMetadata is false, get Zone name by calling ARM
|
// if UseInstanceMetadata is false, get Zone name by calling ARM
|
||||||
|
@ -88,25 +88,35 @@ func TestGetZone(t *testing.T) {
|
|||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
zone string
|
zone string
|
||||||
|
location string
|
||||||
faultDomain string
|
faultDomain string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "GetZone should get real zone if only node's zone is set",
|
name: "GetZone should get real zone if only node's zone is set",
|
||||||
zone: "1",
|
zone: "1",
|
||||||
|
location: "eastus",
|
||||||
expected: "eastus-1",
|
expected: "eastus-1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "GetZone should get real zone if both node's zone and FD are set",
|
name: "GetZone should get real zone if both node's zone and FD are set",
|
||||||
zone: "1",
|
zone: "1",
|
||||||
|
location: "eastus",
|
||||||
faultDomain: "99",
|
faultDomain: "99",
|
||||||
expected: "eastus-1",
|
expected: "eastus-1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "GetZone should get faultDomain if node's zone isn't set",
|
name: "GetZone should get faultDomain if node's zone isn't set",
|
||||||
|
location: "eastus",
|
||||||
faultDomain: "99",
|
faultDomain: "99",
|
||||||
expected: "99",
|
expected: "99",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "GetZone should get availability zone in lower cases",
|
||||||
|
location: "EastUS",
|
||||||
|
zone: "1",
|
||||||
|
expected: "eastus-1",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testcases {
|
for _, test := range testcases {
|
||||||
@ -117,7 +127,7 @@ func TestGetZone(t *testing.T) {
|
|||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
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() {
|
go func() {
|
||||||
http.Serve(listener, mux)
|
http.Serve(listener, mux)
|
||||||
|
Loading…
Reference in New Issue
Block a user