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

Follow up ingress & gateway e2e tests #528

Merged
merged 10 commits into from
Jul 8, 2024
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
69 changes: 31 additions & 38 deletions tests/integration/tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@
LOG = logging.getLogger(__name__)


def get_gateway_service_node_port(p):
gateway_http_port = None
services = json.loads(p.stdout.decode())

gateway_services = [
svc
for svc in services["items"]
if (
svc["metadata"].get("labels").get("projectcontour.io/owning-gateway-name")
== "my-gateway"
or svc["metadata"].get("labels").get("io.cilium.gateway/owning-gateway")
bschimke95 marked this conversation as resolved.
Show resolved Hide resolved
== "my-gateway"
)
]

for svc in gateway_services:
for port in svc["spec"]["ports"]:
if port["port"] == 80:
gateway_http_port = port["nodePort"]
break
if gateway_http_port:
return gateway_http_port
return None


def test_gateway(session_instance: harness.Instance):
manifest = MANIFESTS_DIR / "gateway-test.yaml"
session_instance.exec(
Expand Down Expand Up @@ -40,45 +65,13 @@ def test_gateway(session_instance: harness.Instance):

# Get gateway node port
gateway_http_port = None
util.stubbornly(retries=5, delay_s=2).on(session_instance).until(
lambda p: "my-gateway" in p.stdout.decode()
).exec(["k8s", "kubectl", "get", "service", "-o", "json"])

p = session_instance.exec(
[
"k8s",
"kubectl",
"get",
"service",
"-o=json",
],
capture_output=True,
result = (
util.stubbornly(retries=7, delay_s=3)
.on(session_instance)
.until(lambda p: get_gateway_service_node_port(p) is not None)
.exec(["k8s", "kubectl", "get", "service", "-o", "json"])
)

services = json.loads(p.stdout.decode())

gateway_services = [
svc
for svc in services["items"]
if (
svc["metadata"].get("labels").get("projectcontour.io/owning-gateway-name")
== "my-gateway"
or svc["metadata"].get("labels").get("io.cilium.gateway/owning-gateway")
== "my-gateway"
)
]

assert (
len(gateway_services) > 0
), "No gateway services found that are owned by my-gateway."

for svc in gateway_services:
for port in svc["spec"]["ports"]:
if port["port"] == 80:
gateway_http_port = port["nodePort"]
break
if gateway_http_port:
break
gateway_http_port = get_gateway_service_node_port(result)

assert gateway_http_port is not None, "No ingress nodePort found."

Expand Down
36 changes: 15 additions & 21 deletions tests/integration/tests/test_ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,7 @@
LOG = logging.getLogger(__name__)


def test_ingress(session_instance: List[harness.Instance]):

util.stubbornly(retries=5, delay_s=2).on(session_instance).until(
lambda p: "ingress" in p.stdout.decode()
).exec(["k8s", "kubectl", "get", "service", "-A", "-o", "json"])

p = session_instance.exec(
[
"k8s",
"kubectl",
"get",
"service",
"-A",
"-o=json",
],
capture_output=True,
)

def get_ingress_service_node_port(p):
ingress_http_port = None
services = json.loads(p.stdout.decode())

Expand All @@ -42,15 +25,26 @@ def test_ingress(session_instance: List[harness.Instance]):
)
]

assert len(ingress_services) > 0, "No ingress services found."

for svc in ingress_services:
for port in svc["spec"]["ports"]:
if port["port"] == 80:
ingress_http_port = port["nodePort"]
break
if ingress_http_port:
break
return ingress_http_port
return None


def test_ingress(session_instance: List[harness.Instance]):

result = (
util.stubbornly(retries=7, delay_s=3)
.on(session_instance)
.until(lambda p: get_ingress_service_node_port(p) is not None)
.exec(["k8s", "kubectl", "get", "service", "-A", "-o", "json"])
)

ingress_http_port = get_ingress_service_node_port(result)

assert ingress_http_port is not None, "No ingress nodePort found."

Expand Down
Loading