Merge pull request #69263 from brooksgarrett/issue63959

Respect Allocation IDs
This commit is contained in:
Kubernetes Prow Robot 2019-06-23 00:15:54 -07:00 committed by GitHub
commit bf55a99eb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 8 deletions

View File

@ -23,6 +23,7 @@ import (
"io"
"net"
"path"
"sort"
"strconv"
"strings"
"sync"
@ -44,9 +45,9 @@ import (
"github.com/aws/aws-sdk-go/service/kms"
"github.com/aws/aws-sdk-go/service/sts"
"gopkg.in/gcfg.v1"
"k8s.io/api/core/v1"
"k8s.io/klog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -199,6 +200,11 @@ const ServiceAnnotationLoadBalancerHCTimeout = "service.beta.kubernetes.io/aws-l
// service to specify, in seconds, the interval between health checks.
const ServiceAnnotationLoadBalancerHCInterval = "service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval"
// ServiceAnnotationLoadBalancerEIPAllocations is the annotation used on the
// service to specify a comma separated list of EIP allocations to use as
// static IP addresses for the NLB. Only supported on elbv2 (NLB)
const ServiceAnnotationLoadBalancerEIPAllocations = "service.beta.kubernetes.io/aws-load-balancer-eip-allocations"
// Event key when a volume is stuck on attaching state when being attached to a volume
const volumeAttachmentStuck = "VolumeAttachmentStuck"
@ -3281,9 +3287,16 @@ func (c *Cloud) findELBSubnets(internalELB bool) ([]string, error) {
continue
}
var azNames []string
for key := range subnetsByAZ {
azNames = append(azNames, key)
}
sort.Strings(azNames)
var subnetIDs []string
for _, subnet := range subnetsByAZ {
subnetIDs = append(subnetIDs, aws.StringValue(subnet.SubnetId))
for _, key := range azNames {
subnetIDs = append(subnetIDs, aws.StringValue(subnetsByAZ[key].SubnetId))
}
return subnetIDs, nil

View File

@ -136,9 +136,17 @@ func (c *Cloud) ensureLoadBalancerv2(namespacedName types.NamespacedName, loadBa
createRequest.Scheme = aws.String("internal")
}
var allocationIDs []string
if eipList, present := annotations[ServiceAnnotationLoadBalancerEIPAllocations]; present {
allocationIDs = strings.Split(eipList, ",")
if len(allocationIDs) != len(subnetIDs) {
return nil, fmt.Errorf("Error creating load balancer: Must have same number of EIP AllocationIDs (%d) and SubnetIDs (%d)", len(allocationIDs), len(subnetIDs))
}
}
// We are supposed to specify one subnet per AZ.
// TODO: What happens if we have more than one subnet per AZ?
createRequest.SubnetMappings = createSubnetMappings(subnetIDs)
createRequest.SubnetMappings = createSubnetMappings(subnetIDs, allocationIDs)
for k, v := range tags {
createRequest.Tags = append(createRequest.Tags, &elbv2.Tag{
@ -1222,12 +1230,15 @@ func elbListenersAreEqual(actual, expected *elb.Listener) bool {
return true
}
func createSubnetMappings(subnetIDs []string) []*elbv2.SubnetMapping {
func createSubnetMappings(subnetIDs []string, allocationIDs []string) []*elbv2.SubnetMapping {
response := []*elbv2.SubnetMapping{}
for _, id := range subnetIDs {
// Ignore AllocationId for now
response = append(response, &elbv2.SubnetMapping{SubnetId: aws.String(id)})
for index, id := range subnetIDs {
sm := &elbv2.SubnetMapping{SubnetId: aws.String(id)}
if len(allocationIDs) > 0 {
sm.AllocationId = aws.String(allocationIDs[index])
}
response = append(response, sm)
}
return response