import "./hpa-details.scss"; import React from "react"; import { observer } from "mobx-react"; import { Link } from "react-router-dom"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import { KubeObjectDetailsProps } from "../kube-object"; import { cssNames } from "../../utils"; import { HorizontalPodAutoscaler, hpaApi, HpaMetricType, IHpaMetric } from "../../api/endpoints/hpa.api"; import { KubeEventDetails } from "../+events/kube-event-details"; import { Trans } from "@lingui/macro"; import { Table, TableCell, TableHead, TableRow } from "../table"; import { getDetailsUrl } from "../../navigation"; import { lookupApiLink } from "../../api/kube-api"; import { apiManager } from "../../api/api-manager"; import { KubeObjectMeta } from "../kube-object/kube-object-meta"; interface Props extends KubeObjectDetailsProps { } @observer export class HpaDetails extends React.Component { renderMetrics() { const { object: hpa } = this.props; const renderName = (metric: IHpaMetric) => { switch (metric.type) { case HpaMetricType.Resource: const addition = metric.resource.targetAverageUtilization ? (as a percentage of request) : ""; return Resource {metric.resource.name} on Pods {addition}; case HpaMetricType.Pods: return {metric.pods.metricName} on Pods; case HpaMetricType.Object: const { target } = metric.object; const { kind, name } = target; const objectUrl = getDetailsUrl(lookupApiLink(target, hpa)); return ( {metric.object.metricName} on{" "} {kind}/{name} ); case HpaMetricType.External: return ( {metric.external.metricName} on{" "} {JSON.stringify(metric.external.selector)} ); } } return ( Name Current / Target { hpa.getMetrics().map((metric, index) => { const name = renderName(metric); const values = hpa.getMetricValues(metric); return ( {name} {values} ) }) }
); } render() { const { object: hpa } = this.props; if (!hpa) return; const { scaleTargetRef } = hpa.spec; return (
Reference}> {scaleTargetRef && ( {scaleTargetRef.kind}/{scaleTargetRef.name} )} Min Pods}> {hpa.getMinPods()} Max Pods}> {hpa.getMaxPods()} Replicas}> {hpa.getReplicas()} Status} labelsOnly> {hpa.getConditions().map(({ type, tooltip, isReady }) => { if (!isReady) return null; return ( ) })}
{this.renderMetrics()}
); } } apiManager.registerViews(hpaApi, { Details: HpaDetails, });