Skip to content

Commit

Permalink
Add gateway listeners scaling test
Browse files Browse the repository at this point in the history
Signed-off-by: averevki <[email protected]>
  • Loading branch information
averevki committed Sep 17, 2024
1 parent b52a86c commit e8e7e15
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
12 changes: 12 additions & 0 deletions testsuite/gateway/gateway_api/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion testsuite/kuadrant/policy/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"
76 changes: 76 additions & 0 deletions testsuite/tests/singlecluster/gateway/test_scale_listeners.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e8e7e15

Please sign in to comment.