/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./ingress-details.scss"; import React from "react"; import { observer } from "mobx-react"; import { DrawerItem, DrawerTitle } from "../drawer"; import type { ILoadBalancerIngress } from "../../../common/k8s-api/endpoints"; import { Ingress } from "../../../common/k8s-api/endpoints"; import { Table, TableCell, TableHead, TableRow } from "../table"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { computeRuleDeclarations } from "../../../common/k8s-api/endpoints/ingress.api"; import type { Logger } from "../../../common/logger"; import { withInjectables } from "@ogre-tools/injectable-react"; import loggerInjectable from "../../../common/logger.injectable"; export interface IngressDetailsProps extends KubeObjectDetailsProps { } interface Dependencies { logger: Logger; } @observer class NonInjectedIngressDetails extends React.Component { renderPaths(ingress: Ingress) { return ingress.getRules() .map((rule, index) => (
{rule.host && (
{`Host: ${rule.host}`}
)} {rule.http && ( Path Link Backends { computeRuleDeclarations(ingress, rule) .map(({ displayAsLink, service, url, pathname }) => ( {pathname} { displayAsLink ? ( {url} ) : url } {service} )) }
)}
)); } renderIngressPoints(ingressPoints: ILoadBalancerIngress[]) { if (!ingressPoints || ingressPoints.length === 0) return null; return (
Hostname IP { ingressPoints.map(({ hostname, ip }, index) => ( {hostname ? hostname : "-"} {ip ? ip : "-"} )) }
); } render() { const { object: ingress, logger } = this.props; if (!ingress) { return null; } if (!(ingress instanceof Ingress)) { logger.error("[IngressDetails]: passed object that is not an instanceof Ingress", ingress); return null; } const port = ingress.getServiceNamePort(); return (
{ingress.getPorts()} {ingress.spec.tls && ( {ingress.spec.tls.map((tls, index) =>

{tls.secretName}

)}
)} {port && ( {`${port.serviceName}:${port.servicePort}`} )} Rules {this.renderPaths(ingress)} Load-Balancer Ingress Points {this.renderIngressPoints(ingress.status?.loadBalancer?.ingress ?? [])}
); } } export const IngressDetails = withInjectables(NonInjectedIngressDetails, { getProps: (di, props) => ({ ...props, logger: di.inject(loggerInjectable), }), });