From 3b5306d578131146f4f44142de3393ca86d548bf Mon Sep 17 00:00:00 2001 From: Gerard de Leeuw Date: Wed, 15 Mar 2023 18:03:58 +0100 Subject: [PATCH] Take into account that the ClusterIP can be "None" (#114) --- internal/k8s/pod.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/k8s/pod.go b/internal/k8s/pod.go index 55aa040..dff88cc 100644 --- a/internal/k8s/pod.go +++ b/internal/k8s/pod.go @@ -58,18 +58,18 @@ func GetAddressFromService(service *apiv1.Service) string { switch service.Spec.Type { case apiv1.ServiceTypeNodePort: case apiv1.ServiceTypeClusterIP: - return service.Spec.ClusterIP + if service.Spec.ClusterIP != apiv1.ClusterIPNone { + return service.Spec.ClusterIP + } case apiv1.ServiceTypeExternalName: return service.Spec.ExternalName case apiv1.ServiceTypeLoadBalancer: - { - if len(service.Status.LoadBalancer.Ingress) > 0 { - ingress := service.Status.LoadBalancer.Ingress[0] - if ingress.Hostname != "" { - return ingress.Hostname - } - return ingress.IP + if len(service.Status.LoadBalancer.Ingress) > 0 { + ingress := service.Status.LoadBalancer.Ingress[0] + if ingress.Hostname != "" { + return ingress.Hostname } + return ingress.IP } } return ""