Skip to content

Commit

Permalink
Follow up ingress & gateway e2e tests (#528)
Browse files Browse the repository at this point in the history
* Remove unrelated tests

* Moonray

* update gateway test

* cleanup comments

* update ingress test

* Revert "Remove unrelated tests"

This reverts commit 35b3338.

* Revert "Moonray"

This reverts commit fe32302.

* change retry params ingress test

* angry linter

* update name
  • Loading branch information
louiseschmidtgen authored Jul 8, 2024
1 parent 4c5f449 commit e229caa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 59 deletions.
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")
== "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

0 comments on commit e229caa

Please sign in to comment.