UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

77 lines (76 loc) 3.22 kB
import { jsx as _jsx } from "react/jsx-runtime"; /* * Copyright 2025 The Kubernetes Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React from 'react'; import { useTranslation } from 'react-i18next'; import Ingress from '../../lib/k8s/ingress'; import LabelListItem from '../common/LabelListItem'; import Link from '../common/Link'; import ResourceListView from '../common/Resource/ResourceListView'; function RulesDisplay(props) { const { ingress } = props; const rulesText = React.useMemo(() => { const rules = ingress.getRules(); let labels = []; rules.forEach(({ http }) => { const text = http?.paths.map(({ path, backend }) => { let target = ''; if (!!backend.service) { const service = backend.service.name; const port = backend.service.port.number ?? backend.service.port.name ?? ''; target = `${!!service ? service + ':' + port.toString() : port.toString()}`; } else if (!!backend.resource) { target = `${backend.resource.kind}:${backend.resource.name}`; } return `${path} 🞂 ${target}`; }) ?? ''; labels = labels.concat(text); }); return labels; }, [ingress]); return _jsx(LabelListItem, { labels: rulesText }); } export default function IngressList() { const { t } = useTranslation(['glossary', 'translation']); return (_jsx(ResourceListView, { title: t('Ingresses'), resourceClass: Ingress, columns: [ 'name', 'namespace', 'cluster', { id: 'class', label: t('Class Name'), getValue: ingress => ingress.spec?.ingressClassName, render: ingress => ingress.spec?.ingressClassName ? (_jsx(Link, { routeName: "ingressclass", params: { name: ingress.spec?.ingressClassName }, activeCluster: ingress.cluster, children: ingress.spec?.ingressClassName })) : null, }, { id: 'hosts', label: t('Hosts'), getValue: ingress => ingress .getRules() .map(r => r.host ?? '*') .join(''), render: ingress => (_jsx(LabelListItem, { labels: ingress.getRules().map(({ host }) => host || '*') })), }, { id: 'ports', label: t('translation|Path'), getValue: () => '', render: (ingress) => _jsx(RulesDisplay, { ingress: ingress }), }, 'age', ] })); }