Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for Availability Zone Affinity #3470

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/guide/service/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,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)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just constants for the possible values for attribute lbAttrsLoadBalancingDnsClientRoutingPolicy, for which I already added as tests in https://github.com/kubernetes-sigs/aws-load-balancer-controller/pull/3470/files#diff-5c328b7b0a8428bb53f5a7b561091d3df4bf46a76538ea0a1590611b584d1196R118.

	partialAvailabilityZoneAffinity          = "partial_availability_zone_affinity"
	anyAvailabilityZone                      = "any_availability_zone"
	resourceIDLoadBalancer                   = "LoadBalancer"

Sorry, but I don't get it what you expect me to do.


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
6 changes: 3 additions & 3 deletions test/e2e/ingress/vanilla_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("vanilla ingress tests", func() {
},
}
annotation := map[string]string{
"alb.ingress.kubernetes.io/scheme": "internet-facing",
"alb.ingress.kubernetes.io/scheme": "internet-facing",
"alb.ingress.kubernetes.io/target-type": "ip",
}
if tf.Options.IPFamily == "IPv6" {
Expand Down Expand Up @@ -173,8 +173,8 @@ var _ = Describe("vanilla ingress tests", func() {
},
}
annotation := map[string]string{
"kubernetes.io/ingress.class": "alb",
"alb.ingress.kubernetes.io/scheme": "internet-facing",
"kubernetes.io/ingress.class": "alb",
"alb.ingress.kubernetes.io/scheme": "internet-facing",
"alb.ingress.kubernetes.io/target-type": "ip",
}
if tf.Options.IPFamily == "IPv6" {
Expand Down