Skip to content

Commit

Permalink
Add DNSHealthCheckProbe object
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Nov 2, 2023
1 parent 98dfb84 commit 91b33c3
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions testsuite/openshift/objects/dnspolicy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
"""Module for DNSPolicy related classes"""
from dataclasses import dataclass
from typing import Optional, Literal

import openshift as oc

from testsuite.objects import asdict
from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift.objects import OpenShiftObject
from testsuite.openshift.objects.gateway_api import Referencable


@dataclass
class HealthCheck: # pylint: disable=invalid-name
"""Object representing DNSPolicy health check specification"""

allowInsecureCertificates: Optional[bool] = None
endpoint: Optional[str] = None
expectedResponses: Optional[list[int]] = None
failureThreshold: Optional[int] = None
interval: Optional[str] = None
port: Optional[int] = None
protocol: Literal["http", "https"] = "https"


class DNSHealthCheckProbe(OpenShiftObject):
"""DNSHealthCheckProbe object"""

def is_healthy(self) -> bool:
"""Returns True if DNSHealthCheckProbe endpoint is healthy"""
return self.model.status.healthy


class DNSPolicy(OpenShiftObject):
"""DNSPolicy object"""

Expand All @@ -13,15 +40,24 @@ def create_instance(
openshift: OpenShiftClient,
name: str,
parent: Referencable,
healthCheck: HealthCheck = None,
labels: dict[str, str] = None,
):
): # pylint: disable=invalid-name
"""Creates new instance of DNSPolicy"""

model = {
model: dict = {
"apiVersion": "kuadrant.io/v1alpha1",
"kind": "DNSPolicy",
"metadata": {"name": name, "labels": labels},
"spec": {"targetRef": parent.reference},
}

if healthCheck:
model["spec"]["healthCheck"] = asdict(healthCheck)

return cls(model, context=openshift.context)

def get_dns_health_probe(self) -> oc.APIObject:
"""Returns DNSHealthCheckProbe object for the created DNSPolicy"""
dns_probe = oc.selector("DNSHealthCheckProbe", labels={"kuadrant.io/dnspolicy": self.name()}).object()
return DNSHealthCheckProbe(dns_probe.model, context=self.context)

0 comments on commit 91b33c3

Please sign in to comment.