From e8e7e1570fec7bd6a8a08bb395f307d692a7064e Mon Sep 17 00:00:00 2001 From: averevki Date: Fri, 13 Sep 2024 15:15:35 +0200 Subject: [PATCH] Add gateway listeners scaling test Signed-off-by: averevki --- testsuite/gateway/gateway_api/gateway.py | 12 +++ testsuite/kuadrant/policy/dns.py | 9 ++- .../gateway/test_scale_listeners.py | 76 +++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/singlecluster/gateway/test_scale_listeners.py diff --git a/testsuite/gateway/gateway_api/gateway.py b/testsuite/gateway/gateway_api/gateway.py index 9419f792..9b4e9c93 100644 --- a/testsuite/gateway/gateway_api/gateway.py +++ b/testsuite/gateway/gateway_api/gateway.py @@ -54,6 +54,18 @@ def create_instance(cls, cluster: KubernetesClient, name, hostname, labels, tls= return cls(model, context=cluster.context) + def add_listener(self, name: str, hostname: str): + """Adds new listener to the Gateway""" + self.model.spec.listeners.append( + { + "name": name, + "port": 80, + "protocol": "HTTP", + "hostname": hostname, + "allowedRoutes": {"namespaces": {"from": "All"}}, + } + ) + @property def service_name(self) -> str: return f"{self.name()}-istio" diff --git a/testsuite/kuadrant/policy/dns.py b/testsuite/kuadrant/policy/dns.py index 3a4b86d3..b789ccb9 100644 --- a/testsuite/kuadrant/policy/dns.py +++ b/testsuite/kuadrant/policy/dns.py @@ -4,7 +4,7 @@ from testsuite.gateway import Referencable from testsuite.kubernetes.client import KubernetesClient -from testsuite.kuadrant.policy import Policy +from testsuite.kuadrant.policy import Policy, has_condition from testsuite.utils import asdict, check_condition @@ -67,3 +67,10 @@ def create_instance( model["spec"]["loadBalancing"] = asdict(load_balancing) return cls(model, context=cluster.context) + + def wait_for_full_enforced(self): + """Wait for a Policy to be fully Enforced with increased timelimit for DNSPolicy""" + success = self.wait_until( + has_condition("Enforced", "True", "Enforced", "DNSPolicy has been successfully enforced"), timelimit=300 + ) + assert success, f"{self.kind()} did not get fully enforced in time" diff --git a/testsuite/tests/singlecluster/gateway/test_scale_listeners.py b/testsuite/tests/singlecluster/gateway/test_scale_listeners.py new file mode 100644 index 00000000..1670222d --- /dev/null +++ b/testsuite/tests/singlecluster/gateway/test_scale_listeners.py @@ -0,0 +1,76 @@ +"""Create 2 gateways with 64 listeners each and confirm they are reachable with DNSPolicy applied""" + +import pytest + +from testsuite.httpx import KuadrantClient +from testsuite.gateway.gateway_api.route import HTTPRoute +from testsuite.gateway.gateway_api.gateway import KuadrantGateway +from testsuite.kuadrant.policy.dns import DNSPolicy + +pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy] + +MAX_GATEWAY_LISTENERS = 64 + + +@pytest.fixture(scope="module") +def gateway(request, cluster, blame, base_domain, module_label): + """Create first gateway with 64 listeners""" + gw = KuadrantGateway.create_instance(cluster, blame("gw"), f"gw1-api.{base_domain}", {"app": module_label}) + for i in range(1, MAX_GATEWAY_LISTENERS): + gw.add_listener(f"api{i}", f"gw1-api{i}.{base_domain}") + request.addfinalizer(gw.delete) + gw.commit() + gw.wait_for_ready() + return gw + + +@pytest.fixture(scope="module") +def gateway2(request, cluster, blame, base_domain, module_label): + """Create second gateway with 64 listeners""" + gw = KuadrantGateway.create_instance(cluster, blame("gw"), f"gw2-api.{base_domain}", {"app": module_label}) + for i in range(1, MAX_GATEWAY_LISTENERS): + gw.add_listener(f"api{i}", f"gw2-api{i}.{base_domain}") + request.addfinalizer(gw.delete) + gw.commit() + gw.wait_for_ready() + return gw + + +@pytest.fixture(scope="module") +def dns_policy2(blame, gateway2, module_label, dns_provider_secret): + """Create DNSPolicy for second gateway""" + return DNSPolicy.create_instance( + gateway2.cluster, blame("dns"), gateway2, dns_provider_secret, labels={"app": module_label} + ) + + +@pytest.fixture(scope="module") +def routes(request, gateway, gateway2, blame, wildcard_domain, backend, module_label): + """Create routes for both gateways""" + for g in [gateway, gateway2]: + route = HTTPRoute.create_instance(g.cluster, blame("route"), g, {"app": module_label}) + route.add_hostname(wildcard_domain) + route.add_backend(backend) + request.addfinalizer(route.delete) + route.commit() + + +@pytest.fixture(scope="module", autouse=True) +def commit(request, routes, dns_policy, dns_policy2): # pylint: disable=unused-argument + """Commit and wait for DNSPolicies to be fully enforced""" + for component in [dns_policy, dns_policy2]: + request.addfinalizer(component.delete) + component.commit() + component.wait_for_ready() + + +def test_gateway_max_listeners(gateway, gateway2, dns_policy, dns_policy2, base_domain): + """Verify that both gateways are affected by DNSPolicy and their listeners are reachable""" + assert gateway.refresh().is_affected_by(dns_policy) + assert gateway2.refresh().is_affected_by(dns_policy2) + + assert KuadrantClient(base_url=f"http://gw1-api.{base_domain}").get("/get").response.status_code == 200 + assert KuadrantClient(base_url=f"http://gw1-api63.{base_domain}").get("/get").response.status_code == 200 + + assert KuadrantClient(base_url=f"http://gw2-api21.{base_domain}").get("/get").response.status_code == 200 + assert KuadrantClient(base_url=f"http://gw2-api53.{base_domain}").get("/get").response.status_code == 200