mirror of https://github.com/k3s-io/k3s
Merge pull request #50255 from mattlandis/aws-duplicate-subnets
Automatic merge from submit-queue (batch tested with PRs 50255, 50885) AWS: Arbitrarily choose first (lexicographically) subnet in AZ When there is more than one subnet for an AZ on AWS choose arbitrarily chose the first one lexicographically for consistency. **What this PR does / why we need it**: If two subnets were to be used appear in the same aws az which one is chosen is currently not consistent. This could lead to difficulty in diagnosing issues. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #45983 **Special notes for your reviewer**: **Release note**: ```release-note ```pull/6/head
commit
c573d8192f
|
@ -2487,8 +2487,15 @@ func (c *Cloud) findELBSubnets(internalELB bool) ([]string, error) {
|
|||
continue
|
||||
}
|
||||
|
||||
// TODO: Should this be an error?
|
||||
glog.Warningf("Found multiple subnets in AZ %q; making arbitrary choice between subnets %q and %q", az, *existing.SubnetId, *subnet.SubnetId)
|
||||
// If we have two subnets for the same AZ we arbitrarily choose the one that is first lexicographically.
|
||||
// TODO: Should this be an error.
|
||||
if strings.Compare(*existing.SubnetId, *subnet.SubnetId) > 0 {
|
||||
glog.Warningf("Found multiple subnets in AZ %q; choosing %q between subnets %q and %q", az, *subnet.SubnetId, *existing.SubnetId, *subnet.SubnetId)
|
||||
subnetsByAZ[az] = subnet
|
||||
continue
|
||||
}
|
||||
|
||||
glog.Warningf("Found multiple subnets in AZ %q; choosing %q between subnets %q and %q", az, *existing.SubnetId, *existing.SubnetId, *subnet.SubnetId)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -792,12 +792,18 @@ func TestSubnetIDsinVPC(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// test with 4 subnets from 3 different AZs
|
||||
// add duplicate az subnet
|
||||
// Test with 5 subnets from 3 different AZs.
|
||||
// Add 2 duplicate AZ subnets lexicographically chosen one is the middle element in array to
|
||||
// check that we both choose the correct entry when it comes after and before another element
|
||||
// in the same AZ.
|
||||
subnets[3] = make(map[string]string)
|
||||
subnets[3]["id"] = "subnet-c0000002"
|
||||
subnets[3]["id"] = "subnet-c0000000"
|
||||
subnets[3]["az"] = "af-south-1c"
|
||||
subnets[4] = make(map[string]string)
|
||||
subnets[4]["id"] = "subnet-c0000002"
|
||||
subnets[4]["az"] = "af-south-1c"
|
||||
awsServices.ec2.Subnets = constructSubnets(subnets)
|
||||
routeTables["subnet-c0000000"] = true
|
||||
routeTables["subnet-c0000002"] = true
|
||||
awsServices.ec2.RouteTables = constructRouteTables(routeTables)
|
||||
|
||||
|
@ -812,6 +818,16 @@ func TestSubnetIDsinVPC(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
expected := []*string{aws.String("subnet-a0000001"), aws.String("subnet-b0000001"), aws.String("subnet-c0000000")}
|
||||
for _, s := range result {
|
||||
if !contains(expected, s) {
|
||||
t.Errorf("Unexpected subnet '%s' found", s)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
delete(routeTables, "subnet-c0000002")
|
||||
|
||||
// test with 6 subnets from 3 different AZs
|
||||
// with 3 private subnets
|
||||
subnets[4] = make(map[string]string)
|
||||
|
@ -825,7 +841,7 @@ func TestSubnetIDsinVPC(t *testing.T) {
|
|||
routeTables["subnet-a0000001"] = false
|
||||
routeTables["subnet-b0000001"] = false
|
||||
routeTables["subnet-c0000001"] = false
|
||||
routeTables["subnet-c0000002"] = true
|
||||
routeTables["subnet-c0000000"] = true
|
||||
routeTables["subnet-d0000001"] = true
|
||||
routeTables["subnet-d0000002"] = true
|
||||
awsServices.ec2.RouteTables = constructRouteTables(routeTables)
|
||||
|
@ -840,7 +856,7 @@ func TestSubnetIDsinVPC(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
expected := []*string{aws.String("subnet-c0000002"), aws.String("subnet-d0000001"), aws.String("subnet-d0000002")}
|
||||
expected = []*string{aws.String("subnet-c0000000"), aws.String("subnet-d0000001"), aws.String("subnet-d0000002")}
|
||||
for _, s := range result {
|
||||
if !contains(expected, s) {
|
||||
t.Errorf("Unexpected subnet '%s' found", s)
|
||||
|
|
Loading…
Reference in New Issue