diff --git a/app/react/kubernetes/applications/ListView/ApplicationsDatatable/PublishedPorts.tsx b/app/react/kubernetes/applications/ListView/ApplicationsDatatable/PublishedPorts.tsx index 190f94e98..636504978 100644 --- a/app/react/kubernetes/applications/ListView/ApplicationsDatatable/PublishedPorts.tsx +++ b/app/react/kubernetes/applications/ListView/ApplicationsDatatable/PublishedPorts.tsx @@ -7,64 +7,74 @@ import { Icon } from '@@/Icon'; import { Application } from './types'; export function PublishedPorts({ item }: { item: Application }) { - const urls = getPublishedUrls(item); + const urlsWithTypes = getPublishedUrls(item); - if (urls.length === 0) { + if (urlsWithTypes.length === 0) { return null; } return ( -
-
-
Published URL(s)
-
-
- {urls.map((url) => ( -
- - - {url} - -
+
+
Published URL(s)
+
+ {urlsWithTypes.map(({ url, type }) => ( + + + {type && ( + {type} + )} + {url} + ))}
); } +function getClusterIPUrls(services?: Application['Services']) { + return ( + services?.flatMap( + (service) => + (service.spec?.type === 'ClusterIP' && + service.spec?.ports?.map((port) => ({ + url: `${getSchemeFromPort(port.port)}://${service?.spec + ?.clusterIP}:${port.port}`, + type: 'ClusterIP', + }))) || + [] + ) || [] + ); +} + +function getNodePortUrls(services?: Application['Services']) { + return ( + services?.flatMap( + (service) => + (service.spec?.type === 'NodePort' && + service.spec?.ports?.map((port) => ({ + url: `${getSchemeFromPort(port.port)}://${ + window.location.hostname + }:${port.nodePort}`, + type: 'NodePort', + }))) || + [] + ) || [] + ); +} + export function getPublishedUrls(item: Application) { - // Map all ingress rules in published ports to their respective URLs - const ingressUrls = - item.PublishedPorts?.flatMap((pp) => pp.IngressRules) - .filter(({ Host, IP }) => Host || IP) - .map(({ Host, IP, Path, TLS }) => { - const scheme = - TLS && - TLS.filter((tls) => tls.hosts && tls.hosts.includes(Host)).length > 0 - ? 'https' - : 'http'; - return `${scheme}://${Host || IP}${Path}`; - }) || []; + // Get URLs from clusterIP and nodePort services + const clusterIPs = getClusterIPUrls(item.Services); + const nodePortUrls = getNodePortUrls(item.Services); - // Map all load balancer service ports to ip address - const loadBalancerURLs = - (item.LoadBalancerIPAddress && - item.PublishedPorts?.map( - (pp) => - `${getSchemeFromPort(pp.Port)}://${item.LoadBalancerIPAddress}:${ - pp.Port - }` - )) || - []; + // combine all urls + const publishedUrls = [...clusterIPs, ...nodePortUrls]; - // combine ingress urls - const publishedUrls = [...ingressUrls, ...loadBalancerURLs]; - - // Return the first URL - priority given to ingress urls, then services (load balancers) return publishedUrls.length > 0 ? publishedUrls : []; }