From 91b33c3cc42714aca74ad022d83bbb467c7447e9 Mon Sep 17 00:00:00 2001 From: averevki Date: Thu, 2 Nov 2023 14:59:31 +0100 Subject: [PATCH] Add DNSHealthCheckProbe object --- testsuite/openshift/objects/dnspolicy.py | 40 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/testsuite/openshift/objects/dnspolicy.py b/testsuite/openshift/objects/dnspolicy.py index 8d228b16..03b1b14e 100644 --- a/testsuite/openshift/objects/dnspolicy.py +++ b/testsuite/openshift/objects/dnspolicy.py @@ -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""" @@ -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)