protected String getExternalServiceURL ( String serviceName , String protocol ) { if ( ! isOnline ( ) ) { getLog ( ) . info ( "Not looking for service " + serviceName + " as we are in offline mode" ) ; return null ; } else { try { KubernetesClient kubernetes = getKubernetes ( ) ; String ns = kubernetes . getNamespace ( ) ; if ( StringUtils . isBlank ( ns ) ) { ns = getNamespace ( ) ; } Service service = kubernetes . services ( ) . inNamespace ( ns ) . withName ( serviceName ) . get ( ) ; return service != null ? ServiceUrlUtil . getServiceURL ( kubernetes , serviceName , ns , protocol , true ) : null ; } catch ( Throwable e ) { Throwable cause = e ; boolean notFound = false ; boolean connectError = false ; Stack < Throwable > stack = unfoldExceptions ( e ) ; while ( ! stack . isEmpty ( ) ) { Throwable t = stack . pop ( ) ; if ( t instanceof ConnectException || "No route to host" . equals ( t . getMessage ( ) ) ) { getLog ( ) . warn ( "Cannot connect to Kubernetes to find URL for service %s : %s" , serviceName , cause . getMessage ( ) ) ; return null ; } else if ( t instanceof IllegalArgumentException || t . getMessage ( ) != null && t . getMessage ( ) . matches ( "^No.*found.*$" ) ) { getLog ( ) . warn ( "%s" , cause . getMessage ( ) ) ; return null ; } ; } getLog ( ) . warn ( "Cannot find URL for service %s : %s" , serviceName , cause . getMessage ( ) ) ; return null ; } } }
Returns the external access to the given service name