/** * 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 { disposeOnUnmount, observer } from "mobx-react"; import { makeObservable, observable, reaction } from "mobx"; import { DrawerItem, DrawerTitle } from "../drawer"; import { ILoadBalancerIngress, Ingress } from "../../../common/k8s-api/endpoints"; import { Table, TableCell, TableHead, TableRow } from "../table"; import { ResourceMetrics } from "../resource-metrics"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { IngressCharts } from "./ingress-charts"; import { KubeObjectMeta } from "../kube-object-meta"; import { getBackendServiceNamePort, getMetricsForIngress, type IIngressMetrics } from "../../../common/k8s-api/endpoints/ingress.api"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { boundMethod } from "../../utils"; import logger from "../../../common/logger"; interface Props extends KubeObjectDetailsProps { } @observer export class IngressDetails extends React.Component { @observable metrics: IIngressMetrics = null; constructor(props: Props) { super(props); makeObservable(this); } componentDidMount() { disposeOnUnmount(this, [ reaction(() => this.props.object, () => { this.metrics = null; }), ]); } @boundMethod async loadMetrics() { const { object: ingress } = this.props; this.metrics = await getMetricsForIngress(ingress.getName(), ingress.getNs()); } renderPaths(ingress: Ingress) { const { spec: { rules }} = ingress; if (!rules || !rules.length) return null; return rules.map((rule, index) => { return (
{rule.host && (
<>Host: {rule.host}
)} {rule.http && ( Path Backends { rule.http.paths.map((path, index) => { const { serviceName, servicePort } = getBackendServiceNamePort(path.backend); const backend = `${serviceName}:${servicePort}`; return ( {path.path || ""}

{backend}

); }) }
)}
); }); } renderIngressPoints(ingressPoints: ILoadBalancerIngress[]) { if (!ingressPoints || ingressPoints.length === 0) return null; return (
Hostname IP {ingressPoints.map(({ hostname, ip }, index) => { return ( {hostname ? hostname : "-"} {ip ? ip : "-"} ); }) })
); } render() { const { object: ingress } = 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 { spec, status } = ingress; const ingressPoints = status?.loadBalancer?.ingress; const { metrics } = this; const metricTabs = [ "Network", "Duration", ]; const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Ingress); const { serviceName, servicePort } = ingress.getServiceNamePort(); return (
{!isMetricHidden && ( )} {ingress.getPorts()} {spec.tls && {spec.tls.map((tls, index) =>

{tls.secretName}

)}
} {serviceName && servicePort && {serviceName}:{servicePort} } {this.renderPaths(ingress)} {this.renderIngressPoints(ingressPoints)}
); } }