Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a6a1280e4f | |||
| 7351d88997 | |||
| 071aab4f7e | |||
| 40544429f4 | |||
| 1f110a2846 | |||
| 672caec903 | |||
| b10d09fd41 | |||
| 8b319c0c8a | |||
| 57250a995d | |||
| 702be12fc8 | |||
| 95aaaa96bd | |||
| b891b3a624 | |||
| 7997eb29fa | |||
| 9885dc44c0 | |||
| 72998cfbca | |||
| 6f7217f400 | |||
| 8b8c447983 | |||
| 7b794f540f | |||
| 0f00fd2f29 | |||
| f95a74c6ae | |||
| 60fc377442 | |||
| dd3e877580 | |||
| da1ef7e0c3 | |||
| 39878f63cc | |||
| 374e2f5b57 | |||
| 581219ceae |
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
extends: ['@headlamp-k8s/eslint-config'],
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
name: AI Code Review
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ai-review:
|
||||||
|
name: AI Code Review
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: AI Review
|
||||||
|
uses: Nikita-Filonov/ai-review@v0.56.0
|
||||||
|
with:
|
||||||
|
review-command: run
|
||||||
|
env:
|
||||||
|
LLM__PROVIDER: "OPENAI"
|
||||||
|
LLM__META__MODEL: ${{ vars.AI_REVIEW_MODEL }}
|
||||||
|
LLM__META__MAX_TOKENS: "15000"
|
||||||
|
LLM__META__TEMPERATURE: "0.3"
|
||||||
|
LLM__HTTP_CLIENT__API_URL: "https://api.openai.com/v1"
|
||||||
|
LLM__HTTP_CLIENT__API_TOKEN: ${{ secrets.OPENAI_API_KEY }}
|
||||||
|
VCS__PROVIDER: "GITEA"
|
||||||
|
VCS__PIPELINE__OWNER: ${{ github.repository_owner }}
|
||||||
|
VCS__PIPELINE__REPO: ${{ github.event.repository.name }}
|
||||||
|
VCS__PIPELINE__PULL_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
VCS__HTTP_CLIENT__API_URL: ${{ github.server_url }}/api/v1
|
||||||
|
VCS__HTTP_CLIENT__API_TOKEN: ${{ secrets.AI_REVIEW_GITEA_TOKEN }}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: node:20
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npx @kinvolk/headlamp-plugin build
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: npx eslint --ext .ts,.tsx src/
|
||||||
|
|
||||||
|
- name: Type-check
|
||||||
|
run: npx tsc --noEmit
|
||||||
|
|
||||||
|
- name: Format check
|
||||||
|
run: npx prettier --check src/
|
||||||
@@ -2,3 +2,4 @@ node_modules/
|
|||||||
dist/
|
dist/
|
||||||
.headlamp-plugin/
|
.headlamp-plugin/
|
||||||
.mcp.json
|
.mcp.json
|
||||||
|
*.tar.gz
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
module.exports = require('@headlamp-k8s/eslint-config/prettier-config');
|
||||||
@@ -7,3 +7,4 @@ RUN npx @kinvolk/headlamp-plugin build
|
|||||||
|
|
||||||
FROM alpine:3.20
|
FROM alpine:3.20
|
||||||
COPY --from=build /app/dist/ /plugins/polaris-headlamp-plugin/
|
COPY --from=build /app/dist/ /plugins/polaris-headlamp-plugin/
|
||||||
|
COPY --from=build /app/package.json /plugins/polaris-headlamp-plugin/
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
version: 0.0.2
|
version: 0.0.6
|
||||||
name: polaris-headlamp-plugin
|
name: polaris-headlamp-plugin
|
||||||
displayName: Polaris
|
displayName: Polaris
|
||||||
createdAt: "2026-02-05T19:00:00Z"
|
createdAt: "2026-02-05T19:00:00Z"
|
||||||
@@ -22,7 +22,7 @@ maintainers:
|
|||||||
- name: cpfarhood
|
- name: cpfarhood
|
||||||
email: "chris@farhood.org"
|
email: "chris@farhood.org"
|
||||||
annotations:
|
annotations:
|
||||||
headlamp/plugin/archive-url: "https://github.com/cpfarhood/polaris-headlamp-plugin/releases/download/v0.0.2/polaris-headlamp-plugin-0.0.2.tar.gz"
|
headlamp/plugin/archive-url: "https://github.com/cpfarhood/polaris-headlamp-plugin/releases/download/v0.0.6/polaris-headlamp-plugin-0.0.6.tar.gz"
|
||||||
headlamp/plugin/version-compat: ">=0.26"
|
headlamp/plugin/version-compat: ">=0.26"
|
||||||
headlamp/plugin/archive-checksum: sha256:19cc243fec368e57a3c288ec73d9da60931f25d1e054ba2a84c55247d43d61bc
|
headlamp/plugin/archive-checksum: sha256:12e72b6a64e3f1c73f542b6328d56391c2cc2906a9a9d7eff58fbf27f14a8680
|
||||||
headlamp/plugin/distro-compat: in-cluster
|
headlamp/plugin/distro-compat: in-cluster
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|||||||
|
|
||||||
## Project Overview
|
## Project Overview
|
||||||
|
|
||||||
Headlamp plugin that surfaces Fairwinds Polaris audit results inside the Headlamp UI. Reads from `ConfigMap/polaris-dashboard` in the `polaris` namespace (key: `dashboard.json`). Target Headlamp ≥ v0.26.
|
Headlamp plugin that surfaces Fairwinds Polaris audit results inside the Headlamp UI. Queries the Polaris dashboard API via the Kubernetes service proxy (`/api/v1/namespaces/polaris/services/polaris-dashboard:80/proxy/results.json`). Target Headlamp ≥ v0.26.
|
||||||
|
|
||||||
## Build & Development Commands
|
## Build & Development Commands
|
||||||
|
|
||||||
@@ -36,11 +36,11 @@ src/
|
|||||||
└── PolarisView.tsx # Main page: score badge, check summary, cluster info, error states, refresh interval selector
|
└── PolarisView.tsx # Main page: score badge, check summary, cluster info, error states, refresh interval selector
|
||||||
```
|
```
|
||||||
|
|
||||||
Single sidebar page at `/polaris`. Data is cached in React state and refreshed on a user-configurable interval (stored in localStorage under `polaris-plugin-refresh-interval`, default 5 minutes). The `usePolarisData` hook wraps `ConfigMap.useGet` with caching so stale data is shown while refreshing.
|
Single sidebar page at `/polaris`. Data is fetched via `ApiProxy.request` to the Polaris dashboard service proxy and refreshed on a user-configurable interval (stored in localStorage under `polaris-plugin-refresh-interval`, default 5 minutes). Score is computed from result counts (pass/total).
|
||||||
|
|
||||||
## Key Constraints
|
## Key Constraints
|
||||||
|
|
||||||
- **Data source**: `ConfigMap/polaris-dashboard` in `polaris` namespace, key `dashboard.json`. No CRDs, no external API calls, no cluster write operations.
|
- **Data source**: Polaris dashboard API via K8s service proxy. Requires Polaris deployed in the `polaris` namespace with a `polaris-dashboard` service. No CRDs, no cluster write operations.
|
||||||
- **UI components**: Use only Headlamp-provided components (`@kinvolk/headlamp-plugin/lib/CommonComponents`). Do not import raw MUI packages. No custom theming.
|
- **UI components**: Use only Headlamp-provided components (`@kinvolk/headlamp-plugin/lib/CommonComponents`). Do not import raw MUI packages. No custom theming.
|
||||||
- **Error handling**: Must handle 403 (RBAC denied), 404 (Polaris not installed), malformed JSON, and loading states with distinct visual states.
|
- **Error handling**: Must handle 403 (RBAC denied), 404 (Polaris not installed), malformed JSON, and loading states with distinct visual states.
|
||||||
- **TypeScript strictness**: No `any`, no implicit `unknown` casting, no dead code, no unused imports.
|
- **TypeScript strictness**: No `any`, no implicit `unknown` casting, no dead code, no unused imports.
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "polaris-headlamp-plugin",
|
"name": "polaris-headlamp-plugin",
|
||||||
"version": "0.0.1",
|
"version": "0.0.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "polaris-headlamp-plugin",
|
"name": "polaris-headlamp-plugin",
|
||||||
"version": "0.0.1",
|
"version": "0.0.5",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@kinvolk/headlamp-plugin": "^0.13.0"
|
"@kinvolk/headlamp-plugin": "^0.13.0"
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -1,12 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "polaris-headlamp-plugin",
|
"name": "polaris-headlamp-plugin",
|
||||||
"version": "0.0.2",
|
"version": "0.0.6",
|
||||||
"description": "Headlamp plugin for Fairwinds Polaris audit results",
|
"description": "Headlamp plugin for Fairwinds Polaris audit results",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "headlamp-plugin start",
|
"start": "headlamp-plugin start",
|
||||||
"build": "headlamp-plugin build",
|
"build": "headlamp-plugin build",
|
||||||
"package": "headlamp-plugin package",
|
"package": "headlamp-plugin package",
|
||||||
"tsc": "tsc --noEmit"
|
"tsc": "tsc --noEmit",
|
||||||
|
"lint": "eslint --ext .ts,.tsx src/",
|
||||||
|
"lint:fix": "eslint --ext .ts,.tsx --fix src/",
|
||||||
|
"format": "prettier --write src/",
|
||||||
|
"format:check": "prettier --check src/"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@kinvolk/headlamp-plugin": "^0.13.0"
|
"@kinvolk/headlamp-plugin": "^0.13.0"
|
||||||
|
|||||||
+59
-76
@@ -1,4 +1,4 @@
|
|||||||
import { K8s } from '@kinvolk/headlamp-plugin/lib';
|
import { ApiProxy } from '@kinvolk/headlamp-plugin/lib';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
// --- Polaris AuditData schema (matches pkg/validator/output.go) ---
|
// --- Polaris AuditData schema (matches pkg/validator/output.go) ---
|
||||||
@@ -52,7 +52,6 @@ export interface AuditData {
|
|||||||
DisplayName: string;
|
DisplayName: string;
|
||||||
ClusterInfo: ClusterInfo;
|
ClusterInfo: ClusterInfo;
|
||||||
Results: Result[];
|
Results: Result[];
|
||||||
Score: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Result counting ---
|
// --- Result counting ---
|
||||||
@@ -94,6 +93,13 @@ export function countResults(data: AuditData): ResultCounts {
|
|||||||
|
|
||||||
// --- Settings ---
|
// --- Settings ---
|
||||||
|
|
||||||
|
export const INTERVAL_OPTIONS = [
|
||||||
|
{ label: '1 minute', value: 60 },
|
||||||
|
{ label: '5 minutes', value: 300 },
|
||||||
|
{ label: '10 minutes', value: 600 },
|
||||||
|
{ label: '30 minutes', value: 1800 },
|
||||||
|
];
|
||||||
|
|
||||||
const STORAGE_KEY = 'polaris-plugin-refresh-interval';
|
const STORAGE_KEY = 'polaris-plugin-refresh-interval';
|
||||||
const DEFAULT_INTERVAL_SECONDS = 300; // 5 minutes
|
const DEFAULT_INTERVAL_SECONDS = 300; // 5 minutes
|
||||||
|
|
||||||
@@ -112,8 +118,18 @@ export function setRefreshInterval(seconds: number): void {
|
|||||||
localStorage.setItem(STORAGE_KEY, String(seconds));
|
localStorage.setItem(STORAGE_KEY, String(seconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Score computation ---
|
||||||
|
|
||||||
|
export function computeScore(counts: ResultCounts): number {
|
||||||
|
if (counts.total === 0) return 0;
|
||||||
|
return Math.round((counts.pass / counts.total) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
// --- Data fetching hook ---
|
// --- Data fetching hook ---
|
||||||
|
|
||||||
|
const POLARIS_API_PATH =
|
||||||
|
'/api/v1/namespaces/polaris/services/polaris-dashboard:80/proxy/results.json';
|
||||||
|
|
||||||
interface PolarisDataState {
|
interface PolarisDataState {
|
||||||
data: AuditData | null;
|
data: AuditData | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@@ -121,87 +137,54 @@ interface PolarisDataState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function usePolarisData(refreshIntervalSeconds: number): PolarisDataState {
|
export function usePolarisData(refreshIntervalSeconds: number): PolarisDataState {
|
||||||
const [configMap, fetchError] = K8s.ResourceClasses.ConfigMap.useGet(
|
const [data, setData] = React.useState<AuditData | null>(null);
|
||||||
'polaris-dashboard',
|
const [loading, setLoading] = React.useState(true);
|
||||||
'polaris'
|
const [error, setError] = React.useState<string | null>(null);
|
||||||
);
|
const [tick, setTick] = React.useState(0);
|
||||||
const [cachedData, setCachedData] = React.useState<AuditData | null>(null);
|
|
||||||
const [parseError, setParseError] = React.useState<string | null>(null);
|
|
||||||
const [lastFetchTime, setLastFetchTime] = React.useState<number>(0);
|
|
||||||
const [, setTick] = React.useState(0);
|
|
||||||
|
|
||||||
// Parse ConfigMap data when it arrives
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!configMap) {
|
let cancelled = false;
|
||||||
return;
|
|
||||||
}
|
|
||||||
const dataMap = configMap.data as Record<string, string> | undefined;
|
|
||||||
const raw = dataMap?.['dashboard.json'];
|
|
||||||
if (!raw) {
|
|
||||||
setParseError('ConfigMap exists but dashboard.json key is missing.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const parsed: AuditData = JSON.parse(raw);
|
|
||||||
setCachedData(parsed);
|
|
||||||
setParseError(null);
|
|
||||||
setLastFetchTime(Date.now());
|
|
||||||
} catch {
|
|
||||||
setParseError('Failed to parse dashboard.json: malformed JSON.');
|
|
||||||
}
|
|
||||||
}, [configMap]);
|
|
||||||
|
|
||||||
// Periodic refresh via re-render trigger
|
async function fetchData() {
|
||||||
React.useEffect(() => {
|
try {
|
||||||
if (refreshIntervalSeconds <= 0) {
|
const result: AuditData = await ApiProxy.request(POLARIS_API_PATH);
|
||||||
return;
|
if (!cancelled) {
|
||||||
|
setData(result);
|
||||||
|
setError(null);
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
} catch (err: unknown) {
|
||||||
|
if (cancelled) return;
|
||||||
|
const status = (err as { status?: number }).status;
|
||||||
|
if (status === 403) {
|
||||||
|
setError(
|
||||||
|
'Access denied (403). Check that your RBAC permissions allow proxying to the Polaris service.'
|
||||||
|
);
|
||||||
|
} else if (status === 404 || status === 503) {
|
||||||
|
setError(
|
||||||
|
'Polaris dashboard not reachable. Ensure Polaris is installed in the polaris namespace.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setError(`Failed to fetch Polaris data: ${String(err)}`);
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchData();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [tick]);
|
||||||
|
|
||||||
|
// Periodic refresh
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (refreshIntervalSeconds <= 0) return;
|
||||||
const intervalId = window.setInterval(() => {
|
const intervalId = window.setInterval(() => {
|
||||||
setTick((t) => t + 1);
|
setTick(t => t + 1);
|
||||||
}, refreshIntervalSeconds * 1000);
|
}, refreshIntervalSeconds * 1000);
|
||||||
return () => window.clearInterval(intervalId);
|
return () => window.clearInterval(intervalId);
|
||||||
}, [refreshIntervalSeconds]);
|
}, [refreshIntervalSeconds]);
|
||||||
|
|
||||||
// Determine error state
|
return { data, loading, error };
|
||||||
if (fetchError) {
|
|
||||||
const status = (fetchError as { status?: number }).status;
|
|
||||||
if (status === 403) {
|
|
||||||
return {
|
|
||||||
data: cachedData,
|
|
||||||
loading: false,
|
|
||||||
error:
|
|
||||||
'Access denied (403). Check that your RBAC permissions allow reading ConfigMaps in the polaris namespace.',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (status === 404) {
|
|
||||||
return {
|
|
||||||
data: cachedData,
|
|
||||||
loading: false,
|
|
||||||
error:
|
|
||||||
'Polaris dashboard ConfigMap not found (404). Ensure Polaris is installed in the polaris namespace.',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
data: cachedData,
|
|
||||||
loading: false,
|
|
||||||
error: `Failed to fetch Polaris data: ${String(fetchError)}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parseError) {
|
|
||||||
return { data: cachedData, loading: false, error: parseError };
|
|
||||||
}
|
|
||||||
|
|
||||||
const isLoading = !configMap && !fetchError;
|
|
||||||
|
|
||||||
// Return cached data while loading if we have it
|
|
||||||
if (isLoading && cachedData && lastFetchTime > 0) {
|
|
||||||
return { data: cachedData, loading: false, error: null };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: cachedData,
|
|
||||||
loading: isLoading,
|
|
||||||
error: null,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { NameValueTable, SectionBox } from '@kinvolk/headlamp-plugin/lib/CommonComponents';
|
||||||
|
import React from 'react';
|
||||||
|
import { getRefreshInterval, INTERVAL_OPTIONS, setRefreshInterval } from '../api/polaris';
|
||||||
|
|
||||||
|
interface PluginSettingsProps {
|
||||||
|
data?: { [key: string]: string | number | boolean };
|
||||||
|
onDataChange?: (data: { [key: string]: string | number | boolean }) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PolarisSettings(props: PluginSettingsProps) {
|
||||||
|
const { data, onDataChange } = props;
|
||||||
|
const currentInterval = (data?.refreshInterval as number) ?? getRefreshInterval();
|
||||||
|
|
||||||
|
function handleChange(e: React.ChangeEvent<HTMLSelectElement>) {
|
||||||
|
const seconds = Number(e.target.value);
|
||||||
|
setRefreshInterval(seconds);
|
||||||
|
onDataChange?.({ ...data, refreshInterval: seconds });
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SectionBox title="Polaris Settings">
|
||||||
|
<NameValueTable
|
||||||
|
rows={[
|
||||||
|
{
|
||||||
|
name: 'Refresh Interval',
|
||||||
|
value: (
|
||||||
|
<select value={currentInterval} onChange={handleChange}>
|
||||||
|
{INTERVAL_OPTIONS.map(opt => (
|
||||||
|
<option key={opt.value} value={opt.value}>
|
||||||
|
{opt.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</SectionBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
+61
-108
@@ -1,130 +1,77 @@
|
|||||||
import {
|
import {
|
||||||
Loader,
|
Loader,
|
||||||
|
NameValueTable,
|
||||||
SectionBox,
|
SectionBox,
|
||||||
SectionHeader,
|
SectionHeader,
|
||||||
|
StatusLabel,
|
||||||
} from '@kinvolk/headlamp-plugin/lib/CommonComponents';
|
} from '@kinvolk/headlamp-plugin/lib/CommonComponents';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
AuditData,
|
AuditData,
|
||||||
|
computeScore,
|
||||||
countResults,
|
countResults,
|
||||||
getRefreshInterval,
|
getRefreshInterval,
|
||||||
ResultCounts,
|
ResultCounts,
|
||||||
setRefreshInterval,
|
|
||||||
usePolarisData,
|
usePolarisData,
|
||||||
} from '../api/polaris';
|
} from '../api/polaris';
|
||||||
|
|
||||||
const INTERVAL_OPTIONS = [
|
function scoreStatus(score: number): 'success' | 'warning' | 'error' {
|
||||||
{ label: '1 minute', value: 60 },
|
if (score >= 80) return 'success';
|
||||||
{ label: '5 minutes', value: 300 },
|
if (score >= 50) return 'warning';
|
||||||
{ label: '10 minutes', value: 600 },
|
return 'error';
|
||||||
{ label: '30 minutes', value: 1800 },
|
|
||||||
];
|
|
||||||
|
|
||||||
function RefreshSettings(props: {
|
|
||||||
interval: number;
|
|
||||||
onChange: (seconds: number) => void;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
|
||||||
<label htmlFor="polaris-refresh-interval">Refresh interval:</label>
|
|
||||||
<select
|
|
||||||
id="polaris-refresh-interval"
|
|
||||||
value={props.interval}
|
|
||||||
onChange={(e) => props.onChange(Number(e.target.value))}
|
|
||||||
>
|
|
||||||
{INTERVAL_OPTIONS.map((opt) => (
|
|
||||||
<option key={opt.value} value={opt.value}>
|
|
||||||
{opt.label}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function StatCard(props: { label: string; value: number; color?: string }) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: '16px 24px',
|
|
||||||
textAlign: 'center',
|
|
||||||
minWidth: '120px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '2rem',
|
|
||||||
fontWeight: 'bold',
|
|
||||||
color: props.color,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{props.value}
|
|
||||||
</div>
|
|
||||||
<div style={{ fontSize: '0.875rem', opacity: 0.8 }}>{props.label}</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ScoreBadge(props: { score: number }) {
|
|
||||||
const color = props.score >= 80 ? '#4caf50' : props.score >= 50 ? '#ff9800' : '#f44336';
|
|
||||||
return (
|
|
||||||
<div style={{ textAlign: 'center', marginBottom: '16px' }}>
|
|
||||||
<div style={{ fontSize: '3rem', fontWeight: 'bold', color }}>
|
|
||||||
{props.score}%
|
|
||||||
</div>
|
|
||||||
<div style={{ fontSize: '0.875rem', opacity: 0.8 }}>Cluster Score</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function OverviewSection(props: { data: AuditData; counts: ResultCounts }) {
|
function OverviewSection(props: { data: AuditData; counts: ResultCounts }) {
|
||||||
|
const score = computeScore(props.counts);
|
||||||
|
const status = scoreStatus(score);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SectionBox title="Score">
|
<SectionBox title="Score">
|
||||||
<ScoreBadge score={props.data.Score} />
|
<NameValueTable
|
||||||
|
rows={[
|
||||||
|
{
|
||||||
|
name: 'Cluster Score',
|
||||||
|
value: <StatusLabel status={status}>{score}%</StatusLabel>,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</SectionBox>
|
</SectionBox>
|
||||||
<SectionBox title="Check Summary">
|
<SectionBox title="Check Summary">
|
||||||
<div
|
<NameValueTable
|
||||||
style={{
|
rows={[
|
||||||
display: 'flex',
|
{ name: 'Total Checks', value: String(props.counts.total) },
|
||||||
justifyContent: 'center',
|
{
|
||||||
flexWrap: 'wrap',
|
name: 'Pass',
|
||||||
gap: '16px',
|
value: <StatusLabel status="success">{props.counts.pass}</StatusLabel>,
|
||||||
}}
|
},
|
||||||
>
|
{
|
||||||
<StatCard label="Total" value={props.counts.total} />
|
name: 'Warning',
|
||||||
<StatCard label="Pass" value={props.counts.pass} color="#4caf50" />
|
value: <StatusLabel status="warning">{props.counts.warning}</StatusLabel>,
|
||||||
<StatCard label="Warning" value={props.counts.warning} color="#ff9800" />
|
},
|
||||||
<StatCard label="Danger" value={props.counts.danger} color="#f44336" />
|
{
|
||||||
</div>
|
name: 'Danger',
|
||||||
|
value: <StatusLabel status="error">{props.counts.danger}</StatusLabel>,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</SectionBox>
|
</SectionBox>
|
||||||
<SectionBox title="Cluster Info">
|
<SectionBox title="Cluster Info">
|
||||||
<div
|
<NameValueTable
|
||||||
style={{
|
rows={[
|
||||||
display: 'flex',
|
{ name: 'Nodes', value: String(props.data.ClusterInfo.Nodes) },
|
||||||
justifyContent: 'center',
|
{ name: 'Pods', value: String(props.data.ClusterInfo.Pods) },
|
||||||
flexWrap: 'wrap',
|
{ name: 'Namespaces', value: String(props.data.ClusterInfo.Namespaces) },
|
||||||
gap: '16px',
|
{ name: 'Controllers', value: String(props.data.ClusterInfo.Controllers) },
|
||||||
}}
|
]}
|
||||||
>
|
/>
|
||||||
<StatCard label="Nodes" value={props.data.ClusterInfo.Nodes} />
|
|
||||||
<StatCard label="Pods" value={props.data.ClusterInfo.Pods} />
|
|
||||||
<StatCard label="Namespaces" value={props.data.ClusterInfo.Namespaces} />
|
|
||||||
<StatCard label="Controllers" value={props.data.ClusterInfo.Controllers} />
|
|
||||||
</div>
|
|
||||||
</SectionBox>
|
</SectionBox>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PolarisView() {
|
export default function PolarisView() {
|
||||||
const [interval, setInterval] = React.useState(getRefreshInterval);
|
const interval = getRefreshInterval();
|
||||||
|
|
||||||
function handleIntervalChange(seconds: number) {
|
|
||||||
setInterval(seconds);
|
|
||||||
setRefreshInterval(seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data, loading, error } = usePolarisData(interval);
|
const { data, loading, error } = usePolarisData(interval);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@@ -135,17 +82,18 @@ export default function PolarisView() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SectionHeader title="Polaris" actions={[
|
<SectionHeader title="Polaris" />
|
||||||
<RefreshSettings
|
|
||||||
key="refresh"
|
|
||||||
interval={interval}
|
|
||||||
onChange={handleIntervalChange}
|
|
||||||
/>,
|
|
||||||
]} />
|
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<SectionBox title="Error">
|
<SectionBox title="Error">
|
||||||
<div style={{ padding: '16px', color: '#f44336' }}>{error}</div>
|
<NameValueTable
|
||||||
|
rows={[
|
||||||
|
{
|
||||||
|
name: 'Status',
|
||||||
|
value: <StatusLabel status="error">{error}</StatusLabel>,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</SectionBox>
|
</SectionBox>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -153,9 +101,14 @@ export default function PolarisView() {
|
|||||||
|
|
||||||
{!data && !error && (
|
{!data && !error && (
|
||||||
<SectionBox title="No Data">
|
<SectionBox title="No Data">
|
||||||
<div style={{ padding: '16px' }}>
|
<NameValueTable
|
||||||
No Polaris audit results found.
|
rows={[
|
||||||
</div>
|
{
|
||||||
|
name: 'Status',
|
||||||
|
value: 'No Polaris audit results found.',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</SectionBox>
|
</SectionBox>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
|
registerPluginSettings,
|
||||||
registerRoute,
|
registerRoute,
|
||||||
registerSidebarEntry,
|
registerSidebarEntry,
|
||||||
} from '@kinvolk/headlamp-plugin/lib';
|
} from '@kinvolk/headlamp-plugin/lib';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PolarisSettings from './components/PolarisSettings';
|
||||||
import PolarisView from './components/PolarisView';
|
import PolarisView from './components/PolarisView';
|
||||||
|
|
||||||
registerSidebarEntry({
|
registerSidebarEntry({
|
||||||
@@ -20,3 +22,5 @@ registerRoute({
|
|||||||
exact: true,
|
exact: true,
|
||||||
component: () => <PolarisView />,
|
component: () => <PolarisView />,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerPluginSettings('polaris-headlamp-plugin', PolarisSettings, true);
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "@kinvolk/headlamp-plugin/config/plugins-tsconfig.json",
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user