2ca66e7d7b
Headlamp identifies plugins by reading package.json from the plugin
directory. Since package.json name is 'headlamp-polaris', both the
registerPluginSettings call and the E2E settings test must use
'headlamp-polaris', not 'polaris'.
- registerPluginSettings('polaris') → registerPluginSettings('headlamp-polaris')
- E2E test locator: text=polaris → text=headlamp-polaris
Co-Authored-By: Paperclip <noreply@paperclip.ing>
129 lines
3.0 KiB
TypeScript
129 lines
3.0 KiB
TypeScript
import {
|
|
registerAppBarAction,
|
|
registerDetailsViewSection,
|
|
registerPluginSettings,
|
|
registerRoute,
|
|
registerSidebarEntry,
|
|
} from '@kinvolk/headlamp-plugin/lib';
|
|
import { SectionBox, StatusLabel } from '@kinvolk/headlamp-plugin/lib/CommonComponents';
|
|
import React from 'react';
|
|
import { PolarisDataProvider } from './api/PolarisDataContext';
|
|
import AppBarScoreBadge from './components/AppBarScoreBadge';
|
|
import DashboardView from './components/DashboardView';
|
|
import InlineAuditSection from './components/InlineAuditSection';
|
|
import NamespacesListView from './components/NamespacesListView';
|
|
import PolarisSettings from './components/PolarisSettings';
|
|
|
|
// --- Error boundary for plugin components ---
|
|
|
|
interface ErrorBoundaryState {
|
|
error: string | null;
|
|
}
|
|
|
|
class PolarisErrorBoundary extends React.Component<
|
|
{ children: React.ReactNode },
|
|
ErrorBoundaryState
|
|
> {
|
|
state: ErrorBoundaryState = { error: null };
|
|
|
|
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
|
return { error: error.message };
|
|
}
|
|
|
|
render() {
|
|
if (this.state.error) {
|
|
return (
|
|
<SectionBox title="Polaris Plugin Error">
|
|
<StatusLabel status="error">{this.state.error}</StatusLabel>
|
|
</SectionBox>
|
|
);
|
|
}
|
|
return this.props.children;
|
|
}
|
|
}
|
|
|
|
// --- Sidebar entries ---
|
|
|
|
registerSidebarEntry({
|
|
parent: null,
|
|
name: 'polaris',
|
|
label: 'Polaris',
|
|
url: '/polaris',
|
|
icon: 'mdi:shield-check',
|
|
});
|
|
|
|
registerSidebarEntry({
|
|
parent: 'polaris',
|
|
name: 'polaris-overview',
|
|
label: 'Overview',
|
|
url: '/polaris',
|
|
icon: 'mdi:view-dashboard',
|
|
});
|
|
|
|
registerSidebarEntry({
|
|
parent: 'polaris',
|
|
name: 'polaris-namespaces',
|
|
label: 'Namespaces',
|
|
url: '/polaris/namespaces',
|
|
icon: 'mdi:dns',
|
|
});
|
|
|
|
// --- Routes ---
|
|
|
|
registerRoute({
|
|
path: '/polaris',
|
|
sidebar: 'polaris-overview',
|
|
name: 'polaris',
|
|
exact: true,
|
|
component: () => (
|
|
<PolarisErrorBoundary>
|
|
<PolarisDataProvider>
|
|
<DashboardView />
|
|
</PolarisDataProvider>
|
|
</PolarisErrorBoundary>
|
|
),
|
|
});
|
|
|
|
registerRoute({
|
|
path: '/polaris/namespaces',
|
|
sidebar: 'polaris-namespaces',
|
|
name: 'polaris-namespaces',
|
|
exact: true,
|
|
component: () => (
|
|
<PolarisErrorBoundary>
|
|
<PolarisDataProvider>
|
|
<NamespacesListView />
|
|
</PolarisDataProvider>
|
|
</PolarisErrorBoundary>
|
|
),
|
|
});
|
|
|
|
// Register plugin settings
|
|
registerPluginSettings('headlamp-polaris', PolarisSettings, true);
|
|
|
|
// Register details view section for supported controller types
|
|
registerDetailsViewSection(({ resource }) => {
|
|
const supportedKinds = ['Deployment', 'StatefulSet', 'DaemonSet', 'Job', 'CronJob'];
|
|
|
|
if (!supportedKinds.includes(resource?.kind)) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<PolarisErrorBoundary>
|
|
<PolarisDataProvider>
|
|
<InlineAuditSection resource={resource} />
|
|
</PolarisDataProvider>
|
|
</PolarisErrorBoundary>
|
|
);
|
|
});
|
|
|
|
// Register app bar score badge
|
|
registerAppBarAction(() => (
|
|
<PolarisErrorBoundary>
|
|
<PolarisDataProvider>
|
|
<AppBarScoreBadge />
|
|
</PolarisDataProvider>
|
|
</PolarisErrorBoundary>
|
|
));
|