Skip to content

Plugin API: Add registerProjectApiResource for extending project resources#5571

Open
NAME-ASHWANIYADAV wants to merge 3 commits into
kubernetes-sigs:mainfrom
NAME-ASHWANIYADAV:feat/register-project-api-resource
Open

Plugin API: Add registerProjectApiResource for extending project resources#5571
NAME-ASHWANIYADAV wants to merge 3 commits into
kubernetes-sigs:mainfrom
NAME-ASHWANIYADAV:feat/register-project-api-resource

Conversation

@NAME-ASHWANIYADAV
Copy link
Copy Markdown
Contributor

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV commented May 11, 2026

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, useProjectItems fetches resources from a hardcoded defaultApiResources list in projectUtils.ts. Plugins that register tabs or overview sections via registerProjectDetailsTab / registerProjectOverviewSection receive projectResources as a prop - but these only include standard Kubernetes resources. CRD-based resources are excluded from:

  • Project resource counts
  • Health status indicators
  • The Resources tab
  • Plugin tab/section projectResources prop

This PR completes the Projects extension model by adding a data-layer extension point alongside the existing UI extension points.

Changes

File Change
redux/projectsSlice.ts Add apiResources state + addProjectApiResource reducer with duplicate prevention
plugin/registry.tsx Add registerProjectApiResource() function with JSDoc + ApiResource type export
components/project/useProjectResources.ts Merge plugin-registered resources with defaults via useSelector

Usage Example

import { registerProjectApiResource } from '@kinvolk/headlamp-plugin/lib';

registerProjectApiResource({
  apiVersion: 'argoproj.io/v1alpha1',
  version: 'v1alpha1',
  groupName: 'argoproj.io',
  pluralName: 'applications',
  singularName: 'application',
  kind: 'Application',
  isNamespaced: true,
});

Once registered, the CRD resources will automatically:

  • Appear in the project's resource count and health status
  • Be available in projectResources prop passed to plugin tabs/sections
  • Use the existing namespace filtering, cluster scoping, and watch/polling logic

Testing

  • make frontend-lint - ESLint + Prettier clean ✅
  • Duplicate registration is safely handled via kind + apiVersion check in reducer
  • Existing uniqBy(apiResourceId) in useProjectItems provides additional deduplication

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 11, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: NAME-ASHWANIYADAV
Once this PR has been reviewed and has the lgtm label, please assign ashu8912 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from skoeva and vyncent-t May 11, 2026 20:09
@NAME-ASHWANIYADAV NAME-ASHWANIYADAV force-pushed the feat/register-project-api-resource branch 3 times, most recently from 4f4de93 to eec54c5 Compare May 11, 2026 20:44
@NAME-ASHWANIYADAV
Copy link
Copy Markdown
Contributor Author

NAME-ASHWANIYADAV commented May 11, 2026

The test plugins (22.x, ubuntu-22.04) failure is unrelated to this PR - it's a pre-existing e2e infrastructure issue where the plugin metadata endpoint returns HTTP 404 @ashu8912 @skoeva @illume

@illume illume requested a review from Copilot May 12, 2026 06:55
Copy link
Copy Markdown
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 button not frontend: HomeButton: fix the button.
  • plugin: add registerProjectApiResource API — Description must start with a capital letter — e.g. frontend: HomeButton: Fix the button not frontend: HomeButton: fix the button.
  • projects: merge plugin resources in hook — Description must start with a capital letter — e.g. frontend: HomeButton: Fix the button not frontend: 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 #NN in commit messages.

Good examples:

  • frontend: HomeButton: Fix so it navigates to home
  • backend: config: Add enable-dynamic-clusters flag

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 apiResources to the Projects Redux slice plus an addProjectApiResource action for plugin-registered resources.
  • Added registerProjectApiResource() to the plugin registry and exported the ApiResource type for plugin authors.
  • Updated useProjectItems to merge plugin-registered resources with the built-in defaultApiResources list.

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.

Comment thread frontend/src/components/project/useProjectResources.ts Outdated
Comment thread frontend/src/redux/projectsSlice.ts
Comment thread frontend/src/plugin/registry.tsx
Comment thread frontend/src/plugin/registry.tsx Outdated
@NAME-ASHWANIYADAV NAME-ASHWANIYADAV force-pushed the feat/register-project-api-resource branch from eec54c5 to e770cc6 Compare May 12, 2026 08:01
@NAME-ASHWANIYADAV
Copy link
Copy Markdown
Contributor Author

@illume i have updated the commit message according to the guideline and resolved all co-pilot comments
will appreciate a re-review @illume

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV requested a review from illume May 12, 2026 08:10
@illume illume requested a review from Copilot May 12, 2026 14:00
Copy link
Copy Markdown
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV force-pushed the feat/register-project-api-resource branch from e770cc6 to ad6c411 Compare May 14, 2026 11:22
@NAME-ASHWANIYADAV NAME-ASHWANIYADAV requested a review from illume May 14, 2026 11:23
@NAME-ASHWANIYADAV
Copy link
Copy Markdown
Contributor Author

@illume please take a look !

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread frontend/src/components/project/useProjectResources.ts
Copy link
Copy Markdown
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV force-pushed the feat/register-project-api-resource branch from ad6c411 to f74a6c9 Compare May 16, 2026 15:51
@NAME-ASHWANIYADAV NAME-ASHWANIYADAV requested a review from illume May 16, 2026 15:52
@NAME-ASHWANIYADAV
Copy link
Copy Markdown
Contributor Author

@illume please have a look !!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread frontend/src/plugin/registry.tsx
@NAME-ASHWANIYADAV NAME-ASHWANIYADAV force-pushed the feat/register-project-api-resource branch 3 times, most recently from 27cdfcf to 8f7f5a0 Compare May 17, 2026 10:15
@illume illume requested a review from Copilot May 17, 2026 10:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV force-pushed the feat/register-project-api-resource branch from 8f7f5a0 to 2e895ce Compare May 17, 2026 10:22
@illume illume requested a review from Copilot May 17, 2026 10:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@NAME-ASHWANIYADAV
Copy link
Copy Markdown
Contributor Author

@illume please have a look !!

Copy link
Copy Markdown
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV force-pushed the feat/register-project-api-resource branch from 2e895ce to 8651ab4 Compare May 18, 2026 01:48
@NAME-ASHWANIYADAV
Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment on lines +33 to +39
const pluginApiResources = useTypedSelector(state => state.projects.apiResources);

const resources = useMemo(() => {
const allResources = defaultApiResources;
const allResources = [...defaultApiResources, ...pluginApiResources];

return uniqBy(allResources, r => apiResourceId(r));
}, []);
}, [pluginApiResources]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin API: Allow plugins to register custom API resources for the Projects view

4 participants