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

Add slow_loadbalancers and refactor MockserverBackend #643

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions config/settings.local.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# image: "HTTPBIN_IMAGE"
# mockserver:
# url: "MOCKSERVER_URL"
# image: "MOCKSERVER_IMAGE" # Image to be used for self-deployed Mockserver
# tracing:
# backend: "jaeger" # Tracing backend
# collector_url: "rpc://jaeger-collector.com:4317" # Tracing collector URL (may be internal)
Expand Down Expand Up @@ -48,6 +49,7 @@
# api_url: "https://api.kubernetes2.com"
# token: "KUADRANT_RULEZ"
# kubeconfig_path: "~/.kube/config2"
# slow_loadbalancers: false # For use in Openshift on AWS: If true, causes all Gateways and LoadBalancer Services to wait longer to become ready
# provider_secret: "aws-credentials" # Name of the Secret resource that contains DNS provider credentials
# issuer: # Issuer object for testing TLSPolicy
# name: "selfsigned-cluster-issuer" # Name of Issuer CR
Expand Down
3 changes: 3 additions & 0 deletions config/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ default:
password: "testPassword"
httpbin:
image: "quay.io/trepel/httpbin:jsmadis"
mockserver:
image: "quay.io/mganisin/mockserver:latest"
service_protection:
system_project: "kuadrant-system"
project: "kuadrant"
Expand All @@ -25,6 +27,7 @@ default:
log_level: "debug"
control_plane:
cluster: {}
slow_loadbalancers: false
provider_secret: "aws-credentials"
issuer:
name: "selfsigned-issuer"
Expand Down
14 changes: 6 additions & 8 deletions testsuite/backend/mockserver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Mockserver implementation as Backend"""

from testsuite.config import settings
from testsuite.backend import Backend
from testsuite.kubernetes import Selector
from testsuite.kubernetes.deployment import Deployment, ContainerResources
Expand All @@ -15,15 +16,14 @@ def commit(self):
self.cluster,
self.name,
container_name="mockserver",
image="quay.io/mganisin/mockserver:latest",
image=settings["mockserver"]["image"],
ports={"api": 1080},
selector=Selector(matchLabels=match_labels),
labels={"app": self.label},
resources=ContainerResources(limits_memory="2G"),
lifecycle={"postStart": {"exec": {"command": ["/bin/sh", "init-mockserver"]}}},
)
self.deployment.commit()
self.deployment.wait_for_ready()

self.service = Service.create_instance(
self.cluster,
Expand All @@ -35,9 +35,7 @@ def commit(self):
)
self.service.commit()

def wait_for_ready(self, timeout=300):
"""Waits until Deployment is marked as ready"""
success = self.service.wait_until(
lambda obj: "ip" in self.service.refresh().model.status.loadBalancer.ingress[0], timelimit=timeout
)
assert success, f"Service {self.name} did not get ready in time"
def wait_for_ready(self, timeout=60 * 5):
Copy link
Contributor

@trepel trepel Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do you actually call this method? I can see that you removed the self.deployment.wait_for_ready() call (was on line 26) and moved it into this method but I am struggling to see where this method is actually used.

"""Waits until Deployment and Service is marked as ready"""
self.deployment.wait_for_ready(timeout)
self.service.wait_for_ready(timeout, settings["control_plane"]["slow_loadbalancers"])
4 changes: 4 additions & 0 deletions testsuite/gateway/gateway_api/gateway.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Module containing all gateway classes"""

from time import sleep
from typing import Any

import openshift_client as oc

from testsuite.config import settings
from testsuite.certificates import Certificate
from testsuite.gateway import Gateway, GatewayListener
from testsuite.kubernetes.client import KubernetesClient
Expand Down Expand Up @@ -69,6 +71,8 @@ def wait_for_ready(self, timeout: int = 10 * 60):
"""Waits for the gateway to be ready in the sense of is_ready(self)"""
success = self.wait_until(lambda obj: self.__class__(obj.model).is_ready(), timelimit=timeout)
assert success, "Gateway didn't get ready in time"
if settings["control_plane"]["slow_loadbalancers"]:
sleep(60)

def is_affected_by(self, policy: Policy) -> bool:
"""Returns True, if affected by status is found within the object for the specific policy"""
Expand Down
14 changes: 14 additions & 0 deletions testsuite/kubernetes/service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Service related objects"""

from time import sleep
from dataclasses import dataclass, asdict
from typing import Literal

Expand Down Expand Up @@ -73,3 +74,16 @@ def delete(self, ignore_not_found=True, cmd_args=None):
with timeout(10 * 60):
deleted = super(KubernetesObject, self).delete(ignore_not_found, cmd_args)
return deleted

def wait_for_ready(self, timeout=60 * 5, slow_loadbalancers=False):
"""Waits until LoadBalancer service gets ready."""
if self.model.spec.type != "LoadBalancer":
return
success = self.wait_until(
lambda obj: "ip" in self.refresh().model.status.loadBalancer.ingress[0]
or "hostname" in self.refresh().model.status.loadBalancer.ingress[0],
timelimit=timeout,
)
assert success, f"Service {self.name} did not get ready in time"
if slow_loadbalancers:
sleep(60)