Skip to content

Commit

Permalink
Merge pull request #505 from trepel/hostname-if-no-external-ip
Browse files Browse the repository at this point in the history
Using Hostname if external IP is not found
  • Loading branch information
averevki committed Aug 27, 2024
2 parents 8a494cd + a12e220 commit 07e9d84
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 07e9d84

Please sign in to comment.