mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Merge pull request #61064 from johanneswuerbach/nlb-cross-zone
AWS NLB: Support cross-zone load balancing annotation
This commit is contained in:
commit
d7e0d9b45c
@ -313,6 +313,64 @@ func (c *Cloud) ensureLoadBalancerv2(namespacedName types.NamespacedName, loadBa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
desiredLoadBalancerAttributes := map[string]string{}
|
||||||
|
// Default values to ensured a remove annotation reverts back to the default
|
||||||
|
desiredLoadBalancerAttributes["load_balancing.cross_zone.enabled"] = "false"
|
||||||
|
|
||||||
|
// Determine if cross zone load balancing enabled/disabled has been specified
|
||||||
|
crossZoneLoadBalancingEnabledAnnotation := annotations[ServiceAnnotationLoadBalancerCrossZoneLoadBalancingEnabled]
|
||||||
|
if crossZoneLoadBalancingEnabledAnnotation != "" {
|
||||||
|
crossZoneEnabled, err := strconv.ParseBool(crossZoneLoadBalancingEnabledAnnotation)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error parsing service annotation: %s=%s",
|
||||||
|
ServiceAnnotationLoadBalancerCrossZoneLoadBalancingEnabled,
|
||||||
|
crossZoneLoadBalancingEnabledAnnotation,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if crossZoneEnabled {
|
||||||
|
desiredLoadBalancerAttributes["load_balancing.cross_zone.enabled"] = "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whether the ELB was new or existing, sync attributes regardless. This accounts for things
|
||||||
|
// that cannot be specified at the time of creation and can only be modified after the fact,
|
||||||
|
// e.g. idle connection timeout.
|
||||||
|
describeAttributesRequest := &elbv2.DescribeLoadBalancerAttributesInput{
|
||||||
|
LoadBalancerArn: loadBalancer.LoadBalancerArn,
|
||||||
|
}
|
||||||
|
describeAttributesOutput, err := c.elbv2.DescribeLoadBalancerAttributes(describeAttributesRequest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Unable to retrieve load balancer attributes during attribute sync: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
changedAttributes := []*elbv2.LoadBalancerAttribute{}
|
||||||
|
|
||||||
|
// Identify to be changed attributes
|
||||||
|
for _, foundAttribute := range describeAttributesOutput.Attributes {
|
||||||
|
if targetValue, ok := desiredLoadBalancerAttributes[*foundAttribute.Key]; ok {
|
||||||
|
if targetValue != *foundAttribute.Value {
|
||||||
|
changedAttributes = append(changedAttributes, &elbv2.LoadBalancerAttribute{
|
||||||
|
Key: foundAttribute.Key,
|
||||||
|
Value: aws.String(targetValue),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update attributes requiring changes
|
||||||
|
if len(changedAttributes) > 0 {
|
||||||
|
klog.V(2).Infof("Updating load-balancer attributes for %q", loadBalancerName)
|
||||||
|
|
||||||
|
_, err = c.elbv2.ModifyLoadBalancerAttributes(&elbv2.ModifyLoadBalancerAttributesInput{
|
||||||
|
LoadBalancerArn: loadBalancer.LoadBalancerArn,
|
||||||
|
Attributes: changedAttributes,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Unable to update load balancer attributes during attribute sync: %q", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Subnets cannot be modified on NLBs
|
// Subnets cannot be modified on NLBs
|
||||||
if dirty {
|
if dirty {
|
||||||
loadBalancers, err := c.elbv2.DescribeLoadBalancers(
|
loadBalancers, err := c.elbv2.DescribeLoadBalancers(
|
||||||
|
Loading…
Reference in New Issue
Block a user