Take into account that the ClusterIP can be "None" (#114)

This commit is contained in:
Gerard de Leeuw 2023-03-15 18:03:58 +01:00 committed by GitHub
parent 9415b5cb00
commit 3b5306d578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 ""