Skip to content

Commit

Permalink
Using Hostname if external IP is not found
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Repel <[email protected]>
  • Loading branch information
trepel committed Aug 12, 2024
1 parent 95adf01 commit a12e220
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions testsuite/kubernetes/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit a12e220

Please sign in to comment.