Skip to content

Commit

Permalink
Adding support for Availability Zone Affinity (#3470)
Browse files Browse the repository at this point in the history
Fixes #3431

Signed-off-by: Alex Berger <[email protected]>
  • Loading branch information
alex-berger authored Mar 19, 2024
1 parent ac21af6 commit 8296620
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/guide/service/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ for proxy protocol v2 configuration.
```
service.beta.kubernetes.io/aws-load-balancer-attributes: load_balancing.cross_zone.enabled=true
```
- enable client availability zone affinity
```
service.beta.kubernetes.io/aws-load-balancer-attributes: dns_record.client_routing_policy=availability_zone_affinity
```

- <a name="deprecated-attributes"></a>the following annotations are deprecated in v2.3.0 release in favor of [service.beta.kubernetes.io/aws-load-balancer-attributes](#load-balancer-attributes)

Expand Down
28 changes: 22 additions & 6 deletions pkg/service/model_build_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ import (
)

const (
lbAttrsAccessLogsS3Enabled = "access_logs.s3.enabled"
lbAttrsAccessLogsS3Bucket = "access_logs.s3.bucket"
lbAttrsAccessLogsS3Prefix = "access_logs.s3.prefix"
lbAttrsLoadBalancingCrossZoneEnabled = "load_balancing.cross_zone.enabled"
resourceIDLoadBalancer = "LoadBalancer"
minimalAvailableIPAddressCount = int64(8)
lbAttrsAccessLogsS3Enabled = "access_logs.s3.enabled"
lbAttrsAccessLogsS3Bucket = "access_logs.s3.bucket"
lbAttrsAccessLogsS3Prefix = "access_logs.s3.prefix"
lbAttrsLoadBalancingCrossZoneEnabled = "load_balancing.cross_zone.enabled"
lbAttrsLoadBalancingDnsClientRoutingPolicy = "dns_record.client_routing_policy"
availabilityZoneAffinity = "availability_zone_affinity"
partialAvailabilityZoneAffinity = "partial_availability_zone_affinity"
anyAvailabilityZone = "any_availability_zone"
resourceIDLoadBalancer = "LoadBalancer"
minimalAvailableIPAddressCount = int64(8)
)

func (t *defaultModelBuildTask) buildLoadBalancer(ctx context.Context, scheme elbv2model.LoadBalancerScheme) error {
Expand Down Expand Up @@ -437,6 +441,18 @@ func (t *defaultModelBuildTask) getLoadBalancerAttributes() (map[string]string,
if _, err := t.annotationParser.ParseStringMapAnnotation(annotations.SvcLBSuffixLoadBalancerAttributes, &attributes, t.service.Annotations); err != nil {
return nil, err
}
dnsRecordClientRoutingPolicy, exists := attributes[lbAttrsLoadBalancingDnsClientRoutingPolicy]
if exists {
switch dnsRecordClientRoutingPolicy {
case availabilityZoneAffinity:
case partialAvailabilityZoneAffinity:
case anyAvailabilityZone:
default:
return nil, errors.Errorf("invalid dns_record.client_routing_policy set in annotation %s: got '%s' expected one of ['%s', '%s', '%s']",
annotations.SvcLBSuffixLoadBalancerAttributes, dnsRecordClientRoutingPolicy,
anyAvailabilityZone, partialAvailabilityZoneAffinity, availabilityZoneAffinity)
}
}
return attributes, nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/service/model_build_load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Test_defaultModelBuilderTask_buildLBAttributes(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"service.beta.kubernetes.io/aws-load-balancer-attributes": "access_logs.s3.enabled=true,access_logs.s3.bucket=nlb-bucket," +
"access_logs.s3.prefix=bkt-pfx,load_balancing.cross_zone.enabled=true,deletion_protection.enabled=true",
"access_logs.s3.prefix=bkt-pfx,load_balancing.cross_zone.enabled=true,deletion_protection.enabled=true,dns_record.client_routing_policy=availability_zone_affinity",
},
},
},
Expand All @@ -114,6 +114,10 @@ func Test_defaultModelBuilderTask_buildLBAttributes(t *testing.T) {
Key: lbAttrsDeletionProtectionEnabled,
Value: "true",
},
{
Key: lbAttrsLoadBalancingDnsClientRoutingPolicy,
Value: availabilityZoneAffinity,
},
},
},
{
Expand Down

0 comments on commit 8296620

Please sign in to comment.