Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57250a995d | |||
| 702be12fc8 | |||
| 95aaaa96bd | |||
| b891b3a624 | |||
| 7997eb29fa | |||
| 9885dc44c0 | |||
| 72998cfbca | |||
| 6f7217f400 |
@@ -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 }}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
version: 0.0.4
|
version: 0.0.5
|
||||||
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.4/polaris-headlamp-plugin-0.0.4.tar.gz"
|
headlamp/plugin/archive-url: "https://github.com/cpfarhood/polaris-headlamp-plugin/releases/download/v0.0.5/polaris-headlamp-plugin-0.0.5.tar.gz"
|
||||||
headlamp/plugin/version-compat: ">=0.26"
|
headlamp/plugin/version-compat: ">=0.26"
|
||||||
headlamp/plugin/archive-checksum: sha256:4c460681d389c8977d7e7ae57ac6aedd64281de4b58284b0bcc9fb34525432f2
|
headlamp/plugin/archive-checksum: sha256:afc57a1e869898b0197364e568205426f32572b703c638246463bb5c7898f4d2
|
||||||
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.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "polaris-headlamp-plugin",
|
"name": "polaris-headlamp-plugin",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"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",
|
||||||
|
|||||||
+51
-75
@@ -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 ---
|
||||||
@@ -112,8 +111,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 +130,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,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Loader, SectionBox, SectionHeader } from '@kinvolk/headlamp-plugin/lib/
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
AuditData,
|
AuditData,
|
||||||
|
computeScore,
|
||||||
countResults,
|
countResults,
|
||||||
getRefreshInterval,
|
getRefreshInterval,
|
||||||
ResultCounts,
|
ResultCounts,
|
||||||
@@ -69,10 +70,11 @@ function ScoreBadge(props: { score: number }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function OverviewSection(props: { data: AuditData; counts: ResultCounts }) {
|
function OverviewSection(props: { data: AuditData; counts: ResultCounts }) {
|
||||||
|
const score = computeScore(props.counts);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SectionBox title="Score">
|
<SectionBox title="Score">
|
||||||
<ScoreBadge score={props.data.Score} />
|
<ScoreBadge score={score} />
|
||||||
</SectionBox>
|
</SectionBox>
|
||||||
<SectionBox title="Check Summary">
|
<SectionBox title="Check Summary">
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user