mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
Extend AWS azToRegion method to support Local Zones and other partitions
This commit is contained in:
parent
da18fd14d3
commit
4ae021d5ce
@ -25,6 +25,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -1202,7 +1203,13 @@ func azToRegion(az string) (string, error) {
|
|||||||
if len(az) < 1 {
|
if len(az) < 1 {
|
||||||
return "", fmt.Errorf("invalid (empty) AZ")
|
return "", fmt.Errorf("invalid (empty) AZ")
|
||||||
}
|
}
|
||||||
region := az[:len(az)-1]
|
|
||||||
|
r := regexp.MustCompile(`^([a-zA-Z]+-)+\d+`)
|
||||||
|
region := r.FindString(az)
|
||||||
|
if region == "" {
|
||||||
|
return "", fmt.Errorf("invalid AZ: %s", az)
|
||||||
|
}
|
||||||
|
|
||||||
return region, nil
|
return region, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1982,3 +1982,23 @@ func newMockedFakeAWSServices(id string) *FakeAWSServices {
|
|||||||
s.elb = &MockedFakeELB{FakeELB: s.elb.(*FakeELB)}
|
s.elb = &MockedFakeELB{FakeELB: s.elb.(*FakeELB)}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAzToRegion(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
az string
|
||||||
|
region string
|
||||||
|
}{
|
||||||
|
{"us-west-2a", "us-west-2"},
|
||||||
|
{"us-west-2-lax-1a", "us-west-2"},
|
||||||
|
{"ap-northeast-2a", "ap-northeast-2"},
|
||||||
|
{"us-gov-east-1a", "us-gov-east-1"},
|
||||||
|
{"us-iso-east-1a", "us-iso-east-1"},
|
||||||
|
{"us-isob-east-1a", "us-isob-east-1"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
result, err := azToRegion(testCase.az)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, testCase.region, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user