From a12e2203a0171a12595ed623614b69050abafe69 Mon Sep 17 00:00:00 2001 From: Tomas Repel Date: Mon, 12 Aug 2024 10:38:35 +0200 Subject: [PATCH] Using Hostname if external IP is not found Signed-off-by: Tomas Repel --- testsuite/kubernetes/service.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/testsuite/kubernetes/service.py b/testsuite/kubernetes/service.py index 5ac82a7e..eedc4157 100644 --- a/testsuite/kubernetes/service.py +++ b/testsuite/kubernetes/service.py @@ -3,7 +3,7 @@ from dataclasses import dataclass, asdict from typing import Literal -from openshift_client import timeout +from openshift_client import timeout, Missing from testsuite.kubernetes import KubernetesObject @@ -58,7 +58,15 @@ def external_ip(self): """Returns LoadBalancer IP for this service""" if self.model.spec.type != "LoadBalancer": raise AttributeError("External IP can be only used with LoadBalancer services") - return self.model.status.loadBalancer.ingress[0].ip + ip = self.model.status.loadBalancer.ingress[0].ip + + # If static IP is not used then hostname might be used instead + if ip is Missing: + ip = self.model.status.loadBalancer.ingress[0].hostname + if ip is Missing: + raise AttributeError(f"Neither External IP nor Hostname found in status of {self.model.spec.name} service") + + return ip def delete(self, ignore_not_found=True, cmd_args=None): """Deletes Service, introduces bigger waiting times due to LoadBalancer type"""