Compare commits

...

100 Commits

Author SHA1 Message Date
gitea-actions[bot] 1273f94ae5 ci: update artifact hub metadata for v0.2.0-dev.2 2026-02-09 16:03:25 +00:00
gitea-actions[bot] 99bac773cc ci: update artifact hub metadata for v0.2.0-dev.1 2026-02-09 15:26:20 +00:00
gitea-actions[bot] 9fdb7c04cd ci: update artifact hub metadata for v0.2.0-dev.1 2026-02-09 14:34:11 +00:00
gitea-actions[bot] 975a31d1f3 ci: update artifact hub metadata for v0.2.0-dev.1 2026-02-09 14:26:59 +00:00
gitea-actions[bot] e54630410e ci: update artifact hub metadata for v0.2.0-dev.1 2026-02-09 14:18:16 +00:00
gitea-actions[bot] 4838b22a02 ci: update artifact hub metadata for v0.1.6 2026-02-08 03:15:02 +00:00
Chris Farhood c67bcb1804 chore: bump version to 0.1.6 2026-02-07 22:13:19 -05:00
Chris Farhood c19bb2fa87 fix: use "Polaris" as plugin settings display name
Changed from "headlamp-polaris-plugin" to "Polaris" in the
registerPluginSettings call. This makes the plugin name appear
cleanly in Settings > Plugins.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-07 22:12:55 -05:00
Chris Farhood 253d1277d9 docs: document skipped count limitation
Added "Known Limitations" section explaining that the skipped count
only reflects Severity=ignore checks and does not include
annotation-based exemptions.

Explains why (exempted checks omitted from results.json) and what
would be required to support exemption counting (direct K8s resource
queries with broader RBAC).

