mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(elb): default omitted classic listener instance protocols (#6785)
This commit is contained in:
1 parent
d3c4732b31
commit
80dbdbc0f8
4 files changed
+101
-1
No files matched your search
@@ -0,0 +1,62 @@
|
||||
"""Classic listener defaults survive public readback and identical retries."""
|
||||
|
||||
from contextlib import closing
|
||||
|
||||
import boto3
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"protocol,default", [("HTTP", "HTTP"), ("HTTPS", "HTTP"), ("TCP", "TCP"), ("SSL", "TCP")]
|
||||
)
|
||||
def test_listener_instance_protocol_defaults(
|
||||
aws_config, client_config, ec2_client, iam_client, make_self_signed_certificate, unique_name,
|
||||
protocol, default,
|
||||
):
|
||||
certificate = None
|
||||
created = False
|
||||
with closing(boto3.client("elb", config=client_config, **aws_config)) as elb:
|
||||
try:
|
||||
tls = {}
|
||||
if protocol in ("HTTPS", "SSL"):
|
||||
cert, key = make_self_signed_certificate(unique_name + ".example.test")
|
||||
certificate = iam_client.upload_server_certificate(
|
||||
ServerCertificateName=unique_name, CertificateBody=cert.decode(),
|
||||
PrivateKey=key.decode(),
|
||||
)["ServerCertificateMetadata"]
|
||||
tls["SSLCertificateId"] = certificate["Arn"]
|
||||
listener = {
|
||||
"Protocol": protocol, "LoadBalancerPort": 8443, "InstancePort": 9000, **tls
|
||||
}
|
||||
subnet = ec2_client.describe_subnets()["Subnets"][0]["SubnetId"]
|
||||
elb.create_load_balancer(
|
||||
LoadBalancerName=unique_name, Subnets=[subnet], Listeners=[listener]
|
||||
)
|
||||
created = True
|
||||
added = {**listener, "LoadBalancerPort": 8444, "InstancePort": 9001}
|
||||
explicit = {
|
||||
**listener, "LoadBalancerPort": 8445, "InstancePort": 9002,
|
||||
"InstanceProtocol": "HTTPS" if default == "HTTP" else "SSL",
|
||||
}
|
||||
elb.create_load_balancer_listeners(
|
||||
LoadBalancerName=unique_name, Listeners=[added, explicit]
|
||||
)
|
||||
elb.create_load_balancer_listeners(
|
||||
LoadBalancerName=unique_name, Listeners=[{**added, "InstanceProtocol": default}]
|
||||
)
|
||||
described = elb.describe_load_balancers(LoadBalancerNames=[unique_name])[
|
||||
"LoadBalancerDescriptions"
|
||||
][0]["ListenerDescriptions"]
|
||||
actual = {row["Listener"]["LoadBalancerPort"]: row["Listener"] for row in described}
|
||||
assert actual == {
|
||||
8443: {**listener, "InstanceProtocol": default},
|
||||
8444: {**added, "InstanceProtocol": default},
|
||||
8445: explicit,
|
||||
}
|
||||
finally:
|
||||
try:
|
||||
if created:
|
||||
elb.delete_load_balancer(LoadBalancerName=unique_name)
|
||||
finally:
|
||||
if certificate is not None:
|
||||
iam_client.delete_server_certificate(ServerCertificateName=unique_name)
|
||||
@@ -64,6 +64,10 @@ opened and no traffic is forwarded. Only the control plane and health checking a
|
||||
|
||||
## Behavior Notes
|
||||
|
||||
- An omitted `InstanceProtocol` defaults to `HTTP` for HTTP/HTTPS listeners and
|
||||
`TCP` for TCP/SSL listeners. Explicit backend protocols remain unchanged.
|
||||
Creation, listener additions, persisted readback and identical listener retries
|
||||
use the same effective value.
|
||||
- Load balancer state is persisted through Floci storage, and on startup health checking is
|
||||
restarted for the load balancers of every account.
|
||||
- A new load balancer gets AWS's default health check (`TCP:80`, interval 30, timeout 5,
|
||||
|
||||
@@ -28,7 +28,16 @@ public class ClassicListener {
|
||||
public Integer getLoadBalancerPort() { return loadBalancerPort; }
|
||||
public void setLoadBalancerPort(Integer loadBalancerPort) { this.loadBalancerPort = loadBalancerPort; }
|
||||
|
||||
public String getInstanceProtocol() { return instanceProtocol; }
|
||||
public String getInstanceProtocol() {
|
||||
if (instanceProtocol != null && !instanceProtocol.isEmpty()) {
|
||||
return instanceProtocol;
|
||||
}
|
||||
return switch (protocol) {
|
||||
case "HTTPS" -> "HTTP";
|
||||
case "SSL" -> "TCP";
|
||||
case null, default -> protocol;
|
||||
};
|
||||
}
|
||||
public void setInstanceProtocol(String instanceProtocol) { this.instanceProtocol = instanceProtocol; }
|
||||
|
||||
public Integer getInstancePort() { return instancePort; }
|
||||
|
||||
@@ -95,6 +95,31 @@ class ElbClassicServiceTest {
|
||||
List.of(), List.of("subnet-a"), List.of("sg-1"), null, Map.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
void omittedInstanceProtocolMatchesExplicitDefaultOnListenerRetry() {
|
||||
ClassicListener listener = httpListener();
|
||||
listener.setInstanceProtocol(null);
|
||||
ClassicLoadBalancer lb = service.createLoadBalancer(REGION, "default-listener",
|
||||
List.of(listener), List.of(), List.of("subnet-a"), List.of(), null, Map.of());
|
||||
assertEquals("HTTP", lb.getListeners().getFirst().getInstanceProtocol());
|
||||
service.createLoadBalancerListeners(REGION, "default-listener", List.of(httpListener()));
|
||||
assertEquals(1, lb.getListeners().size());
|
||||
|
||||
ClassicListener tcp = new ClassicListener();
|
||||
tcp.setProtocol("TCP");
|
||||
tcp.setLoadBalancerPort(443);
|
||||
tcp.setInstancePort(9090);
|
||||
service.createLoadBalancerListeners(REGION, "default-listener", List.of(tcp));
|
||||
assertEquals("TCP", lb.getListeners().getLast().getInstanceProtocol());
|
||||
ClassicListener explicit = new ClassicListener();
|
||||
explicit.setProtocol("TCP");
|
||||
explicit.setLoadBalancerPort(443);
|
||||
explicit.setInstancePort(9090);
|
||||
explicit.setInstanceProtocol("TCP");
|
||||
service.createLoadBalancerListeners(REGION, "default-listener", List.of(explicit));
|
||||
assertEquals(2, lb.getListeners().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGivesADnsNameAndTheAwsDefaultHealthCheck() {
|
||||
ClassicLoadBalancer lb = create("my-elb");
|
||||
|
||||
Reference in new issue
Block a user