/** * 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 type { ILoadBalancerIngress } from "../../../common/k8s-api/endpoints"; import { 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 { computeRuleDeclarations } from "../../../common/k8s-api/endpoints/ingress.api"; import { getActiveClusterEntity } from "../../api/catalog/entity/legacy-globals"; import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import logger from "../../../common/logger"; import type { IngressMetricData, RequestIngressMetrics } from "../../../common/k8s-api/endpoints/metrics.api/request-ingress-metrics.injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import requestIngressMetricsInjectable from "../../../common/k8s-api/endpoints/metrics.api/request-ingress-metrics.injectable"; export interface IngressDetailsProps extends KubeObjectDetailsProps { } interface Dependencies { requestIngressMetrics: RequestIngressMetrics; } @observer class NonInjectedIngressDetails extends React.Component { @observable metrics: IngressMetricData | null = null; constructor(props: IngressDetailsProps & Dependencies) { super(props); makeObservable(this); } componentDidMount() { disposeOnUnmount(this, [ reaction(() => this.props.object, () => { this.metrics = null; }), ]); } loadMetrics = async () => { const { object: ingress, requestIngressMetrics } = this.props; this.metrics = await requestIngressMetrics(ingress.getName(), ingress.getNs()); }; 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 } = 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 isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Ingress); const port = ingress.getServiceNamePort(); return (
{!isMetricHidden && ( )} {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, requestIngressMetrics: di.inject(requestIngressMetricsInjectable), }), });