Points users to the "View in Polaris Dashboard" link as a workaround.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-07 22:12:55 -05:00
Chris Farhood f69c91acf9 feat: add tooltip to skipped count explaining limitation
The skipped count only reflects checks with Severity=ignore from
the Polaris API. Annotation-based exemptions (e.g.,
polaris.fairwinds.com/*-exempt) are not included because:

1. Exempted checks are completely omitted from results.json
2. The Polaris dashboard UI counts exemptions client-side by
   querying Kubernetes resources for annotations
3. Our plugin only has access to the processed audit results

Added HTML title tooltip to explain this limitation to users.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-07 22:12:55 -05:00
Chris Farhood 5659026959 fix: add :80 port to dashboard proxy constant
The POLARIS_DASHBOARD_PROXY constant was missing :80, causing
dashboard links in the UI to fail with "no endpoints available".
This matches the fix already applied to POLARIS_API_PATH.

Fixes external dashboard link in namespace detail view.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-07 22:12:55 -05:00
gitea-actions[bot] 6ae632f577 ci: update artifact hub metadata for v0.1.5 2026-02-08 01:48:09 +00:00
Chris Farhood e0cfb4e808 chore: bump version to 0.1.5 2026-02-07 20:46:32 -05:00
Chris Farhood c4c43cef40 fix: restore :80 port in service proxy URL
The removal of :80 in commit 39d85a3 broke service proxy requests.
Kubernetes API requires explicit port specification when services
have named ports. Without it, the API server returns "no endpoints
available" even though endpoints exist.

Root cause: polaris-dashboard service defines port as named
"http-dashboard" on port 80. The proxy sub-resource requires
either :80 or :http-dashboard suffix to resolve correctly.

Fixes the "Polaris dashboard not reachable" error on v0.1.4.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-07 20:46:13 -05:00
gitea-actions[bot] 957c5fe791 ci: update artifact hub metadata for v0.1.4 2026-02-08 00:20:15 +00:00
Chris Farhood 380e34e652 chore: bump version to 0.1.4
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 19:18:47 -05:00
Chris Farhood b1e50d7416 Merge pull request 'feat: E2E smoke tests + fix empty namespace crash' (#19) from feat/e2e-tests-and-empty-ns-fix into main
Reviewed-on: farhoodliquor/headlamp-polaris-plugin#19
2026-02-07 19:17:11 -05:00
Chris Farhood 2298de9edd style: format polaris.ts for prettier
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 19:13:08 -05:00
Chris Farhood 39d85a3596 fix: drop :80 port suffix from service proxy URL for RBAC compatibility
When the proxy URL includes `:80`, Kubernetes checks the RBAC
resourceName as `polaris-dashboard:80` which doesn't match the
Role's resourceNames `["polaris-dashboard"]`. Dropping the port
suffix uses the service's default port and matches the RBAC correctly.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 19:11:03 -05:00
Chris Farhood 1421a159dd fix: remove unused import flagged by ESLint in PolarisSettings test
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 19:01:09 -05:00
Chris Farhood 186f9ef380 feat: add Playwright E2E smoke tests and fix empty namespace crash
Fix getNamespaces() to skip cluster-scoped resources (Namespace: "")
that caused Router.createRouteURL to throw TypeError on the Namespaces
page. Add Playwright E2E smoke tests with Authentik OIDC auth for CI
and K8s token fallback for local dev. Add Gitea Actions E2E workflow,
vitest unit test infrastructure, and test-utils fixtures.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 18:53:40 -05:00
gitea-actions[bot] 2a85f2a3d1 ci: update artifact hub metadata for v0.1.3 2026-02-07 19:51:35 +00:00
Chris Farhood c4e3c20a41 chore: bump version to 0.1.3
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 14:49:58 -05:00
Chris Farhood 50caae256d fix: skipped display, namespace link crash, overview redesign
- Fix skipped count showing empty by rendering as plain text instead
  of StatusLabel with empty status (which renders near-invisible)
- Fix namespace link crash by using Router.createRouteURL to generate
  cluster-prefixed URLs with react-router-dom Link, instead of
  Headlamp's Link component which crashes on plugin-registered routes
- Redesign overview page with PercentageCircle score chart and
  PercentageBar check distribution for a better visual experience

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 14:45:39 -05:00
Chris Farhood 3784b9b1c8 docs: update README for consolidated dashboard and current architecture
Remove references to deleted Full Audit page and DynamicSidebarRegistrar.
Add Namespaces page, skipped checks, test commands, and NamespacesListView
to project structure. Fix stale version numbers in install examples.
Consolidate CI/release docs to match single Gitea Actions workflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 14:35:30 -05:00
gitea-actions[bot] 6760841b22 ci: update artifact hub metadata for v0.1.2 2026-02-07 19:21:46 +00:00
Chris Farhood ce32783fe6 chore: bump version to 0.1.2
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 14:20:45 -05:00
Chris Farhood 3b0287bf19 Merge pull request 'feat: consolidate dashboard pages, fix namespace links, add tests' (#18) from feat/consolidate-dashboard-fix-namespace-links into main
Reviewed-on: farhoodliquor/headlamp-polaris-plugin#18
2026-02-07 14:20:00 -05:00
Chris Farhood 101b663867 style: fix prettier formatting in NamespacesListView
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 14:17:38 -05:00
Chris Farhood 6281dbfa5e feat: consolidate dashboard pages, fix namespace links, add tests
Merge Overview and Full Audit into a single dashboard page that always
shows the skipped check count. Fix namespace link 404s by using
Headlamp's Link component (which generates cluster-prefixed URLs)
instead of raw react-router-dom Link. Add vitest unit tests for all
polaris.ts utility functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 14:10:08 -05:00
gitea-actions[bot] 48c8ca04c0 ci: update artifact hub metadata for v0.1.1 2026-02-07 17:22:17 +00:00
Chris Farhood cc280034f6 chore: bump version to 0.1.1 and update architecture docs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 12:21:22 -05:00
Chris Farhood a2cbd8b496 Merge pull request 'feat: replace dynamic sidebar with namespaces list page' (#17) from feat/namespaces-list-view into main
Reviewed-on: farhoodliquor/headlamp-polaris-plugin#17
2026-02-07 12:19:50 -05:00
Chris Farhood b815ce165d feat: replace dynamic sidebar with namespaces list page
Headlamp's sidebar Collapse only opens when an item is selected via
route matching, so 3-level nesting (Polaris > Namespaces > ns) never
expanded. Replace the DynamicSidebarRegistrar with a dedicated
/polaris/namespaces route that shows a table of namespaces with
scores and clickable links to the detail views.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 12:15:04 -05:00
gitea-actions[bot] 4126439e52 ci: update artifact hub metadata for v0.1.0 2026-02-07 16:37:15 +00:00
Chris Farhood 49ed3ea7ff chore: bump version to 0.1.0 and fix release workflow race condition
Fetch latest main before pushing metadata update to prevent
non-fast-forward rejections when main moves during the release run.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 11:36:13 -05:00
Chris Farhood deafe68893 chore: bump version to 0.0.11
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 10:47:43 -05:00
Chris Farhood a6f30bf681 ci: update artifact hub metadata for v0.0.10
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 10:46:42 -05:00
Chris Farhood 9df30c3943 docs: address review feedback on dashboard.enabled wording
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 10:35:51 -05:00
Chris Farhood cc3cc81af9 docs: add service proxy RBAC/security requirements and update outdated docs
The README, CLAUDE.md, and artifacthub-pkg.yml all referenced the old
ConfigMap-based data source. Updated to document the actual Kubernetes
service proxy path, the correct RBAC Role/RoleBinding (services/proxy
get), and added sections for token-auth mode, NetworkPolicy, audit
logging, and troubleshooting. Also updated the project structure and
feature descriptions to match the current codebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 10:25:59 -05:00
Chris Farhood d5ab99116c chore: bump version to 0.0.10
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 09:53:22 -05:00
Chris Farhood 5e330798e1 Merge pull request 'feat: restructure sidebar hierarchy and add full audit view' (#15) from feat/sidebar-restructure-dashboard-views into main
Reviewed-on: farhoodliquor/headlamp-polaris-plugin#15
2026-02-07 09:52:49 -05:00
Chris Farhood 1559a9ffcd feat: restructure sidebar hierarchy and add full audit view
Reorganize the sidebar into a proper hierarchy (Overview, Full Audit,
Namespaces) and add a Full Audit dashboard view that includes skipped
checks. Namespace routes move to /polaris/ns/:namespace to avoid
path collisions, and namespace detail pages now link out to the
Polaris dashboard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 09:50:28 -05:00
gitea-actions[bot] bea7eaa67b ci: update artifact hub metadata for v0.0.9 2026-02-07 13:46:45 +00:00
Chris Farhood 9a1d7f961f chore: bump version to 0.0.9
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 08:45:43 -05:00
Chris Farhood e6e2aa63a5 Merge pull request 'docs: update ArtifactHub URLs in README' (#14) from fix/readme-artifacthub-urls into main
Reviewed-on: farhoodliquor/headlamp-polaris-plugin#14
Reviewed-by: Chris Farhood <cpfarhood@noreply.git.farh.net>
2026-02-07 08:45:14 -05:00
Chris Farhood dab068a963 refactor: rename npm package to headlamp-polaris-plugin
Aligns npm package name with the repo and ArtifactHub package name.
Updates all references: package.json, registerPluginSettings, Dockerfile,
release workflow tarball URLs, artifacthub-pkg.yml archive-url, and README.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 08:43:55 -05:00
Chris Farhood 244714316f docs: update ArtifactHub URLs to match new package name
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 08:43:43 -05:00
gitea-actions[bot] b1fa087011 ci: update artifact hub metadata for v0.0.8 2026-02-07 13:03:11 +00:00
Chris Farhood bfe926546b chore: bump version to 0.0.8
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 08:02:03 -05:00
Chris Farhood dccc393857 Merge pull request 'fix: correct ArtifactHub package name and checksum' (#13) from fix/artifacthub-package-name into main
Reviewed-on: farhoodliquor/headlamp-polaris-plugin#13
2026-02-07 13:01:29 +00:00
Chris Farhood f414dafa28 fix: correct ArtifactHub package name and release checksum
Rename package from polaris-headlamp-plugin to headlamp-polaris-plugin
so the ArtifactHub URL becomes /headlamp/polaris/headlamp-polaris-plugin.
Also fix the archive checksum to match the actual v0.0.7 tarball on GitHub.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 07:59:35 -05:00
gitea-actions[bot] 6e914ad71f ci: update artifact hub metadata for v0.0.7 2026-02-07 05:11:57 +00:00
Chris Farhood d923e655fe fix: correct GitHub API URLs in release workflow
Two GitHub API URLs still had the old repo name (polaris-headlamp-plugin
instead of headlamp-polaris-plugin), causing the GitHub release step to
target the wrong repository.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 00:10:02 -05:00
gitea-actions[bot] a1ef628fb5 ci: update artifact hub metadata for v0.0.7 2026-02-07 04:58:47 +00:00
Chris Farhood b8129a0dbb chore: bump version to 0.0.7
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 23:57:44 -05:00
Chris Farhood 7facb9be10 Merge pull request 'feat: add per-namespace detail pages with sidebar sub-items' (#12) from feature/polaris-detail-view into main
Reviewed-on: farhoodliquor/headlamp-polaris-plugin#12
2026-02-07 04:42:22 +00:00
Chris Farhood 1b86407d8b refactor: precompute resource counts and add return type annotation
Avoid recalculating per-resource counts 3x per table row by precomputing
them into a Map. Add explicit ResultCounts return type to resourceCounts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 23:38:10 -05:00
Chris Farhood 40df014b6b style: fix import sorting and prettier formatting
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 23:30:22 -05:00
Chris Farhood b217a8119e feat: add per-namespace detail pages with dynamic sidebar sub-items
Add drill-down namespace views under the Polaris sidebar entry. Each
namespace gets a sidebar sub-item registered dynamically from audit data,
linking to /polaris/:namespace with a score summary and per-resource table.

Introduces a shared PolarisDataContext so the sidebar registrar and view
components share a single data fetch. Also updates the Artifact Hub
repository ID.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 23:09:40 -05:00
Chris Farhood 818f4bc9cb chore: update repo URLs after rename to headlamp-polaris-plugin
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 22:21:05 -05:00
gitea-actions[bot] a6a1280e4f ci: update artifact hub metadata for v0.0.6 2026-02-07 03:03:21 +00:00
Chris Farhood 7351d88997 chore: bump version to 0.0.6
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 22:02:05 -05:00
Chris Farhood 071aab4f7e Merge pull request 'fix: use native Headlamp components for consistent styling' (#11) from fix/native-headlamp-styling into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#11
2026-02-07 03:01:18 +00:00
Chris Farhood 40544429f4 fix: remove tarball from repo and gitignore *.tar.gz
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 22:00:15 -05:00
Chris Farhood 1f110a2846 style: fix prettier formatting
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 21:59:16 -05:00
Chris Farhood 672caec903 ci: add build step to CI workflow
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 21:56:13 -05:00
Chris Farhood b10d09fd41 feat: move refresh interval to plugin settings
Register plugin settings via registerPluginSettings so the refresh
interval is configurable from Headlamp's plugin config page instead
of being embedded in the main view header.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 21:55:13 -05:00
Chris Farhood 8b319c0c8a fix: use native Headlamp components for consistent styling
Replace inline-styled divs and native HTML elements with Headlamp's
built-in NameValueTable, StatusLabel, and HeaderLabel components so the
plugin matches the look and feel of native pages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 21:49:17 -05:00
Chris Farhood 57250a995d ci: update artifact hub checksum for v0.0.5
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 21:22:42 -05:00
Chris Farhood 702be12fc8 chore: bump version to 0.0.5
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 21:14:00 -05:00
Chris Farhood 95aaaa96bd Merge pull request 'feat: query Polaris dashboard API instead of ConfigMap' (#10) from feat/polaris-api-datasource into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#10
2026-02-07 02:11:22 +00:00
Chris Farhood b891b3a624 docs: update CLAUDE.md to reflect API proxy data source
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 21:10:00 -05:00
Chris Farhood 7997eb29fa feat: query Polaris dashboard API instead of ConfigMap
The plugin now fetches audit data from the Polaris dashboard service
via the Kubernetes service proxy instead of reading from a ConfigMap.
This works with the standard Polaris dashboard deployment without
requiring additional configuration.

- Replace ConfigMap.useGet with ApiProxy.request to /results.json
- Compute score from result counts (pass/total) since the API
  response doesn't include a pre-computed score
- Update error messages for service proxy context
- Update CLAUDE.md to reflect new data source

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 20:50:07 -05:00
Chris Farhood 9885dc44c0 Merge pull request 'chore: add AI code review workflow for PRs' (#9) from chore/add-ai-review into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#9
2026-02-06 22:21:35 +00:00
Chris Farhood 72998cfbca fix: add container image for ai-review workflow
The default gitea/act_runner image has no Node.js, which actions/checkout@v4
requires. Use catthehacker/ubuntu:act-latest like the kubernetes repo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 17:18:07 -05:00
Chris Farhood 6f7217f400 chore: add AI code review workflow for PRs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 17:15:50 -05:00
gitea-actions[bot] 8b8c447983 ci: update artifact hub metadata for v0.0.4 2026-02-06 21:57:57 +00:00
Chris Farhood 7b794f540f Merge pull request 'chore: bump version to 0.0.4' (#8) from release/v0.0.4 into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#8
2026-02-06 21:55:13 +00:00
Chris Farhood 0f00fd2f29 chore: bump version to 0.0.4
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 16:54:24 -05:00
Chris Farhood f95a74c6ae Merge pull request 'fix: include package.json in Docker plugin directory' (#7) from fix/dockerfile-package-json into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#7
2026-02-06 21:53:57 +00:00
Chris Farhood 60fc377442 fix: include package.json in Docker plugin directory
Headlamp's plugin discovery requires both main.js and package.json in
the plugin directory. The Dockerfile only copied dist/ (main.js),
causing the plugin to not be discovered at runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 16:43:56 -05:00
Chris Farhood dd3e877580 Merge pull request 'chore: add linting, formatting, and type-checking' (#6) from chore/add-linting-formatting into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#6
2026-02-06 21:39:37 +00:00
Chris Farhood da1ef7e0c3 chore: add linting, formatting, and type-checking
Add ESLint, Prettier, and TypeScript config files extending the shared
Headlamp plugin configs. Add npm scripts for lint/format. Auto-fix
existing source files. Add CI workflow for PRs and main pushes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 16:35:42 -05:00
gitea-actions[bot] 39878f63cc ci: update artifact hub metadata for v0.0.3 2026-02-06 21:01:11 +00:00
Chris Farhood 374e2f5b57 Merge pull request 'chore: bump version to 0.0.3' (#5) from release/v0.0.3 into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#5
2026-02-06 20:58:43 +00:00
Chris Farhood 581219ceae chore: bump version to 0.0.3
AH doesn't re-process existing versions when a tag is force-moved,
so v0.0.2 is permanently stuck with a stale checksum. Releasing v0.0.3
so AH indexes it as a new version with the correct checksum from the
aligned tag.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 15:57:41 -05:00
gitea-actions[bot] 1b905d2bc6 ci: update artifact hub metadata for v0.0.2 2026-02-06 19:33:13 +00:00
Chris Farhood 43b284a0f4 Merge pull request 'fix: align tag with metadata after release' (#4) from fix/release-tag-alignment into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#4
2026-02-06 19:29:58 +00:00
Chris Farhood f54795f34f fix: align tag with metadata after release to solve AH checksum mismatch
The CI builds a non-reproducible tarball after the tag is created, then
updates artifacthub-pkg.yml on main with the correct checksum. But
Artifact Hub reads from the tag ref, not main, so it sees the stale
checksum and Headlamp rejects the plugin with "Checksum mismatch".

Changes:
- Add guard step: if the GitHub release tarball checksum already matches
  the metadata in the current commit, skip the entire build (prevents
  infinite retrigger loop)
- After updating metadata on main, force-move the tag to that commit
  so AH reads the correct checksum
- Push main + tag directly to GitHub to avoid mirror sync delay
- Replace akkuman/gitea-release-action with curl-based approach so all
  steps use the same shell guard pattern

Release flow: tag push -> build -> publish releases -> update metadata
on main -> force-move tag -> (retriggered run hits guard -> exits)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 14:20:03 -05:00
gitea-actions[bot] be75ff55d4 ci: update artifact hub metadata for v0.0.2 2026-02-06 19:09:59 +00:00
gitea-actions[bot] 25a093c131 ci: update artifact hub metadata for v0.0.2 2026-02-06 15:26:58 +00:00
Chris Farhood ed9afd02d6 Merge pull request 'fix: remove GitHub Actions workflow to eliminate release race' (#3) from fix/remove-github-ci-race into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#3
2026-02-06 14:46:27 +00:00
Chris Farhood 2dabb1c731 fix: remove GitHub Actions workflow and handle existing release assets
The GitHub Actions fallback workflow raced with the Gitea CI — it ran
first and created the GitHub release with its own tarball (different
checksum), causing the Gitea CI's upload to fail and leaving a
checksum mismatch on Artifact Hub.

- Remove .github/workflows/release.yml entirely (Gitea CI handles both
  Gitea and GitHub releases)
- Fix the Gitea CI's GitHub release step to delete existing assets
  before uploading, so re-runs and race conditions are handled gracefully

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 09:02:19 -05:00
gitea-actions[bot] 8941f9ac16 ci: update artifact hub metadata for v0.0.2 2026-02-06 13:19:36 +00:00
Chris Farhood 4810893440 Merge pull request 'fix: use git push instead of Gitea API for checksum update' (#2) from fix/ci-use-git-push into main
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#2
2026-02-06 13:18:31 +00:00
Chris Farhood e37904a377 fix: use git push instead of Gitea API for checksum update
The Gitea Contents API returned HTTP error (curl exit 22) when the CI
tried to update artifacthub-pkg.yml. Switch to using git checkout/commit/push
which reuses the auth already configured by actions/checkout. Also added
fetch-depth: 0 so the main branch is available for checkout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 08:16:51 -05:00
claude e16776d5f1 fix: correct archive checksum and automate CI updates (#1)
## Summary
- Fix the v0.0.1 archive checksum in `artifacthub-pkg.yml` to match the actual GitHub release tarball (was causing "Checksum mismatch" on Headlamp plugin install)
- Gitea CI now computes the checksum after packaging and updates `artifacthub-pkg.yml` on `main` via the Gitea API, then uploads the **same tarball** to GitHub releases (requires `GH_PAT` secret) so both releases serve identical artifacts
- GitHub CI becomes a fallback — skips entirely if the Gitea CI already created the release, preventing a second build from producing a mismatched tarball

## Setup required
Add a `GH_PAT` secret to the Gitea repo containing a GitHub personal access token with `repo` scope. Without it, the GitHub release step gracefully skips and the GitHub Actions fallback handles it.

## Test plan
- [ ] Verify `GH_PAT` secret is set in Gitea repo settings
- [ ] Tag and push a new release (`v0.0.2`)
- [ ] Confirm Gitea CI updates `artifacthub-pkg.yml` checksum on `main`
- [ ] Confirm GitHub release is created by Gitea CI with matching tarball
- [ ] Confirm GitHub Actions fallback skips (release already exists)
- [ ] Verify Headlamp plugin installs without checksum mismatch

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Chris Farhood <chris@farhood.org>
Reviewed-on: farhoodliquor/polaris-headlamp-plugin#1
Co-authored-by: claude <no-reply.claude@farh.net>
Co-committed-by: claude <no-reply.claude@farh.net>
2026-02-06 13:13:44 +00:00
Chris Farhood 2ad61e90cc feat: add Artifact Hub metadata and GitHub Actions release workflow
Artifact Hub requires a GitHub-hosted repo for Headlamp plugins.
Since Gitea push-mirrors git objects but not releases, a GitHub
Actions workflow builds and publishes GitHub Releases with the
tarball that Artifact Hub needs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-05 17:58:00 -05:00
Chris Farhood dd330f1c14 docs: add comprehensive README with setup, deploy, and release instructions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-05 16:45:33 -05:00
36 changed files with 2768 additions and 279 deletions
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@headlamp-k8s/eslint-config'],
};
+36
View File
@@ -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 }}
+30
View File
@@ -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/
+28
View File
@@ -0,0 +1,28 @@
name: E2E
on:
push:
branches:
- main
pull_request:
jobs:
e2e:
runs-on: ubuntu-latest
container: node:20
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: npm ci
- name: Install Chromium
run: npx playwright install --with-deps chromium
- name: Run E2E smoke tests
env:
HEADLAMP_URL: https://headlamp.animaniacs.farh.net
AUTHENTIK_USERNAME: ${{ secrets.AUTHENTIK_USERNAME }}
AUTHENTIK_PASSWORD: ${{ secrets.AUTHENTIK_PASSWORD }}
run: npx playwright test
+158 -15
View File
@@ -12,31 +12,174 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if release is already finalized
run: |
VERSION=${GITHUB_REF_NAME#v}
TARBALL_URL="https://github.com/cpfarhood/headlamp-polaris-plugin/releases/download/${GITHUB_REF_NAME}/headlamp-polaris-plugin-${VERSION}.tar.gz"
HTTP_CODE=$(curl -sL -o /tmp/release.tar.gz -w "%{http_code}" "$TARBALL_URL" 2>/dev/null)
if [ "$HTTP_CODE" = "200" ]; then
ACTUAL="sha256:$(sha256sum /tmp/release.tar.gz | awk '{print $1}')"
EXPECTED=$(grep 'archive-checksum' artifacthub-pkg.yml | awk '{print $2}')
echo "Release tarball checksum: $ACTUAL"
echo "Metadata checksum: $EXPECTED"
if [ "$ACTUAL" = "$EXPECTED" ]; then
echo "SKIP_BUILD=true" >> $GITHUB_ENV
echo "Checksums match - release is finalized, nothing to do"
fi
else
echo "No existing release (HTTP $HTTP_CODE) - will build"
fi
rm -f /tmp/release.tar.gz
- name: Install dependencies
run: npm ci
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
npm ci
- name: Build plugin
run: npx @kinvolk/headlamp-plugin build
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
npx @kinvolk/headlamp-plugin build
- name: Package tarball
run: npx @kinvolk/headlamp-plugin package
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
npx @kinvolk/headlamp-plugin package
- name: Compute tarball checksum
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
TARBALL=$(ls *.tar.gz)
CHECKSUM=$(sha256sum "$TARBALL" | awk '{print $1}')
echo "TARBALL=$TARBALL" >> $GITHUB_ENV
echo "CHECKSUM=$CHECKSUM" >> $GITHUB_ENV
echo "Tarball: $TARBALL"
echo "Checksum: sha256:$CHECKSUM"
- name: Install Docker CLI
run: apt-get update && apt-get install -y docker.io
- name: Build Docker image
run: docker build -t git.farh.net/${{ github.repository }}:${{ github.ref_name }} -t git.farh.net/${{ github.repository }}:latest .
- name: Push Docker image
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
apt-get update && apt-get install -y docker.io
- name: Build and push Docker image
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
docker build -t git.farh.net/${{ github.repository }}:${{ github.ref_name }} -t git.farh.net/${{ github.repository }}:latest .
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.farh.net -u ${{ github.actor }} --password-stdin
docker push git.farh.net/${{ github.repository }}:${{ github.ref_name }}
docker push git.farh.net/${{ github.repository }}:latest
- name: Create release
uses: akkuman/gitea-release-action@v1
with:
files: |
*.tar.gz
token: ${{ github.token }}
- name: Create Gitea release
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
API_URL="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
# Create release (or get existing)
RELEASE=$(curl -s -X POST \
-H "Authorization: token ${{ github.token }}" \
-H "Content-Type: application/json" \
"${API_URL}/releases" \
-d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"${GITHUB_REF_NAME}\"}")
RELEASE_ID=$(echo "$RELEASE" | node -e "process.stdin.resume();let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>console.log(JSON.parse(d).id))")
if [ "$RELEASE_ID" = "undefined" ]; then
RELEASE=$(curl -sf \
-H "Authorization: token ${{ github.token }}" \
"${API_URL}/releases/tags/${GITHUB_REF_NAME}")
RELEASE_ID=$(echo "$RELEASE" | node -e "process.stdin.resume();let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>console.log(JSON.parse(d).id))")
fi
echo "Gitea Release ID: $RELEASE_ID"
# Delete existing assets
ASSETS=$(curl -sf \
-H "Authorization: token ${{ github.token }}" \
"${API_URL}/releases/${RELEASE_ID}/assets")
echo "$ASSETS" | node -e "
process.stdin.resume();let d='';
process.stdin.on('data',c=>d+=c);
process.stdin.on('end',()=>{
JSON.parse(d).forEach(a=>console.log(a.id));
})" | while read -r ASSET_ID; do
curl -sf -X DELETE \
-H "Authorization: token ${{ github.token }}" \
"${API_URL}/releases/${RELEASE_ID}/assets/${ASSET_ID}"
done
# Upload tarball
curl -sf -X POST \
-H "Authorization: token ${{ github.token }}" \
-F "attachment=@${TARBALL}" \
"${API_URL}/releases/${RELEASE_ID}/assets?name=${TARBALL}"
echo "Gitea release updated"
- name: Create GitHub release
continue-on-error: true
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
GH_API="https://api.github.com/repos/cpfarhood/headlamp-polaris-plugin"
# Create release or fetch existing one
BODY=$(curl -s -X POST \
-H "Authorization: token ${{ secrets.GH_PAT }}" \
-H "Accept: application/vnd.github+json" \
"${GH_API}/releases" \
-d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"${GITHUB_REF_NAME}\",\"generate_release_notes\":true}")
RELEASE_ID=$(echo "$BODY" | node -e "process.stdin.resume();let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>console.log(JSON.parse(d).id))")
if [ "$RELEASE_ID" = "undefined" ]; then
echo "Release already exists, fetching it..."
BODY=$(curl -sf \
-H "Authorization: token ${{ secrets.GH_PAT }}" \
-H "Accept: application/vnd.github+json" \
"${GH_API}/releases/tags/${GITHUB_REF_NAME}")
RELEASE_ID=$(echo "$BODY" | node -e "process.stdin.resume();let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>console.log(JSON.parse(d).id))")
fi
echo "GitHub Release ID: $RELEASE_ID"
# Delete existing assets with the same name
ASSETS=$(curl -sf \
-H "Authorization: token ${{ secrets.GH_PAT }}" \
-H "Accept: application/vnd.github+json" \
"${GH_API}/releases/${RELEASE_ID}/assets")
echo "$ASSETS" | node -e "
process.stdin.resume();let d='';
process.stdin.on('data',c=>d+=c);
process.stdin.on('end',()=>{
const assets=JSON.parse(d);
assets.filter(a=>a.name==='${TARBALL}').forEach(a=>console.log(a.id));
})" | while read -r ASSET_ID; do
echo "Deleting existing asset $ASSET_ID..."
curl -sf -X DELETE \
-H "Authorization: token ${{ secrets.GH_PAT }}" \
"${GH_API}/releases/assets/${ASSET_ID}"
done
# Upload tarball
curl -sf -X POST \
-H "Authorization: token ${{ secrets.GH_PAT }}" \
-H "Content-Type: application/gzip" \
"https://uploads.github.com/repos/cpfarhood/headlamp-polaris-plugin/releases/${RELEASE_ID}/assets?name=${TARBALL}" \
--data-binary "@${TARBALL}"
echo "GitHub release updated with same tarball"
- name: Update metadata and align tag
run: |
[ "$SKIP_BUILD" = "true" ] && exit 0
VERSION=${GITHUB_REF_NAME#v}
git config user.name "gitea-actions[bot]"
git config user.email "gitea-actions[bot]@git.farh.net"
git fetch origin main
git checkout origin/main -B main
sed -i "s|headlamp/plugin/archive-checksum:.*|headlamp/plugin/archive-checksum: sha256:${CHECKSUM}|" artifacthub-pkg.yml
sed -i "s|headlamp/plugin/archive-url:.*|headlamp/plugin/archive-url: \"https://github.com/cpfarhood/headlamp-polaris-plugin/releases/download/${GITHUB_REF_NAME}/headlamp-polaris-plugin-${VERSION}.tar.gz\"|" artifacthub-pkg.yml
sed -i "s|^version:.*|version: ${VERSION}|" artifacthub-pkg.yml
git add artifacthub-pkg.yml
git diff --cached --quiet || {
git commit -m "ci: update artifact hub metadata for ${GITHUB_REF_NAME}"
git push origin main
}
# Force-move tag to the commit with correct checksum.
# This triggers a new CI run, but the guard step will detect
# that the release checksum already matches and skip the build.
git tag -f ${GITHUB_REF_NAME}
git push -f origin ${GITHUB_REF_NAME}
# Also push to GitHub directly to avoid waiting for mirror sync
git remote add github https://x-access-token:${{ secrets.GH_PAT }}@github.com/cpfarhood/headlamp-polaris-plugin.git 2>/dev/null || true
git push github main 2>/dev/null || true
git push -f github ${GITHUB_REF_NAME} 2>/dev/null || true
echo "Tag ${GITHUB_REF_NAME} aligned with updated metadata"
+4
View File
@@ -2,3 +2,7 @@ node_modules/
dist/
.headlamp-plugin/
.mcp.json
*.tar.gz
e2e/.auth/
test-results/
.playwright-mcp/
+1
View File
@@ -0,0 +1 @@
module.exports = require('@headlamp-k8s/eslint-config/prettier-config');
+2 -1
View File
@@ -6,4 +6,5 @@ COPY src/ src/
RUN npx @kinvolk/headlamp-plugin build
FROM alpine:3.20
COPY --from=build /app/dist/ /plugins/polaris-headlamp-plugin/
COPY --from=build /app/dist/ /plugins/headlamp-polaris-plugin/
COPY --from=build /app/package.json /plugins/headlamp-polaris-plugin/
+286
View File
@@ -0,0 +1,286 @@
# headlamp-polaris-plugin
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/polaris)](https://artifacthub.io/packages/headlamp/polaris/headlamp-polaris-plugin)
A [Headlamp](https://headlamp.dev/) plugin that surfaces [Fairwinds Polaris](https://polaris.docs.fairwinds.com/) audit results directly in the Headlamp UI.
## What It Does
Adds a **Polaris** top-level sidebar section to Headlamp with the following views:
- **Overview** -- cluster score as a percentage (color-coded green/amber/red), check summary (pass/warning/danger/skipped counts), and cluster info (nodes, pods, namespaces, controllers)
- **Namespaces** -- table of all namespaces with per-namespace score, pass/warning/danger/skipped counts; click a namespace to drill down
- **Namespace detail** -- per-namespace score, check counts, and a resource table showing pass/warning/danger per workload
- **External link** -- quick jump to the native Polaris dashboard via the Kubernetes service proxy (from namespace detail view)
Data is fetched from the Polaris dashboard API through the Kubernetes service proxy (`/api/v1/namespaces/polaris/services/polaris-dashboard/proxy/results.json`). The plugin is read-only -- it never writes to the cluster.
Results are refreshed on a user-configurable interval (1 / 5 / 10 / 30 minutes, default 5). The setting is available in **Settings > Plugins > Polaris** and persists in the browser's localStorage.
Error states are handled explicitly: RBAC denied (403), Polaris not installed (404/503), malformed JSON, and loading.
## Prerequisites
| Requirement | Minimum version |
|-------------|----------------|
| Headlamp | v0.26+ |
| Polaris (with dashboard enabled) | Any recent release |
| Kubernetes | v1.24+ |
Polaris must be deployed in the `polaris` namespace with the dashboard component enabled (`dashboard.enabled: true` in the Helm chart, which is the default). The plugin reads from the `polaris-dashboard` ClusterIP service on port 80.
## Installing
### Option 1: Artifact Hub + Headlamp plugin manager (recommended)
The plugin is published on [Artifact Hub](https://artifacthub.io/packages/headlamp/polaris/headlamp-polaris-plugin). Configure Headlamp's `pluginsManager` in your Helm values to install it automatically:
```yaml
pluginsManager:
sources:
- url: https://artifacthub.io/packages/headlamp/polaris/headlamp-polaris-plugin
```
Headlamp will fetch and install the plugin on startup.
### Option 2: Docker init container
The plugin ships as a container image at `git.farh.net/farhoodliquor/headlamp-polaris-plugin`.
Add it as an init container in your Headlamp Helm values:
```yaml
initContainers:
- name: polaris-plugin
image: git.farh.net/farhoodliquor/headlamp-polaris-plugin:latest
command: ["sh", "-c", "cp -r /plugins/* /headlamp/plugins/"]
volumeMounts:
- name: plugins
mountPath: /headlamp/plugins
volumes:
- name: plugins
emptyDir: {}
volumeMounts:
- name: plugins
mountPath: /headlamp/plugins
```
### Option 3: Manual tarball install
Download the `.tar.gz` from the [GitHub releases page](https://github.com/cpfarhood/headlamp-polaris-plugin/releases) or the [Gitea releases page](https://git.farh.net/farhoodliquor/headlamp-polaris-plugin/releases), then extract into Headlamp's plugin directory:
```bash
tar xzf headlamp-polaris-plugin-<version>.tar.gz -C /headlamp/plugins/
```
### Option 4: Build from source
```bash
npm install
npm run build
npx @kinvolk/headlamp-plugin extract . /headlamp/plugins
```
## RBAC / Security Setup
The plugin fetches audit data through the Kubernetes API server's **service proxy** sub-resource. The identity making the request (Headlamp's service account, or the user's own token in token-auth mode) must be granted:
| Verb | API Group | Resource | Resource Name | Namespace |
|------|-----------|----------|---------------|-----------|
| `get` | `""` (core) | `services/proxy` | `polaris-dashboard` | `polaris` |
### Minimal RBAC manifests
```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: polaris-proxy-reader
namespace: polaris
rules:
- apiGroups: [""]
resources: ["services/proxy"]
resourceNames: ["polaris-dashboard"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: headlamp-polaris-proxy
namespace: polaris
subjects:
- kind: ServiceAccount
name: headlamp # adjust to match your Headlamp service account
namespace: kube-system # adjust to match the namespace Headlamp runs in
roleRef:
kind: Role
name: polaris-proxy-reader
apiGroup: rbac.authorization.k8s.io
```
Apply with `kubectl apply -f polaris-rbac.yaml`.
### Token-auth mode
When Headlamp is configured for user-supplied tokens (rather than a fixed service account), **each user** must have the RoleBinding above attached to their own identity. A 403 error in the plugin means the currently logged-in user lacks this binding.
### NetworkPolicy
If the `polaris` namespace enforces network policies, ensure ingress is allowed from the Kubernetes API server (which performs the proxy hop) to `polaris-dashboard` on port 80.
### Read-only access
The plugin only performs `GET` requests through the service proxy. No `create`, `update`, `delete`, or `patch` verbs are required. Do not grant broader access than `get` on `services/proxy`.
### Audit logging
Every proxied request is recorded in Kubernetes API audit logs as a `get` on `services/proxy` in the `polaris` namespace. If the auto-refresh interval generates more audit volume than desired, increase the refresh interval in the plugin settings or adjust your audit policy.
## Troubleshooting
| Symptom | Likely cause | Fix |
|---------|-------------|-----|
| **403 Access Denied** | Missing RBAC binding for `services/proxy` | Apply the Role + RoleBinding from the RBAC section above |
| **404 or 503** | Polaris not installed, or dashboard disabled | Install Polaris with `dashboard.enabled: true` in the `polaris` namespace |
| **No data** | Polaris running but no workloads scanned yet | Wait for the next Polaris audit cycle or restart the Polaris pod |
| **Stale data** | Refresh interval too long | Lower the interval in **Settings > Plugins > Polaris** |
## Development
### Setup
```bash
git clone https://github.com/cpfarhood/headlamp-polaris-plugin.git
cd headlamp-polaris-plugin
npm install
```
### Run locally (hot reload)
```bash
npm start
```
This starts the Headlamp plugin dev server. Point a running Headlamp instance at the dev server to see changes live.
### Build for production
```bash
npm run build # outputs dist/main.js
npm run package # creates headlamp-polaris-plugin-<version>.tar.gz
```
### Type-check, lint, format, and test
```bash
npm run tsc # type-check without emitting
npm run lint # eslint
npm run format:check # prettier check
npm test # vitest unit tests
```
## Project Structure
```
src/
index.tsx -- Entry point. Registers sidebar entries and routes.
api/
polaris.ts -- TypeScript types (AuditData schema), usePolarisData hook,
countResults utilities, refresh interval settings.
polaris.test.ts -- Unit tests for utility functions (vitest).
PolarisDataContext.tsx -- React context provider; shared data fetch across views.
components/
DashboardView.tsx -- Overview page (score, check summary with skipped, cluster info).
NamespacesListView.tsx -- Namespace list with scores and links to detail views.
NamespaceDetailView.tsx -- Per-namespace drill-down with resource table.
PolarisSettings.tsx -- Plugin settings page (refresh interval selector).
vitest.config.mts -- Vitest configuration (jsdom environment).
```
## Data Source
The plugin fetches live audit results from the Polaris dashboard HTTP API via the Kubernetes service proxy:
```
GET /api/v1/namespaces/polaris/services/polaris-dashboard/proxy/results.json
```
This endpoint is served by the `polaris-dashboard` ClusterIP service, which is created by the Polaris Helm chart when `dashboard.enabled: true`. The JSON response matches Polaris's `AuditData` schema (`pkg/validator/output.go`):
```
AuditData
ClusterInfo -- nodes, pods, namespaces, controllers
Results[] -- per-workload results
Results{} -- top-level check results (ResultSet)
PodResult
Results{} -- pod-level check results
ContainerResults[]
Results{} -- container-level check results
```
Each check in a `ResultSet` has `Success` (bool) and `Severity` (`"warning"`, `"danger"`, or `"ignore"`). Checks with `Severity: "ignore"` and `Success: false` are counted as skipped. The cluster score is computed client-side as `pass / total * 100`.
## Known Limitations
### Skipped Count and Annotation-Based Exemptions
The **Skipped** count shown in the plugin only reflects checks with `Severity: "ignore"` in the Polaris API response. It does **not** include annotation-based exemptions (e.g., `polaris.fairwinds.com/privilegeEscalationAllowed-exempt: "true"`).
**Why?** Polaris completely omits exempted checks from the `results.json` endpoint. The native Polaris dashboard UI computes the "skipped" count client-side by:
1. Querying Kubernetes resources (Deployments, DaemonSets, StatefulSets, Pods) directly
2. Parsing their annotations for `polaris.fairwinds.com/*-exempt` keys
3. Counting how many checks were exempted
This plugin only has access to the processed audit results via the service proxy and does not query raw Kubernetes resources. To show accurate exemption counts, the plugin would need to:
- Request cluster-wide read access to all workload types (requires additional RBAC grants beyond `services/proxy`)
- Parse annotations on every workload in every namespace
- Cross-reference with the Polaris check catalog to count exemptions
This is a significant architectural change and is not currently implemented. Hover over the "Skipped" count in the UI to see a tooltip explaining this limitation.
**Workaround:** Use the "View in Polaris Dashboard" link from any namespace detail view to see the full exemption count in the native dashboard.
## Releasing
Releases are automated via CI. To cut a release:
```bash
# Bump version in package.json and artifacthub-pkg.yml (version + archive-url), then:
git add package.json artifacthub-pkg.yml
git commit -m "chore: bump version to X.Y.Z"
git tag vX.Y.Z
git push origin main vX.Y.Z
```
This triggers the **Gitea Actions** release workflow (`.gitea/workflows/release.yaml`):
1. Build the plugin in a `node:20` container
2. Package a `.tar.gz` tarball
3. Build and push a Docker image to `git.farh.net/farhoodliquor/headlamp-polaris-plugin:{tag}` and `:latest`
4. Create a Gitea release with the tarball attached
5. Create a GitHub release with the same tarball (for Artifact Hub)
6. Update `artifacthub-pkg.yml` checksum on main and force-move the tag to match
A guard step prevents infinite loops: if the release tarball checksum already matches the metadata, the build is skipped.
### CI secrets
| Secret | Where | Purpose |
|---|---|---|
| `REGISTRY_TOKEN` | Gitea | Personal access token with `package:write` scope for Docker image push |
| `GH_PAT` | Gitea | GitHub personal access token for creating GitHub releases |
The Gitea release uses the built-in `github.token`. The `archive-checksum` in `artifacthub-pkg.yml` is updated automatically by the release workflow.
## Links
- [Artifact Hub](https://artifacthub.io/packages/headlamp/polaris/headlamp-polaris-plugin)
- [GitHub (mirror)](https://github.com/cpfarhood/headlamp-polaris-plugin)
- [Gitea (source of truth)](https://git.farh.net/farhoodliquor/headlamp-polaris-plugin)
- [Headlamp](https://headlamp.dev/)
- [Fairwinds Polaris](https://polaris.docs.fairwinds.com/)
## License
MIT
+34
View File
@@ -0,0 +1,34 @@
version: 0.2.0-dev.2
name: headlamp-polaris-plugin
displayName: Polaris
createdAt: "2026-02-05T19:00:00Z"
description: >-
Surfaces Fairwinds Polaris audit results inside the Headlamp UI.
Shows cluster score, check summary, and per-namespace drill-downs
with per-resource pass/warning/danger breakdowns. Data is fetched
read-only via the Kubernetes service proxy to the Polaris dashboard.
Requires a Role granting `get` on `services/proxy` for the
`polaris-dashboard` service in the `polaris` namespace.
license: MIT
homeURL: "https://github.com/cpfarhood/headlamp-polaris-plugin"
category: security
keywords:
- polaris
- fairwinds
- security
- audit
- headlamp
- kubernetes
links:
- name: Source
url: "https://github.com/cpfarhood/headlamp-polaris-plugin"
- name: Polaris
url: "https://polaris.docs.fairwinds.com/"
maintainers:
- name: cpfarhood
email: "chris@farhood.org"
annotations:
headlamp/plugin/archive-url: "https://github.com/cpfarhood/headlamp-polaris-plugin/releases/download/v0.2.0-dev.2/headlamp-polaris-plugin-0.2.0-dev.2.tar.gz"
headlamp/plugin/version-compat: ">=0.26"
headlamp/plugin/archive-checksum: sha256:ffd430bfc5262fb592ecd8eb0f0d5d04e04845468737c5e4704dfe7cc7522963
headlamp/plugin/distro-compat: in-cluster
+3 -3
View File
@@ -1,4 +1,4 @@
repositoryID: polaris-headlamp-plugin
repositoryID: fc3397f6-a75a-4950-ab50-da75c08a8089
owners:
- name: farhoodliquor
email: ""
- name: cpfarhood
email: "chris@farhood.org"
+61 -6
View File
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## 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/proxy/results.json`). Target Headlamp ≥ v0.26.
## Build & Development Commands
@@ -23,24 +23,79 @@ npx tsc --noEmit
# Lint
npx eslint src/
# Run tests
npm test
```
## Architecture
```
src/
├── index.tsx # Entry point: registerSidebarEntry + registerRoute for /polaris
├── index.tsx # Entry point: registers sidebar entries + routes
├── api/
── polaris.ts # Types (AuditData schema), usePolarisData hook, countResults utility, refresh settings
── polaris.ts # Types (AuditData schema), usePolarisData hook, countResults utilities, refresh settings
│ ├── polaris.test.ts # Unit tests for utility functions (vitest)
│ └── PolarisDataContext.tsx # React context provider for shared data fetch
└── components/
── PolarisView.tsx # Main page: score badge, check summary, cluster info, error states, refresh interval selector
── DashboardView.tsx # Overview page (score, check summary with skipped count, cluster info)
├── NamespacesListView.tsx # Namespace list with scores and links to detail views
├── NamespaceDetailView.tsx # Per-namespace drill-down with resource table
└── PolarisSettings.tsx # Plugin settings (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.
Top-level sidebar section at `/polaris` with sub-routes for namespaces list (`/polaris/namespaces`) and per-namespace views (`/polaris/ns/:namespace`). 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). Skipped checks are always displayed in summaries.
**Sidebar limitation**: Headlamp's sidebar only supports 2-level nesting (parent → children). The `Collapse` component is driven by route-based selection, not click-to-toggle, so 3-level hierarchies don't expand properly. Namespace navigation is handled via the in-content table on the Namespaces page instead.
## Security / RBAC Requirements
The plugin reaches Polaris through the Kubernetes API server's service proxy sub-resource (`/api/v1/namespaces/polaris/services/polaris-dashboard/proxy/...`). The Headlamp service account (or the user's bearer token when Headlamp runs in token-auth mode) must be granted:
| Verb | API Group | Resource | Resource Name | Namespace |
|------|-----------|----------|---------------|-----------|
| `get` | `""` (core) | `services/proxy` | `polaris-dashboard` | `polaris` |
Minimal RBAC example:
```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: polaris-proxy-reader
namespace: polaris
rules:
- apiGroups: [""]
resources: ["services/proxy"]
resourceNames: ["polaris-dashboard"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: headlamp-polaris-proxy
namespace: polaris
subjects:
- kind: ServiceAccount
name: headlamp # adjust to match your Headlamp SA
namespace: kube-system
roleRef:
kind: Role
name: polaris-proxy-reader
apiGroup: rbac.authorization.k8s.io
```
Additional considerations:
- **NetworkPolicy**: If the `polaris` namespace enforces network policies, allow ingress from the Headlamp pod (or the API server, since it performs the proxy hop) to `polaris-dashboard` on port 80.
- **Polaris dashboard listen address**: The Polaris Helm chart exposes the dashboard on a ClusterIP service (`polaris-dashboard:80`). If the chart is installed with `dashboard.enabled: false`, the service will not be created, resulting in a 404 error for proxy requests.
- **No write operations**: The plugin only performs `GET` requests through the proxy. No `create`, `update`, or `delete` verbs are required. Do not grant broader service proxy access than `get`.
- **Token-auth mode**: When Headlamp is configured for user-supplied tokens (rather than a fixed service account), each user's own RBAC bindings must include the role above. A 403 from the plugin means the logged-in user lacks the binding.
- **Audit logging**: Kubernetes API audit logs will record every proxied request as a `get` on `services/proxy` in the `polaris` namespace. Set an appropriate audit policy level if request volume from the auto-refresh interval is a concern.
## 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.
- **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.
+58
View File
@@ -0,0 +1,58 @@
# E2E Smoke Tests
Playwright-based smoke tests that validate the Polaris plugin against a live Headlamp deployment.
## CI
E2E tests run automatically in Gitea Actions on pushes to `main` and pull requests. The workflow (`.gitea/workflows/e2e.yaml`) uses Authentik OIDC for authentication via repo secrets.
### Required Gitea secrets
| Secret | Description |
| -------------------- | -------------------------------------------------------------- |
| `AUTHENTIK_USERNAME` | Authentik email or username for a CI user with Headlamp access |
| `AUTHENTIK_PASSWORD` | Password for that user |
## Running Locally
### Option 1: OIDC via Authentik (same as CI)
```bash
AUTHENTIK_USERNAME=you@example.com AUTHENTIK_PASSWORD=... npm run e2e
```
The default base URL is `https://headlamp.animaniacs.farh.net`. Override with `HEADLAMP_URL` if needed.
### Option 2: K8s bearer token (port-forward)
```bash
kubectl port-forward -n kube-system svc/headlamp 4466:80
export HEADLAMP_TOKEN=$(kubectl create token headlamp -n kube-system)
HEADLAMP_URL=http://localhost:4466 npm run e2e
```
Or in headed mode (opens a browser window):
```bash
HEADLAMP_URL=http://localhost:4466 npm run e2e:headed
```
## Environment Variables
| Variable | Required | Default | Description |
| -------------------- | -------- | -------------------------------------- | --------------------------------------- |
| `HEADLAMP_URL` | No | `https://headlamp.animaniacs.farh.net` | Base URL of the Headlamp instance |
| `AUTHENTIK_USERNAME` | OIDC | — | Authentik email/username |
| `AUTHENTIK_PASSWORD` | OIDC | — | Authentik password |
| `HEADLAMP_TOKEN` | Token | — | Kubernetes bearer token (fallback auth) |
Set either `AUTHENTIK_USERNAME` + `AUTHENTIK_PASSWORD` or `HEADLAMP_TOKEN`. OIDC takes priority if both are set.
## What the Tests Validate
- **Sidebar entry** — The Polaris sidebar item appears after login
- **Overview page** — Cluster score and check distribution render correctly
- **Namespaces page** — Table of namespaces loads with clickable links
- **Namespace detail** — Clicking a namespace shows its score and resource table
These are smoke tests against real cluster data. They verify the plugin loads and renders without errors, not specific data values.
+67
View File
@@ -0,0 +1,67 @@
import { test as setup, expect, Page } from '@playwright/test';
const AUTH_STATE_PATH = 'e2e/.auth/state.json';
async function authenticateWithOIDC(page: Page, username: string, password: string): Promise<void> {
// Navigate to login — Headlamp redirects / to /c/main/login
await page.goto('/');
await page.waitForURL('**/login');
// Click "Sign In" and capture the Authentik popup
const popupPromise = page.waitForEvent('popup');
await page.getByRole('button', { name: /sign in/i }).click();
const popup = await popupPromise;
// Authentik step 1: fill username
await popup.getByRole('textbox', { name: /email or username/i }).fill(username);
await popup.getByRole('button', { name: /log in/i }).click();
// Authentik step 2: fill password
await popup.getByRole('textbox', { name: /password/i }).fill(password);
await popup.getByRole('button', { name: /continue|log in/i }).click();
// Wait for the popup to close (Authentik redirects back, Headlamp processes callback)
await popup.waitForEvent('close', { timeout: 15_000 });
// Original page should now be authenticated — wait for sidebar
await expect(page.getByRole('navigation', { name: 'Navigation' })).toBeVisible({
timeout: 15_000,
});
}
async function authenticateWithToken(page: Page, token: string): Promise<void> {
// Navigate to login — Headlamp redirects / to /c/main/login
await page.goto('/');
await page.waitForURL('**/login');
// Click the token auth option
await page.getByRole('button', { name: /use a token/i }).click();
await page.waitForURL('**/token');
// Fill the "ID token" field and submit
await page.getByRole('textbox', { name: /id token/i }).fill(token);
await page.getByRole('button', { name: /authenticate/i }).click();
// Wait for the main UI to load
await expect(page.getByRole('navigation', { name: 'Navigation' })).toBeVisible({
timeout: 15_000,
});
}
setup('authenticate with Headlamp', async ({ page }) => {
const username = process.env.AUTHENTIK_USERNAME;
const password = process.env.AUTHENTIK_PASSWORD;
const token = process.env.HEADLAMP_TOKEN;
if (username && password) {
await authenticateWithOIDC(page, username, password);
} else if (token) {
await authenticateWithToken(page, token);
} else {
throw new Error(
'Set AUTHENTIK_USERNAME + AUTHENTIK_PASSWORD for OIDC auth, or HEADLAMP_TOKEN for token auth'
);
}
await page.context().storageState({ path: AUTH_STATE_PATH });
});
+61
View File
@@ -0,0 +1,61 @@
import { test, expect } from '@playwright/test';
test.describe('Polaris plugin smoke tests', () => {
test('sidebar contains Polaris entry', async ({ page }) => {
await page.goto('/');
// The sidebar is the "Navigation" nav element (not "Appbar Tools")
const sidebar = page.getByRole('navigation', { name: 'Navigation' });
await expect(sidebar).toBeVisible({ timeout: 15_000 });
await expect(sidebar.getByRole('button', { name: 'Polaris' })).toBeVisible();
});
test('overview page renders cluster score', async ({ page }) => {
await page.goto('/c/main/polaris');
// SectionHeader renders a heading
await expect(page.getByRole('heading', { name: 'Polaris \u2014 Overview' })).toBeVisible();
// "Cluster Score" section exists with a percentage
await expect(page.getByText('Cluster Score')).toBeVisible();
await expect(page.getByText(/%/)).toBeVisible();
});
test('namespaces page renders table with links', async ({ page }) => {
await page.goto('/c/main/polaris/namespaces');
await expect(page.getByRole('heading', { name: 'Polaris \u2014 Namespaces' })).toBeVisible();
// Table should have at least one row with a namespace link
const table = page.locator('table');
await expect(table).toBeVisible();
const rows = table.locator('tbody tr');
await expect(rows.first()).toBeVisible();
// Each namespace row should contain a link
const firstLink = rows.first().locator('a');
await expect(firstLink).toBeVisible();
});
test('namespace detail page renders from table link', async ({ page }) => {
await page.goto('/c/main/polaris/namespaces');
// Click the first namespace link in the table
const table = page.locator('table');
await expect(table).toBeVisible();
const firstLink = table.locator('tbody tr').first().locator('a');
const namespaceName = await firstLink.textContent();
await firstLink.click();
// Detail page should show the namespace name in the heading
await expect(
page.getByRole('heading', { name: `Polaris \u2014 ${namespaceName}` })
).toBeVisible();
// "Namespace Score" section should be present
await expect(page.getByText('Namespace Score')).toBeVisible();
// Resources table should exist
await expect(page.getByText('Resources')).toBeVisible();
await expect(page.locator('table')).toBeVisible();
});
});
+69 -5
View File
@@ -1,14 +1,15 @@
{
"name": "polaris-headlamp-plugin",
"version": "0.0.1",
"name": "headlamp-polaris-plugin",
"version": "0.1.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "polaris-headlamp-plugin",
"version": "0.0.1",
"name": "headlamp-polaris-plugin",
"version": "0.1.3",
"devDependencies": {
"@kinvolk/headlamp-plugin": "^0.13.0"
"@kinvolk/headlamp-plugin": "^0.13.0",
"@playwright/test": "^1.58.2"
}
},
"node_modules/@adobe/css-tools": {
@@ -2469,6 +2470,22 @@
"node": ">=14"
}
},
"node_modules/@playwright/test": {
"version": "1.58.2",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.58.2.tgz",
"integrity": "sha512-akea+6bHYBBfA9uQqSYmlJXn61cTa+jbO87xVLCWbTqbWadRVmhxlXATaOjOgcBaWU4ePo0wB41KMFv3o35IXA==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright": "1.58.2"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@popperjs/core": {
"version": "2.11.8",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
@@ -13554,6 +13571,53 @@
"node": ">=8"
}
},
"node_modules/playwright": {
"version": "1.58.2",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.58.2.tgz",
"integrity": "sha512-vA30H8Nvkq/cPBnNw4Q8TWz1EJyqgpuinBcHET0YVJVFldr8JDNiU9LaWAE1KqSkRYazuaBhTpB5ZzShOezQ6A==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.58.2"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=18"
},
"optionalDependencies": {
"fsevents": "2.3.2"
}
},
"node_modules/playwright-core": {
"version": "1.58.2",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.58.2.tgz",
"integrity": "sha512-yZkEtftgwS8CsfYo7nm0KE8jsvm6i/PTgVtB8DL726wNf6H2IMsDuxCpJj59KDaxCtSnrWan2AeDqM7JBaultg==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=18"
}
},
"node_modules/playwright/node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/possible-typed-array-names": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz",
+13 -4
View File
@@ -1,14 +1,23 @@
{
"name": "polaris-headlamp-plugin",
"version": "0.0.1",
"name": "headlamp-polaris-plugin",
"version": "0.1.6",
"description": "Headlamp plugin for Fairwinds Polaris audit results",
"scripts": {
"start": "headlamp-plugin start",
"build": "headlamp-plugin build",
"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/",
"test": "vitest run",
"test:watch": "vitest",
"e2e": "playwright test",
"e2e:headed": "playwright test --headed"
},
"devDependencies": {
"@kinvolk/headlamp-plugin": "^0.13.0"
"@kinvolk/headlamp-plugin": "^0.13.0",
"@playwright/test": "^1.58.2"
}
}
+26
View File
@@ -0,0 +1,26 @@
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './e2e',
timeout: 30_000,
expect: { timeout: 10_000 },
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
reporter: 'list',
use: {
baseURL: process.env.HEADLAMP_URL || 'https://headlamp.animaniacs.farh.net',
trace: 'on-first-retry',
},
projects: [
{ name: 'setup', testMatch: /auth\.setup\.ts/ },
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
storageState: 'e2e/.auth/state.json',
},
dependencies: ['setup'],
},
],
});
+48
View File
@@ -0,0 +1,48 @@
import { renderHook } from '@testing-library/react';
import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { makeAuditData, makeResult } from '../test-utils';
vi.mock('@kinvolk/headlamp-plugin/lib', () => ({
ApiProxy: { request: vi.fn() },
}));
// Mock usePolarisData so PolarisDataProvider doesn't make real API calls
vi.mock('./polaris', async importOriginal => {
const actual = await importOriginal<typeof import('./polaris')>();
return {
...actual,
usePolarisData: vi.fn(() => ({
data: makeAuditData([makeResult()]),
loading: false,
error: null,
})),
};
});
import { PolarisDataProvider, usePolarisDataContext } from './PolarisDataContext';
describe('usePolarisDataContext', () => {
it('throws when used outside PolarisDataProvider', () => {
// Suppress console.error from React during expected error
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
expect(() => {
renderHook(() => usePolarisDataContext());
}).toThrow('usePolarisDataContext must be used within a PolarisDataProvider');
spy.mockRestore();
});
it('returns context value when inside PolarisDataProvider', () => {
const wrapper = ({ children }: { children: React.ReactNode }) => (
<PolarisDataProvider>{children}</PolarisDataProvider>
);
const { result } = renderHook(() => usePolarisDataContext(), { wrapper });
expect(result.current.data).not.toBeNull();
expect(result.current.loading).toBe(false);
expect(result.current.error).toBeNull();
});
});
+25
View File
@@ -0,0 +1,25 @@
import React from 'react';
import { AuditData, getRefreshInterval, usePolarisData } from './polaris';
interface PolarisDataContextValue {
data: AuditData | null;
loading: boolean;
error: string | null;
}
const PolarisDataContext = React.createContext<PolarisDataContextValue | null>(null);
export function PolarisDataProvider(props: { children: React.ReactNode }) {
const interval = getRefreshInterval();
const state = usePolarisData(interval);
return <PolarisDataContext.Provider value={state}>{props.children}</PolarisDataContext.Provider>;
}
export function usePolarisDataContext(): PolarisDataContextValue {
const ctx = React.useContext(PolarisDataContext);
if (ctx === null) {
throw new Error('usePolarisDataContext must be used within a PolarisDataProvider');
}
return ctx;
}
+390
View File
@@ -0,0 +1,390 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { makeAuditData, makeResult } from '../test-utils';
vi.mock('@kinvolk/headlamp-plugin/lib', () => ({
ApiProxy: { request: vi.fn() },
}));
import { ApiProxy } from '@kinvolk/headlamp-plugin/lib';
import {
computeScore,
countResults,
countResultsForItems,
filterResultsByNamespace,
getNamespaces,
getRefreshInterval,
Result,
ResultCounts,
setRefreshInterval,
usePolarisData,
} from './polaris';
// --- computeScore ---
describe('computeScore', () => {
it('returns 0 when total is 0', () => {
const counts: ResultCounts = { total: 0, pass: 0, warning: 0, danger: 0, skipped: 0 };
expect(computeScore(counts)).toBe(0);
});
it('returns 100 when all checks pass', () => {
const counts: ResultCounts = { total: 10, pass: 10, warning: 0, danger: 0, skipped: 0 };
expect(computeScore(counts)).toBe(100);
});
it('rounds to nearest integer', () => {
const counts: ResultCounts = { total: 3, pass: 1, warning: 1, danger: 1, skipped: 0 };
expect(computeScore(counts)).toBe(33);
});
it('includes skipped in total denominator', () => {
const counts: ResultCounts = { total: 10, pass: 5, warning: 2, danger: 1, skipped: 2 };
expect(computeScore(counts)).toBe(50);
});
});
// --- countResults / countResultsForItems ---
describe('countResults', () => {
it('returns zero counts for empty results', () => {
const data = makeAuditData([]);
const counts = countResults(data);
expect(counts).toEqual({ total: 0, pass: 0, warning: 0, danger: 0, skipped: 0 });
});
it('counts top-level result set entries', () => {
const result = makeResult({
Results: {
check1: {
ID: 'check1',
Message: 'ok',
Details: [],
Success: true,
Severity: 'warning',
Category: 'Security',
},
check2: {
ID: 'check2',
Message: 'bad',
Details: [],
Success: false,
Severity: 'danger',
Category: 'Security',
},
},
});
const counts = countResults(makeAuditData([result]));
expect(counts.total).toBe(2);
expect(counts.pass).toBe(1);
expect(counts.danger).toBe(1);
expect(counts.warning).toBe(0);
expect(counts.skipped).toBe(0);
});
it('counts skipped (severity=ignore, success=false) entries', () => {
const result = makeResult({
Results: {
skipped1: {
ID: 'skipped1',
Message: 'skipped',
Details: [],
Success: false,
Severity: 'ignore',
Category: 'Security',
},
},
});
const counts = countResults(makeAuditData([result]));
expect(counts.total).toBe(1);
expect(counts.skipped).toBe(1);
expect(counts.pass).toBe(0);
});
it('counts PodResult and ContainerResults', () => {
const result = makeResult({
Results: {
top: {
ID: 'top',
Message: 'ok',
Details: [],
Success: true,
Severity: 'warning',
Category: 'Reliability',
},
},
PodResult: {
Name: 'pod-1',
Results: {
podCheck: {
ID: 'podCheck',
Message: 'warn',
Details: [],
Success: false,
Severity: 'warning',
Category: 'Reliability',
},
},
ContainerResults: [
{
Name: 'container-1',
Results: {
containerCheck: {
ID: 'containerCheck',
Message: 'danger',
Details: [],
Success: false,
Severity: 'danger',
Category: 'Security',
},
},
},
],
},
});
const counts = countResults(makeAuditData([result]));
expect(counts.total).toBe(3);
expect(counts.pass).toBe(1);
expect(counts.warning).toBe(1);
expect(counts.danger).toBe(1);
});
it('aggregates across multiple results', () => {
const r1 = makeResult({
Name: 'deploy-a',
Results: {
c1: {
ID: 'c1',
Message: '',
Details: [],
Success: true,
Severity: 'warning',
Category: 'X',
},
},
});
const r2 = makeResult({
Name: 'deploy-b',
Results: {
c2: {
ID: 'c2',
Message: '',
Details: [],
Success: false,
Severity: 'warning',
Category: 'X',
},
},
});
const counts = countResults(makeAuditData([r1, r2]));
expect(counts.total).toBe(2);
expect(counts.pass).toBe(1);
expect(counts.warning).toBe(1);
});
});
describe('countResultsForItems', () => {
it('works on a subset of results', () => {
const results: Result[] = [
makeResult({
Results: {
a: {
ID: 'a',
Message: '',
Details: [],
Success: false,
Severity: 'danger',
Category: 'X',
},
},
}),
];
const counts = countResultsForItems(results);
expect(counts.danger).toBe(1);
expect(counts.total).toBe(1);
});
});
// --- getNamespaces ---
describe('getNamespaces', () => {
it('returns empty array for no results', () => {
expect(getNamespaces(makeAuditData([]))).toEqual([]);
});
it('returns sorted unique namespaces', () => {
const data = makeAuditData([
makeResult({ Namespace: 'beta' }),
makeResult({ Namespace: 'alpha' }),
makeResult({ Namespace: 'beta' }),
makeResult({ Namespace: 'gamma' }),
]);
expect(getNamespaces(data)).toEqual(['alpha', 'beta', 'gamma']);
});
it('excludes results with empty namespace (cluster-scoped resources)', () => {
const data = makeAuditData([
makeResult({ Namespace: '' }),
makeResult({ Namespace: 'alpha' }),
makeResult({ Namespace: '' }),
]);
expect(getNamespaces(data)).toEqual(['alpha']);
});
});
// --- filterResultsByNamespace ---
describe('filterResultsByNamespace', () => {
it('returns only results matching the namespace', () => {
const data = makeAuditData([
makeResult({ Name: 'a', Namespace: 'ns1' }),
makeResult({ Name: 'b', Namespace: 'ns2' }),
makeResult({ Name: 'c', Namespace: 'ns1' }),
]);
const filtered = filterResultsByNamespace(data, 'ns1');
expect(filtered).toHaveLength(2);
expect(filtered.map(r => r.Name)).toEqual(['a', 'c']);
});
it('returns empty array for non-existent namespace', () => {
const data = makeAuditData([makeResult({ Namespace: 'ns1' })]);
expect(filterResultsByNamespace(data, 'ns-missing')).toEqual([]);
});
});
// --- getRefreshInterval / setRefreshInterval ---
describe('getRefreshInterval', () => {
beforeEach(() => {
window.localStorage.removeItem('polaris-plugin-refresh-interval');
});
it('returns default (300) when nothing stored', () => {
expect(getRefreshInterval()).toBe(300);
});
it('returns stored value when valid', () => {
localStorage.setItem('polaris-plugin-refresh-interval', '60');
expect(getRefreshInterval()).toBe(60);
});
it('returns default for non-numeric stored value', () => {
localStorage.setItem('polaris-plugin-refresh-interval', 'abc');
expect(getRefreshInterval()).toBe(300);
});
it('returns default for zero stored value', () => {
localStorage.setItem('polaris-plugin-refresh-interval', '0');
expect(getRefreshInterval()).toBe(300);
});
it('returns default for negative stored value', () => {
localStorage.setItem('polaris-plugin-refresh-interval', '-10');
expect(getRefreshInterval()).toBe(300);
});
});
describe('setRefreshInterval', () => {
beforeEach(() => {
window.localStorage.removeItem('polaris-plugin-refresh-interval');
});
it('stores value that getRefreshInterval reads back', () => {
setRefreshInterval(1800);
expect(getRefreshInterval()).toBe(1800);
});
});
// --- usePolarisData ---
describe('usePolarisData', () => {
const mockRequest = ApiProxy.request as ReturnType<typeof vi.fn>;
beforeEach(() => {
mockRequest.mockReset();
});
it('returns data on successful fetch', async () => {
const auditData = makeAuditData([makeResult()]);
mockRequest.mockResolvedValue(auditData);
const { result } = renderHook(() => usePolarisData(300));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.data).toEqual(auditData);
expect(result.current.error).toBeNull();
});
it('returns RBAC error on 403', async () => {
mockRequest.mockRejectedValue({ status: 403 });
const { result } = renderHook(() => usePolarisData(300));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.data).toBeNull();
expect(result.current.error).toContain('403');
expect(result.current.error).toContain('RBAC');
});
it('returns not-installed error on 404', async () => {
mockRequest.mockRejectedValue({ status: 404 });
const { result } = renderHook(() => usePolarisData(300));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.error).toContain('not reachable');
});
it('returns not-installed error on 503', async () => {
mockRequest.mockRejectedValue({ status: 503 });
const { result } = renderHook(() => usePolarisData(300));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.error).toContain('not reachable');
});
it('returns generic error for other failures', async () => {
mockRequest.mockRejectedValue(new Error('network down'));
const { result } = renderHook(() => usePolarisData(300));
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
expect(result.current.error).toContain('Failed to fetch');
expect(result.current.error).toContain('network down');
});
it('does not update state after unmount', async () => {
let resolveFetch: (value: unknown) => void = () => {};
mockRequest.mockReturnValue(
new Promise(resolve => {
resolveFetch = resolve;
})
);
const { result, unmount } = renderHook(() => usePolarisData(300));
expect(result.current.loading).toBe(true);
unmount();
// Resolve after unmount — should not throw or update state
await act(async () => {
resolveFetch(makeAuditData([]));
});
});
});
+92 -79
View File
@@ -1,4 +1,4 @@
import { K8s } from '@kinvolk/headlamp-plugin/lib';
import { ApiProxy } from '@kinvolk/headlamp-plugin/lib';
import React from 'react';
// --- Polaris AuditData schema (matches pkg/validator/output.go) ---
@@ -52,7 +52,6 @@ export interface AuditData {
DisplayName: string;
ClusterInfo: ClusterInfo;
Results: Result[];
Score: number;
}
// --- Result counting ---
@@ -62,6 +61,7 @@ export interface ResultCounts {
pass: number;
warning: number;
danger: number;
skipped: number;
}
function countResultSet(rs: ResultSet, counts: ResultCounts): void {
@@ -70,6 +70,8 @@ function countResultSet(rs: ResultSet, counts: ResultCounts): void {
counts.total++;
if (msg.Success) {
counts.pass++;
} else if (msg.Severity === 'ignore') {
counts.skipped++;
} else if (msg.Severity === 'warning') {
counts.warning++;
} else if (msg.Severity === 'danger') {
@@ -78,9 +80,9 @@ function countResultSet(rs: ResultSet, counts: ResultCounts): void {
}
}
export function countResults(data: AuditData): ResultCounts {
const counts: ResultCounts = { total: 0, pass: 0, warning: 0, danger: 0 };
for (const result of data.Results) {
function countResultItems(results: Result[]): ResultCounts {
const counts: ResultCounts = { total: 0, pass: 0, warning: 0, danger: 0, skipped: 0 };
for (const result of results) {
countResultSet(result.Results, counts);
if (result.PodResult) {
countResultSet(result.PodResult.Results, counts);
@@ -92,8 +94,37 @@ export function countResults(data: AuditData): ResultCounts {
return counts;
}
export function countResults(data: AuditData): ResultCounts {
return countResultItems(data.Results);
}
export function countResultsForItems(results: Result[]): ResultCounts {
return countResultItems(results);
}
export function getNamespaces(data: AuditData): string[] {
const namespaces = new Set<string>();
for (const result of data.Results) {
if (result.Namespace) {
namespaces.add(result.Namespace);
}
}
return Array.from(namespaces).sort();
}
export function filterResultsByNamespace(data: AuditData, namespace: string): Result[] {
return data.Results.filter(r => r.Namespace === namespace);
}
// --- 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 DEFAULT_INTERVAL_SECONDS = 300; // 5 minutes
@@ -112,8 +143,23 @@ export function setRefreshInterval(seconds: number): void {
localStorage.setItem(STORAGE_KEY, String(seconds));
}
// --- Polaris dashboard proxy URL ---
export const POLARIS_DASHBOARD_PROXY =
'/api/v1/namespaces/polaris/services/polaris-dashboard:80/proxy/';
// --- 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 ---
const POLARIS_API_PATH =
'/api/v1/namespaces/polaris/services/polaris-dashboard:80/proxy/results.json';
interface PolarisDataState {
data: AuditData | null;
loading: boolean;
@@ -121,87 +167,54 @@ interface PolarisDataState {
}
export function usePolarisData(refreshIntervalSeconds: number): PolarisDataState {
const [configMap, fetchError] = K8s.ResourceClasses.ConfigMap.useGet(
'polaris-dashboard',
'polaris'
);
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);
const [data, setData] = React.useState<AuditData | null>(null);
const [loading, setLoading] = React.useState(true);
const [error, setError] = React.useState<string | null>(null);
const [tick, setTick] = React.useState(0);
// Parse ConfigMap data when it arrives
React.useEffect(() => {
if (!configMap) {
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]);
let cancelled = false;
// Periodic refresh via re-render trigger
React.useEffect(() => {
if (refreshIntervalSeconds <= 0) {
return;
async function fetchData() {
try {
const result: AuditData = await ApiProxy.request(POLARIS_API_PATH);
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(() => {
setTick((t) => t + 1);
setTick(t => t + 1);
}, refreshIntervalSeconds * 1000);
return () => window.clearInterval(intervalId);
}, [refreshIntervalSeconds]);
// Determine error state
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,
};
return { data, loading, error };
}
+134
View File
@@ -0,0 +1,134 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { makeAuditData, makeResult } from '../test-utils';
// Mock Headlamp lib
vi.mock('@kinvolk/headlamp-plugin/lib', () => ({
ApiProxy: { request: vi.fn() },
}));
// Mock Headlamp CommonComponents as thin pass-throughs
vi.mock('@kinvolk/headlamp-plugin/lib/CommonComponents', () => ({
Loader: ({ title }: { title: string }) => <div data-testid="loader">{title}</div>,
SectionBox: ({ title, children }: { title?: string; children?: React.ReactNode }) => (
<div data-testid="section-box" data-title={title}>
{children}
</div>
),
SectionHeader: ({ title }: { title: string }) => <div data-testid="section-header">{title}</div>,
StatusLabel: ({ status, children }: { status: string; children?: React.ReactNode }) => (
<span data-testid="status-label" data-status={status}>
{children}
</span>
),
NameValueTable: ({ rows }: { rows: Array<{ name: string; value: React.ReactNode }> }) => (
<table data-testid="name-value-table">
<tbody>
{rows.map(row => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.value}</td>
</tr>
))}
</tbody>
</table>
),
PercentageCircle: ({ label }: { label: string }) => (
<div data-testid="percentage-circle">{label}</div>
),
PercentageBar: () => <div data-testid="percentage-bar" />,
}));
// Mock the context hook — we'll override per test via mockReturnValue
const mockUsePolarisDataContext = vi.fn();
vi.mock('../api/PolarisDataContext', () => ({
usePolarisDataContext: () => mockUsePolarisDataContext(),
}));
import DashboardView from './DashboardView';
describe('DashboardView', () => {
it('renders loader when loading', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: true,
error: null,
});
render(<DashboardView />);
expect(screen.getByTestId('loader')).toHaveTextContent('Loading Polaris audit data');
});
it('renders error message when error is set', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: false,
error: 'Access denied (403)',
});
render(<DashboardView />);
expect(screen.getByText('Access denied (403)')).toBeInTheDocument();
});
it('renders score, check distribution, and cluster info with data', () => {
const data = makeAuditData([
makeResult({
Results: {
c1: {
ID: 'c1',
Message: '',
Details: [],
Success: true,
Severity: 'warning',
Category: 'X',
},
c2: {
ID: 'c2',
Message: '',
Details: [],
Success: false,
Severity: 'danger',
Category: 'X',
},
},
}),
]);
mockUsePolarisDataContext.mockReturnValue({
data,
loading: false,
error: null,
});
render(<DashboardView />);
// Score circle shows 50%
expect(screen.getByTestId('percentage-circle')).toHaveTextContent('50%');
// Check distribution values
expect(screen.getByText('Total Checks')).toBeInTheDocument();
// Cluster info section (title is in data-title attr of SectionBox)
const sectionBoxes = screen.getAllByTestId('section-box');
const clusterInfoBox = sectionBoxes.find(
el => el.getAttribute('data-title') === 'Cluster Info'
);
expect(clusterInfoBox).toBeDefined();
// Cluster info values
expect(screen.getByText('Nodes')).toBeInTheDocument();
expect(screen.getByText('Pods')).toBeInTheDocument();
});
it('renders "No Data" when no data and no error', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: false,
error: null,
});
render(<DashboardView />);
expect(screen.getByText('No Polaris audit results found.')).toBeInTheDocument();
});
});
+121
View File
@@ -0,0 +1,121 @@
import {
Loader,
NameValueTable,
PercentageBar,
PercentageCircle,
SectionBox,
SectionHeader,
StatusLabel,
} from '@kinvolk/headlamp-plugin/lib/CommonComponents';
import React from 'react';
import { AuditData, computeScore, countResults, ResultCounts } from '../api/polaris';
import { usePolarisDataContext } from '../api/PolarisDataContext';
const COLORS = {
pass: '#4caf50',
warning: '#ff9800',
danger: '#f44336',
skipped: '#9e9e9e',
};
function OverviewSection(props: { data: AuditData; counts: ResultCounts }) {
const { counts } = props;
const score = computeScore(counts);
const chartData = [
{ name: 'Pass', value: counts.pass, fill: COLORS.pass },
{ name: 'Warning', value: counts.warning, fill: COLORS.warning },
{ name: 'Danger', value: counts.danger, fill: COLORS.danger },
{ name: 'Skipped', value: counts.skipped, fill: COLORS.skipped },
];
return (
<>
<SectionBox title="Cluster Score">
<PercentageCircle data={chartData} total={counts.total} label={`${score}%`} />
</SectionBox>
<SectionBox title="Check Distribution">
<PercentageBar data={chartData} total={counts.total} />
<NameValueTable
rows={[
{ name: 'Total Checks', value: String(counts.total) },
{
name: 'Pass',
value: <StatusLabel status="success">{counts.pass}</StatusLabel>,
},
{
name: 'Warning',
value: <StatusLabel status="warning">{counts.warning}</StatusLabel>,
},
{
name: 'Danger',
value: <StatusLabel status="error">{counts.danger}</StatusLabel>,
},
{
name: 'Skipped',
value: (
<span title="Only counts checks with Severity=ignore. Annotation-based exemptions are not included.">
{counts.skipped}
</span>
),
},
]}
/>
</SectionBox>
<SectionBox title="Cluster Info">
<NameValueTable
rows={[
{ name: 'Nodes', value: String(props.data.ClusterInfo.Nodes) },
{ name: 'Pods', value: String(props.data.ClusterInfo.Pods) },
{ name: 'Namespaces', value: String(props.data.ClusterInfo.Namespaces) },
{ name: 'Controllers', value: String(props.data.ClusterInfo.Controllers) },
]}
/>
</SectionBox>
</>
);
}
export default function DashboardView() {
const { data, loading, error } = usePolarisDataContext();
if (loading) {
return <Loader title="Loading Polaris audit data..." />;
}
const counts = data ? countResults(data) : null;
return (
<>
<SectionHeader title="Polaris — Overview" />
{error && (
<SectionBox title="Error">
<NameValueTable
rows={[
{
name: 'Status',
value: <StatusLabel status="error">{error}</StatusLabel>,
},
]}
/>
</SectionBox>
)}
{data && counts && <OverviewSection data={data} counts={counts} />}
{!data && !error && (
<SectionBox title="No Data">
<NameValueTable
rows={[
{
name: 'Status',
value: 'No Polaris audit results found.',
},
]}
/>
</SectionBox>
)}
</>
);
}
+200
View File
@@ -0,0 +1,200 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { makeAuditData, makeResult } from '../test-utils';
// Mock Headlamp lib
vi.mock('@kinvolk/headlamp-plugin/lib', () => ({
ApiProxy: { request: vi.fn() },
}));
// Mock react-router-dom useParams
const mockNamespace = vi.fn(() => 'test-ns');
vi.mock('react-router-dom', () => ({
useParams: () => ({ namespace: mockNamespace() }),
}));
// Mock Headlamp CommonComponents
vi.mock('@kinvolk/headlamp-plugin/lib/CommonComponents', () => ({
Loader: ({ title }: { title: string }) => <div data-testid="loader">{title}</div>,
SectionBox: ({ title, children }: { title?: string; children?: React.ReactNode }) => (
<div data-testid="section-box" data-title={title}>
{children}
</div>
),
SectionHeader: ({ title }: { title: string }) => <div data-testid="section-header">{title}</div>,
StatusLabel: ({ status, children }: { status: string; children?: React.ReactNode }) => (
<span data-testid="status-label" data-status={status}>
{children}
</span>
),
NameValueTable: ({ rows }: { rows: Array<{ name: string; value: React.ReactNode }> }) => (
<table data-testid="name-value-table">
<tbody>
{rows.map(row => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.value}</td>
</tr>
))}
</tbody>
</table>
),
SimpleTable: ({
columns,
data,
emptyMessage,
}: {
columns: Array<{ label: string; getter: (row: unknown) => React.ReactNode }>;
data: unknown[];
emptyMessage?: string;
}) =>
data.length === 0 ? (
<div data-testid="simple-table-empty">{emptyMessage}</div>
) : (
<table data-testid="simple-table">
<thead>
<tr>
{columns.map(col => (
<th key={col.label}>{col.label}</th>
))}
</tr>
</thead>
<tbody>
{data.map((row, i) => (
<tr key={i}>
{columns.map(col => (
<td key={col.label}>{col.getter(row)}</td>
))}
</tr>
))}
</tbody>
</table>
),
}));
const mockUsePolarisDataContext = vi.fn();
vi.mock('../api/PolarisDataContext', () => ({
usePolarisDataContext: () => mockUsePolarisDataContext(),
}));
import NamespaceDetailView from './NamespaceDetailView';
describe('NamespaceDetailView', () => {
it('renders loader when loading', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: true,
error: null,
});
render(<NamespaceDetailView />);
expect(screen.getByTestId('loader')).toHaveTextContent('Loading Polaris data for test-ns');
});
it('renders error message when error is set', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: false,
error: 'Access denied (403)',
});
render(<NamespaceDetailView />);
expect(screen.getByText('Access denied (403)')).toBeInTheDocument();
expect(screen.getByTestId('section-header')).toHaveTextContent('Polaris — test-ns');
});
it('renders "No Data" when no data and no error', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: false,
error: null,
});
render(<NamespaceDetailView />);
expect(screen.getByText('No Polaris audit results found.')).toBeInTheDocument();
});
it('renders namespace score and resource table with data', () => {
const data = makeAuditData([
makeResult({
Name: 'deploy-a',
Namespace: 'test-ns',
Kind: 'Deployment',
Results: {
c1: {
ID: 'c1',
Message: '',
Details: [],
Success: true,
Severity: 'warning',
Category: 'X',
},
c2: {
ID: 'c2',
Message: '',
Details: [],
Success: false,
Severity: 'warning',
Category: 'X',
},
},
}),
makeResult({
Name: 'other',
Namespace: 'other-ns',
Kind: 'Deployment',
Results: {
c3: {
ID: 'c3',
Message: '',
Details: [],
Success: true,
Severity: 'warning',
Category: 'X',
},
},
}),
]);
mockUsePolarisDataContext.mockReturnValue({
data,
loading: false,
error: null,
});
render(<NamespaceDetailView />);
// Header
expect(screen.getByTestId('section-header')).toHaveTextContent('Polaris — test-ns');
// Score section: 50% (1 pass / 2 total)
expect(screen.getByText('50%')).toBeInTheDocument();
expect(screen.getByText('Total Checks')).toBeInTheDocument();
// Resource table shows only test-ns resources
expect(screen.getByText('deploy-a')).toBeInTheDocument();
expect(screen.queryByText('other')).not.toBeInTheDocument();
});
it('renders empty table message for namespace with no results', () => {
const data = makeAuditData([
makeResult({
Name: 'deploy-a',
Namespace: 'other-ns',
Results: {},
}),
]);
mockUsePolarisDataContext.mockReturnValue({
data,
loading: false,
error: null,
});
render(<NamespaceDetailView />);
expect(screen.getByTestId('simple-table-empty')).toHaveTextContent(
'No resources found in namespace "test-ns"'
);
});
});
+163
View File
@@ -0,0 +1,163 @@
import {
Loader,
NameValueTable,
SectionBox,
SectionHeader,
SimpleTable,
StatusLabel,
} from '@kinvolk/headlamp-plugin/lib/CommonComponents';
import React from 'react';
import { useParams } from 'react-router-dom';
import {
computeScore,
countResultsForItems,
filterResultsByNamespace,
POLARIS_DASHBOARD_PROXY,
Result,
ResultCounts,
} from '../api/polaris';
import { usePolarisDataContext } from '../api/PolarisDataContext';
function scoreStatus(score: number): 'success' | 'warning' | 'error' {
if (score >= 80) return 'success';
if (score >= 50) return 'warning';
return 'error';
}
function resourceCounts(result: Result): ResultCounts {
return countResultsForItems([result]);
}
export default function NamespaceDetailView() {
const { namespace } = useParams<{ namespace: string }>();
const { data, loading, error } = usePolarisDataContext();
if (loading) {
return <Loader title={`Loading Polaris data for ${namespace}...`} />;
}
if (error) {
return (
<>
<SectionHeader title={`Polaris — ${namespace}`} />
<SectionBox title="Error">
<NameValueTable
rows={[
{
name: 'Status',
value: <StatusLabel status="error">{error}</StatusLabel>,
},
]}
/>
</SectionBox>
</>
);
}
if (!data) {
return (
<>
<SectionHeader title={`Polaris — ${namespace}`} />
<SectionBox title="No Data">
<NameValueTable rows={[{ name: 'Status', value: 'No Polaris audit results found.' }]} />
</SectionBox>
</>
);
}
const results = filterResultsByNamespace(data, namespace);
const counts = countResultsForItems(results);
const score = computeScore(counts);
const status = scoreStatus(score);
const countsPerResource = new Map<string, ResultCounts>();
for (const r of results) {
countsPerResource.set(`${r.Namespace}/${r.Kind}/${r.Name}`, resourceCounts(r));
}
function getResourceCounts(row: Result): ResultCounts {
return countsPerResource.get(`${row.Namespace}/${row.Kind}/${row.Name}`) ?? resourceCounts(row);
}
return (
<>
<SectionHeader title={`Polaris — ${namespace}`} />
<SectionBox title="External">
<NameValueTable
rows={[
{
name: 'Polaris Dashboard',
value: (
<a href={POLARIS_DASHBOARD_PROXY} target="_blank" rel="noopener noreferrer">
View in Polaris Dashboard
</a>
),
},
]}
/>
</SectionBox>
<SectionBox title="Namespace Score">
<NameValueTable
rows={[
{
name: 'Score',
value: <StatusLabel status={status}>{score}%</StatusLabel>,
},
{ name: 'Total Checks', value: String(counts.total) },
{
name: 'Pass',
value: <StatusLabel status="success">{counts.pass}</StatusLabel>,
},
{
name: 'Warning',
value: <StatusLabel status="warning">{counts.warning}</StatusLabel>,
},
{
name: 'Danger',
value: <StatusLabel status="error">{counts.danger}</StatusLabel>,
},
{
name: 'Skipped',
value: (
<span title="Only counts checks with Severity=ignore. Annotation-based exemptions are not included.">
{counts.skipped}
</span>
),
},
]}
/>
</SectionBox>
<SectionBox title="Resources">
<SimpleTable
columns={[
{ label: 'Name', getter: (row: Result) => row.Name },
{ label: 'Kind', getter: (row: Result) => row.Kind },
{
label: 'Pass',
getter: (row: Result) => (
<StatusLabel status="success">{getResourceCounts(row).pass}</StatusLabel>
),
},
{
label: 'Warning',
getter: (row: Result) => (
<StatusLabel status="warning">{getResourceCounts(row).warning}</StatusLabel>
),
},
{
label: 'Danger',
getter: (row: Result) => (
<StatusLabel status="error">{getResourceCounts(row).danger}</StatusLabel>
),
},
]}
data={results}
emptyMessage={`No resources found in namespace "${namespace}".`}
/>
</SectionBox>
</>
);
}
+219
View File
@@ -0,0 +1,219 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { describe, expect, it, vi } from 'vitest';
import { makeAuditData, makeResult } from '../test-utils';
// Mock Headlamp lib
vi.mock('@kinvolk/headlamp-plugin/lib', () => ({
ApiProxy: { request: vi.fn() },
Router: {
createRouteURL: (name: string, params: Record<string, string>) =>
`/polaris/ns/${params.namespace}`,
},
}));
// Mock Headlamp CommonComponents
vi.mock('@kinvolk/headlamp-plugin/lib/CommonComponents', () => ({
Loader: ({ title }: { title: string }) => <div data-testid="loader">{title}</div>,
SectionBox: ({ title, children }: { title?: string; children?: React.ReactNode }) => (
<div data-testid="section-box" data-title={title}>
{children}
</div>
),
SectionHeader: ({ title }: { title: string }) => <div data-testid="section-header">{title}</div>,
StatusLabel: ({ status, children }: { status: string; children?: React.ReactNode }) => (
<span data-testid="status-label" data-status={status}>
{children}
</span>
),
NameValueTable: ({ rows }: { rows: Array<{ name: string; value: React.ReactNode }> }) => (
<table data-testid="name-value-table">
<tbody>
{rows.map(row => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.value}</td>
</tr>
))}
</tbody>
</table>
),
SimpleTable: ({
columns,
data,
emptyMessage,
}: {
columns: Array<{ label: string; getter: (row: unknown) => React.ReactNode }>;
data: unknown[];
emptyMessage?: string;
}) =>
data.length === 0 ? (
<div data-testid="simple-table-empty">{emptyMessage}</div>
) : (
<table data-testid="simple-table">
<thead>
<tr>
{columns.map(col => (
<th key={col.label}>{col.label}</th>
))}
</tr>
</thead>
<tbody>
{data.map((row, i) => (
<tr key={i}>
{columns.map(col => (
<td key={col.label}>{col.getter(row)}</td>
))}
</tr>
))}
</tbody>
</table>
),
}));
const mockUsePolarisDataContext = vi.fn();
vi.mock('../api/PolarisDataContext', () => ({
usePolarisDataContext: () => mockUsePolarisDataContext(),
}));
import NamespacesListView from './NamespacesListView';
function renderWithRouter(ui: React.ReactElement) {
return render(<MemoryRouter>{ui}</MemoryRouter>);
}
describe('NamespacesListView', () => {
it('renders loader when loading', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: true,
error: null,
});
renderWithRouter(<NamespacesListView />);
expect(screen.getByTestId('loader')).toHaveTextContent('Loading Polaris audit data');
});
it('renders error message when error is set', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: false,
error: 'Polaris dashboard not reachable',
});
renderWithRouter(<NamespacesListView />);
expect(screen.getByText('Polaris dashboard not reachable')).toBeInTheDocument();
});
it('renders "No Data" when no data and no error', () => {
mockUsePolarisDataContext.mockReturnValue({
data: null,
loading: false,
error: null,
});
renderWithRouter(<NamespacesListView />);
expect(screen.getByText('No Polaris audit results found.')).toBeInTheDocument();
});
it('renders namespace rows with correct scores and links', () => {
const data = makeAuditData([
makeResult({
Name: 'deploy-a',
Namespace: 'alpha',
Results: {
c1: {
ID: 'c1',
Message: '',
Details: [],
Success: true,
Severity: 'warning',
Category: 'X',
},
},
}),
makeResult({
Name: 'deploy-b',
Namespace: 'beta',
Results: {
c2: {
ID: 'c2',
Message: '',
Details: [],
Success: false,
Severity: 'danger',
Category: 'X',
},
},
}),
]);
mockUsePolarisDataContext.mockReturnValue({
data,
loading: false,
error: null,
});
renderWithRouter(<NamespacesListView />);
// Namespace links
const alphaLink = screen.getByText('alpha');
expect(alphaLink.closest('a')).toHaveAttribute('href', '/polaris/ns/alpha');
const betaLink = screen.getByText('beta');
expect(betaLink.closest('a')).toHaveAttribute('href', '/polaris/ns/beta');
});
it('uses correct scoreStatus: >=80 success, >=50 warning, <50 error', () => {
// Create a namespace with 100% score (1 pass) and one with 0% (1 danger)
const data = makeAuditData([
makeResult({
Name: 'perfect',
Namespace: 'good-ns',
Results: {
c1: {
ID: 'c1',
Message: '',
Details: [],
Success: true,
Severity: 'warning',
Category: 'X',
},
},
}),
makeResult({
Name: 'bad',
Namespace: 'bad-ns',
Results: {
c2: {
ID: 'c2',
Message: '',
Details: [],
Success: false,
Severity: 'danger',
Category: 'X',
},
},
}),
]);
mockUsePolarisDataContext.mockReturnValue({
data,
loading: false,
error: null,
});
renderWithRouter(<NamespacesListView />);
// Find score StatusLabels - good-ns has 100% (success), bad-ns has 0% (error)
const statusLabels = screen.getAllByTestId('status-label');
const scoreLabels = statusLabels.filter(el => el.textContent?.includes('%'));
const successScore = scoreLabels.find(el => el.textContent === '100%');
expect(successScore).toHaveAttribute('data-status', 'success');
const errorScore = scoreLabels.find(el => el.textContent === '0%');
expect(errorScore).toHaveAttribute('data-status', 'error');
});
});
+135
View File
@@ -0,0 +1,135 @@
import { Router } from '@kinvolk/headlamp-plugin/lib';
import {
Loader,
NameValueTable,
SectionBox,
SectionHeader,
SimpleTable,
StatusLabel,
} from '@kinvolk/headlamp-plugin/lib/CommonComponents';
import React from 'react';
import { Link } from 'react-router-dom';
import {
computeScore,
countResultsForItems,
filterResultsByNamespace,
getNamespaces,
} from '../api/polaris';
import { usePolarisDataContext } from '../api/PolarisDataContext';
function scoreStatus(score: number): 'success' | 'warning' | 'error' {
if (score >= 80) return 'success';
if (score >= 50) return 'warning';
return 'error';
}
interface NamespaceRow {
namespace: string;
score: number;
pass: number;
warning: number;
danger: number;
skipped: number;
}
export default function NamespacesListView() {
const { data, loading, error } = usePolarisDataContext();
if (loading) {
return <Loader title="Loading Polaris audit data..." />;
}
if (error) {
return (
<>
<SectionHeader title="Polaris — Namespaces" />
<SectionBox title="Error">
<NameValueTable
rows={[
{
name: 'Status',
value: <StatusLabel status="error">{error}</StatusLabel>,
},
]}
/>
</SectionBox>
</>
);
}
if (!data) {
return (
<>
<SectionHeader title="Polaris — Namespaces" />
<SectionBox title="No Data">
<NameValueTable rows={[{ name: 'Status', value: 'No Polaris audit results found.' }]} />
</SectionBox>
</>
);
}
const namespaces = getNamespaces(data);
const rows: NamespaceRow[] = namespaces.map(ns => {
const results = filterResultsByNamespace(data, ns);
const counts = countResultsForItems(results);
const score = computeScore(counts);
return {
namespace: ns,
score,
pass: counts.pass,
warning: counts.warning,
danger: counts.danger,
skipped: counts.skipped,
};
});
return (
<>
<SectionHeader title="Polaris — Namespaces" />
<SectionBox>
<SimpleTable
columns={[
{
label: 'Namespace',
getter: (row: NamespaceRow) => (
<Link
to={Router.createRouteURL('polaris-namespace', {
namespace: row.namespace,
})}
>
{row.namespace}
</Link>
),
},
{
label: 'Score',
getter: (row: NamespaceRow) => (
<StatusLabel status={scoreStatus(row.score)}>{row.score}%</StatusLabel>
),
},
{
label: 'Pass',
getter: (row: NamespaceRow) => <StatusLabel status="success">{row.pass}</StatusLabel>,
},
{
label: 'Warning',
getter: (row: NamespaceRow) => (
<StatusLabel status="warning">{row.warning}</StatusLabel>
),
},
{
label: 'Danger',
getter: (row: NamespaceRow) => <StatusLabel status="error">{row.danger}</StatusLabel>,
},
{
label: 'Skipped',
getter: (row: NamespaceRow) => String(row.skipped),
},
]}
data={rows}
emptyMessage="No namespaces found in Polaris audit data."
/>
</SectionBox>
</>
);
}
+82
View File
@@ -0,0 +1,82 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { describe, expect, it, vi } from 'vitest';
// Mock Headlamp lib
vi.mock('@kinvolk/headlamp-plugin/lib', () => ({
ApiProxy: { request: vi.fn() },
}));
// Mock Headlamp CommonComponents
vi.mock('@kinvolk/headlamp-plugin/lib/CommonComponents', () => ({
SectionBox: ({ title, children }: { title?: string; children?: React.ReactNode }) => (
<div data-testid="section-box" data-title={title}>
{children}
</div>
),
NameValueTable: ({ rows }: { rows: Array<{ name: string; value: React.ReactNode }> }) => (
<div data-testid="name-value-table">
{rows.map(row => (
<div key={row.name}>
<span>{row.name}</span>
<span>{row.value}</span>
</div>
))}
</div>
),
}));
import PolarisSettings from './PolarisSettings';
describe('PolarisSettings', () => {
it('renders with interval from props.data', () => {
render(<PolarisSettings data={{ refreshInterval: 60 }} />);
const select = screen.getByRole('combobox');
expect(select).toHaveValue('60');
});
it('falls back to getRefreshInterval when no prop data', () => {
// Default is 300 (5 minutes)
render(<PolarisSettings />);
const select = screen.getByRole('combobox');
expect(select).toHaveValue('300');
});
it('renders all interval options', () => {
render(<PolarisSettings />);
const options = screen.getAllByRole('option');
expect(options).toHaveLength(4);
expect(options[0]).toHaveTextContent('1 minute');
expect(options[1]).toHaveTextContent('5 minutes');
expect(options[2]).toHaveTextContent('10 minutes');
expect(options[3]).toHaveTextContent('30 minutes');
});
it('calls setRefreshInterval and onDataChange when selection changes', async () => {
const onDataChange = vi.fn();
render(<PolarisSettings data={{ refreshInterval: 300 }} onDataChange={onDataChange} />);
const select = screen.getByRole('combobox');
await userEvent.selectOptions(select, '1800');
// Check localStorage was updated
expect(localStorage.getItem('polaris-plugin-refresh-interval')).toBe('1800');
// Check callback was called with merged data
expect(onDataChange).toHaveBeenCalledWith({ refreshInterval: 1800 });
});
it('works without onDataChange callback', async () => {
render(<PolarisSettings data={{ refreshInterval: 300 }} />);
const select = screen.getByRole('combobox');
// Should not throw even without onDataChange
await userEvent.selectOptions(select, '60');
expect(localStorage.getItem('polaris-plugin-refresh-interval')).toBe('60');
});
});
+40
View File
@@ -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>
);
}
-163
View File
@@ -1,163 +0,0 @@
import {
Loader,
SectionBox,
SectionHeader,
} from '@kinvolk/headlamp-plugin/lib/CommonComponents';
import React from 'react';
import {
AuditData,
countResults,
getRefreshInterval,
ResultCounts,
setRefreshInterval,
usePolarisData,
} from '../api/polaris';
const INTERVAL_OPTIONS = [
{ label: '1 minute', value: 60 },
{ label: '5 minutes', value: 300 },
{ label: '10 minutes', value: 600 },
{ 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 }) {
return (
<>
<SectionBox title="Score">
<ScoreBadge score={props.data.Score} />
</SectionBox>
<SectionBox title="Check Summary">
<div
style={{
display: 'flex',
justifyContent: 'center',
flexWrap: 'wrap',
gap: '16px',
}}
>
<StatCard label="Total" value={props.counts.total} />
<StatCard label="Pass" value={props.counts.pass} color="#4caf50" />
<StatCard label="Warning" value={props.counts.warning} color="#ff9800" />
<StatCard label="Danger" value={props.counts.danger} color="#f44336" />
</div>
</SectionBox>
<SectionBox title="Cluster Info">
<div
style={{
display: 'flex',
justifyContent: 'center',
flexWrap: 'wrap',
gap: '16px',
}}
>
<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>
</>
);
}
export default function PolarisView() {
const [interval, setInterval] = React.useState(getRefreshInterval);
function handleIntervalChange(seconds: number) {
setInterval(seconds);
setRefreshInterval(seconds);
}
const { data, loading, error } = usePolarisData(interval);
if (loading) {
return <Loader title="Loading Polaris audit data..." />;
}
const counts = data ? countResults(data) : null;
return (
<>
<SectionHeader title="Polaris" actions={[
<RefreshSettings
key="refresh"
interval={interval}
onChange={handleIntervalChange}
/>,
]} />
{error && (
<SectionBox title="Error">
<div style={{ padding: '16px', color: '#f44336' }}>{error}</div>
</SectionBox>
)}
{data && counts && <OverviewSection data={data} counts={counts} />}
{!data && !error && (
<SectionBox title="No Data">
<div style={{ padding: '16px' }}>
No Polaris audit results found.
</div>
</SectionBox>
)}
</>
);
}
+58 -3
View File
@@ -1,9 +1,16 @@
import {
registerPluginSettings,
registerRoute,
registerSidebarEntry,
} from '@kinvolk/headlamp-plugin/lib';
import React from 'react';
import PolarisView from './components/PolarisView';
import { PolarisDataProvider } from './api/PolarisDataContext';
import DashboardView from './components/DashboardView';
import NamespaceDetailView from './components/NamespaceDetailView';
import NamespacesListView from './components/NamespacesListView';
import PolarisSettings from './components/PolarisSettings';
// --- Sidebar entries ---
registerSidebarEntry({
parent: null,
@@ -13,10 +20,58 @@ registerSidebarEntry({
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',
sidebar: 'polaris-overview',
name: 'polaris',
exact: true,
component: () => <PolarisView />,
component: () => (
<PolarisDataProvider>
<DashboardView />
</PolarisDataProvider>
),
});
registerRoute({
path: '/polaris/namespaces',
sidebar: 'polaris-namespaces',
name: 'polaris-namespaces',
exact: true,
component: () => (
<PolarisDataProvider>
<NamespacesListView />
</PolarisDataProvider>
),
});
registerRoute({
path: '/polaris/ns/:namespace',
sidebar: 'polaris-namespaces',
name: 'polaris-namespace',
exact: true,
component: () => (
<PolarisDataProvider>
<NamespaceDetailView />
</PolarisDataProvider>
),
});
registerPluginSettings('polaris', PolarisSettings, true);
+61
View File
@@ -0,0 +1,61 @@
import React from 'react';
import { AuditData, Result } from './api/polaris';
// --- Fixtures ---
export function makeResult(overrides: Partial<Result> = {}): Result {
return {
Name: 'my-deploy',
Namespace: 'default',
Kind: 'Deployment',
Results: {},
CreatedTime: '2025-01-01T00:00:00Z',
...overrides,
};
}
export function makeAuditData(results: Result[]): AuditData {
return {
PolarisOutputVersion: '1.0',
AuditTime: '2025-01-01T00:00:00Z',
SourceType: 'Cluster',
SourceName: 'test',
DisplayName: 'test',
ClusterInfo: { Version: '1.28', Nodes: 3, Pods: 10, Namespaces: 2, Controllers: 5 },
Results: results,
};
}
// --- Mock Polaris Context Provider ---
interface MockPolarisProviderProps {
data?: AuditData | null;
loading?: boolean;
error?: string | null;
children: React.ReactNode;
}
// We dynamically import PolarisDataContext to inject mock values.
// This avoids mocking the hook module — we supply real context with controlled values.
const PolarisDataContext = React.createContext<{
data: AuditData | null;
loading: boolean;
error: string | null;
} | null>(null);
export function MockPolarisProvider({
data = null,
loading = false,
error = null,
children,
}: MockPolarisProviderProps) {
return (
<PolarisDataContext.Provider value={{ data, loading, error }}>
{children}
</PolarisDataContext.Provider>
);
}
// The context reference used in test-utils must be the SAME object the components import.
// We achieve this by having component tests mock `usePolarisDataContext` to read from our context.
export { PolarisDataContext };
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "@kinvolk/headlamp-plugin/config/plugins-tsconfig.json",
"compilerOptions": {
"types": ["vite/client", "vite-plugin-svgr/client", "vitest/globals", "lodash", "@testing-library/jest-dom"]
},
"include": ["src"]
}
+10
View File
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./vitest.setup.ts'],
exclude: ['e2e/**', 'node_modules/**'],
},
});
+43
View File
@@ -0,0 +1,43 @@
import '@testing-library/jest-dom';
// Node 22+ ships a minimal built-in `localStorage` global (property-bag only,
// no getItem/setItem/removeItem/clear) that shadows jsdom's Web Storage
// implementation. Provide a spec-compliant shim so code under test works.
if (typeof localStorage !== 'undefined' && typeof localStorage.getItem !== 'function') {
const store = new Map<string, string>();
const storage = {
getItem(key: string): string | null {
return store.get(key) ?? null;
},
setItem(key: string, value: string): void {
store.set(key, String(value));
},
removeItem(key: string): void {
store.delete(key);
},
clear(): void {
store.clear();
},
get length(): number {
return store.size;
},
key(index: number): string | null {
return [...store.keys()][index] ?? null;
},
};
Object.defineProperty(globalThis, 'localStorage', {
value: storage,
writable: true,
configurable: true,
});
if (typeof window !== 'undefined') {
Object.defineProperty(window, 'localStorage', {
value: storage,
writable: true,
configurable: true,
});
}
}