- {urls.map((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 : [];
}