Plugin API: Add registerProjectApiResource for extending project resources#5571
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: NAME-ASHWANIYADAV The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
4f4de93 to
eec54c5
Compare
illume
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
Could you take a look at the commit messages in this PR? We follow a Linux kernel style for git commits — see the contributing guide and git log for examples.
Commits that need attention
projects: add plugin apiResources state— Description must start with a capital letter — e.g.frontend: HomeButton: Fix the buttonnotfrontend: HomeButton: fix the button.plugin: add registerProjectApiResource API— Description must start with a capital letter — e.g.frontend: HomeButton: Fix the buttonnotfrontend: HomeButton: fix the button.projects: merge plugin resources in hook— Description must start with a capital letter — e.g.frontend: HomeButton: Fix the buttonnotfrontend: HomeButton: fix the button.
Commit guidelines
- Use atomic commits focused on a single change.
- Use the title format
<area>: <Description of changes>— description must start with a capital letter. - Keep the title under 72 characters (soft requirement).
- Explain the intention and why the change is needed.
- Make commit titles meaningful and describe what changed.
- Do not add code that a later commit rewrites; squash or reorder commits instead.
- Do not include
Fixes #NNin commit messages.
Good examples:
frontend: HomeButton: Fix so it navigates to homebackend: config: Add enable-dynamic-clusters flag
There was a problem hiding this comment.
Pull request overview
This PR extends Headlamp’s plugin API with a new data-layer extension point so plugins can register additional Kubernetes API resources (e.g., CRDs) to be included in Projects resource fetching, counts, and health calculations.
Changes:
- Added
apiResourcesto the Projects Redux slice plus anaddProjectApiResourceaction for plugin-registered resources. - Added
registerProjectApiResource()to the plugin registry and exported theApiResourcetype for plugin authors. - Updated
useProjectItemsto merge plugin-registered resources with the built-indefaultApiResourceslist.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/redux/projectsSlice.ts | Stores plugin-registered project API resources and exposes a reducer/action to add them. |
| frontend/src/plugin/registry.tsx | Exposes registerProjectApiResource() and re-exports ApiResource for plugin consumption. |
| frontend/src/plugin/snapshots/pluginLib.snapshot | Updates the plugin-lib export snapshot to include registerProjectApiResource. |
| frontend/src/components/project/useProjectResources.ts | Merges default resources with plugin-registered resources when fetching project items. |
| frontend/src/components/project/ProjectCreateFromYaml.stories.tsx | Extends story preloaded state to include projects.apiResources. |
| frontend/src/components/project/NewProjectPopup.stories.tsx | Extends story preloaded state to include projects.apiResources. |
eec54c5 to
e770cc6
Compare
illume
left a comment
There was a problem hiding this comment.
Thanks for this PR.
The CI lint check is failing for the frontend. Can you run cd frontend && npm run lint to find and fix the issues?
How to fix lint errors
Run cd frontend && npm run lint to see all ESLint errors. Many can be fixed automatically with cd frontend && npm run lint -- --fix. Remaining errors need manual attention.
e770cc6 to
ad6c411
Compare
|
@illume please take a look ! |
illume
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
There are some open Copilot review comments — could you take a look at them? Please mark each one as resolved once you've addressed it.
ad6c411 to
f74a6c9
Compare
|
@illume please have a look !! |
27cdfcf to
8f7f5a0
Compare
8f7f5a0 to
2e895ce
Compare
|
@illume please have a look !! |
illume
left a comment
There was a problem hiding this comment.
This is very useful, thanks.
Could you please use this function inside one of the plugins/examples? We try to do this as a form of tutorial for each thing.
This will also need some documentation inside the docs/development/plugins/functionality/index.md ?
In this section:
### Projects customization
2e895ce to
8651ab4
Compare
|
I have added example usage in plugins/examples/projects/src/index.tsx and documentation in docs/development/plugins/functionality/index.md under Projects customization @illume |
| const pluginApiResources = useTypedSelector(state => state.projects.apiResources); | ||
|
|
||
| const resources = useMemo(() => { | ||
| const allResources = defaultApiResources; | ||
| const allResources = [...defaultApiResources, ...pluginApiResources]; | ||
|
|
||
| return uniqBy(allResources, r => apiResourceId(r)); | ||
| }, []); | ||
| }, [pluginApiResources]); |
Closes #5384
What this PR does
Adds a new plugin API function
registerProjectApiResource()that allows plugins to register custom API resources (e.g. CRDs) to be included in Project resource fetching.Currently,
useProjectItemsfetches resources from a hardcodeddefaultApiResourceslist inprojectUtils.ts. Plugins that register tabs or overview sections viaregisterProjectDetailsTab/registerProjectOverviewSectionreceiveprojectResourcesas a prop - but these only include standard Kubernetes resources. CRD-based resources are excluded from:projectResourcespropThis PR completes the Projects extension model by adding a data-layer extension point alongside the existing UI extension points.
Changes
redux/projectsSlice.tsapiResourcesstate +addProjectApiResourcereducer with duplicate preventionplugin/registry.tsxregisterProjectApiResource()function with JSDoc +ApiResourcetype exportcomponents/project/useProjectResources.tsuseSelectorUsage Example
Once registered, the CRD resources will automatically:
projectResourcesprop passed to plugin tabs/sectionsTesting
make frontend-lint- ESLint + Prettier clean ✅kind + apiVersioncheck in reduceruniqBy(apiResourceId)inuseProjectItemsprovides additional deduplication