-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor testsuite to be more aligned with Gateway API
- Loading branch information
Showing
54 changed files
with
1,019 additions
and
1,037 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"""Module containing Proxy related stuff""" | ||
from abc import abstractmethod, ABC | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Optional, Any | ||
|
||
from . import LifecycleObject, asdict | ||
from ..certificates import Certificate | ||
|
||
if TYPE_CHECKING: | ||
from testsuite.openshift.client import OpenShiftClient | ||
from testsuite.openshift.httpbin import Httpbin | ||
|
||
|
||
class Referencable(ABC): | ||
"""Object that can be referenced in Gateway API style""" | ||
|
||
@property | ||
@abstractmethod | ||
def reference(self) -> dict[str, str]: | ||
""" | ||
Returns dict, which can be used as reference in Gateway API Objects. | ||
https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.ParentReference | ||
""" | ||
|
||
|
||
@dataclass | ||
class CustomReference(Referencable): | ||
""" | ||
Manually creates Reference object. | ||
https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io%2fv1beta1.ParentReference | ||
""" | ||
|
||
@property | ||
def reference(self) -> dict[str, Any]: | ||
return asdict(self) | ||
|
||
group: str | ||
kind: str | ||
name: str | ||
namespace: Optional[str] = None | ||
sectionName: Optional[str] = None # pylint: disable=invalid-name | ||
port: Optional[int] = None | ||
|
||
|
||
class Gateway(LifecycleObject, Referencable): | ||
""" | ||
Abstraction layer for a Gateway sitting between end-user and Kuadrant | ||
Simplified: Equals to Gateway Kubernetes object | ||
""" | ||
|
||
@property | ||
@abstractmethod | ||
def openshift(self) -> "OpenShiftClient": | ||
"""Returns OpenShift client for this gateway""" | ||
|
||
@property | ||
@abstractmethod | ||
def service_name(self) -> str: | ||
"""Service name for this gateway""" | ||
|
||
@abstractmethod | ||
def wait_for_ready(self, timeout: int = 90): | ||
"""Waits until the gateway is ready""" | ||
|
||
@abstractmethod | ||
def get_tls_cert(self) -> Optional[Certificate]: | ||
"""Returns TLS cert bound to this Gateway, if the Gateway does not use TLS, returns None""" | ||
|
||
|
||
class GatewayRoute(LifecycleObject, Referencable): | ||
""" | ||
Abstraction layer for *Route objects in Gateway API | ||
Simplified: Equals to HTTPRoute Kubernetes object | ||
""" | ||
|
||
@classmethod | ||
@abstractmethod | ||
def create_instance( | ||
cls, | ||
openshift: "OpenShiftClient", | ||
name, | ||
gateway: Gateway, | ||
labels: dict[str, str] = None, | ||
): | ||
"""Creates new gateway instance""" | ||
|
||
@abstractmethod | ||
def add_hostname(self, hostname: str): | ||
"""Adds hostname to the Route""" | ||
|
||
@abstractmethod | ||
def remove_hostname(self, hostname: str): | ||
"""Remove hostname from the Route""" | ||
|
||
@abstractmethod | ||
def remove_all_hostnames(self): | ||
"""Remove all hostnames from the Route""" | ||
|
||
@abstractmethod | ||
def add_backend(self, backend: "Httpbin", prefix): | ||
"""Adds another backend to the Route, with specific prefix""" | ||
|
||
@abstractmethod | ||
def remove_all_backend(self): | ||
"""Sets match for a specific backend""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Abstract classes for Hostname related stuff""" | ||
from abc import ABC, abstractmethod | ||
|
||
from httpx import Client | ||
|
||
from .gateway import Gateway | ||
|
||
|
||
class Hostname(ABC): | ||
""" | ||
Abstraction layer on top of externally exposed hostname | ||
Simplified: Does not have any equal Kubernetes object. It is a hostname you can send HTTP request to | ||
""" | ||
|
||
@abstractmethod | ||
def client(self, **kwargs) -> Client: | ||
"""Return Httpx client for the requests to this backend""" | ||
|
||
@property | ||
@abstractmethod | ||
def hostname(self) -> str: | ||
"""Returns full hostname in string form associated with this object""" | ||
|
||
|
||
class Exposer: | ||
"""Exposes hostnames to be accessible from outside""" | ||
|
||
@abstractmethod | ||
def expose_hostname(self, name, gateway: Gateway) -> Hostname: | ||
""" | ||
Exposes hostname, so it is accessible from outside | ||
Actual hostname is generated from "name" and is returned in a form of a Hostname object | ||
""" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.