fix(ui): bring back k8s applications page row expand published urls [r8s-145] (#356)
parent
c80cc6e268
commit
7d18c22aa1
|
@ -7,64 +7,74 @@ import { Icon } from '@@/Icon';
|
||||||
import { Application } from './types';
|
import { Application } from './types';
|
||||||
|
|
||||||
export function PublishedPorts({ item }: { item: Application }) {
|
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 null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="published-url-container">
|
<div className="published-url-container pl-10 flex">
|
||||||
<div>
|
<div className="text-muted mr-12">Published URL(s)</div>
|
||||||
<div className="text-muted"> Published URL(s) </div>
|
<div className="flex flex-col">
|
||||||
</div>
|
{urlsWithTypes.map(({ url, type }) => (
|
||||||
<div>
|
<a
|
||||||
{urls.map((url) => (
|
key={url}
|
||||||
<div key={url}>
|
href={url}
|
||||||
<a
|
target="_blank"
|
||||||
href={url}
|
className="publish-url-link vertical-center mb-1"
|
||||||
target="_blank"
|
rel="noreferrer"
|
||||||
className="publish-url-link vertical-center"
|
>
|
||||||
rel="noreferrer"
|
<Icon icon={ExternalLinkIcon} />
|
||||||
>
|
{type && (
|
||||||
<Icon icon={ExternalLinkIcon} />
|
<span className="text-muted w-24 inline-block">{type}</span>
|
||||||
{url}
|
)}
|
||||||
</a>
|
<span>{url}</span>
|
||||||
</div>
|
</a>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
export function getPublishedUrls(item: Application) {
|
||||||
// Map all ingress rules in published ports to their respective URLs
|
// Get URLs from clusterIP and nodePort services
|
||||||
const ingressUrls =
|
const clusterIPs = getClusterIPUrls(item.Services);
|
||||||
item.PublishedPorts?.flatMap((pp) => pp.IngressRules)
|
const nodePortUrls = getNodePortUrls(item.Services);
|
||||||
.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}`;
|
|
||||||
}) || [];
|
|
||||||
|
|
||||||
// Map all load balancer service ports to ip address
|
// combine all urls
|
||||||
const loadBalancerURLs =
|
const publishedUrls = [...clusterIPs, ...nodePortUrls];
|
||||||
(item.LoadBalancerIPAddress &&
|
|
||||||
item.PublishedPorts?.map(
|
|
||||||
(pp) =>
|
|
||||||
`${getSchemeFromPort(pp.Port)}://${item.LoadBalancerIPAddress}:${
|
|
||||||
pp.Port
|
|
||||||
}`
|
|
||||||
)) ||
|
|
||||||
[];
|
|
||||||
|
|
||||||
// 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 : [];
|
return publishedUrls.length > 0 ? publishedUrls : [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue