Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend Map: Allow plugins to customize the map #2602

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Conversation

sniok
Copy link
Contributor

@sniok sniok commented Nov 22, 2024

Basic Map extension

This PR introduces 3 new functions that allow for the simplest case of extending the Map.

You can read the full docs page over here https://github.com/headlamp-k8s/headlamp/blob/d02531292dd770360d127a792d345e82428ad994/docs/development/plugins/functionality/extending-the-map.md

You can add your own nodes and edges, customize the icon for the nodes and show a details page for the node.

  1. registerMapSource
    registers a "Source" which provides Nodes and Edges to the map

  2. registerKindIcon
    adds an icon for a specific resource "kind", which is displayed on the node and the map search (not the global one)

  3. registerKindDetailsPage
    registers details panel for a specific resource "kind"

Reasoning and intentions

The registerKindIcon and registerKindDetailsPage don't mention Map and have a generic name (and not registerMapNodeIcon for example) for a reason.
I think in the near future this can be used in other places and not just Map.
For example KindIcon can be used in the global search, and Details component can be used in the normal Details page for custom resources.
For now the customizations are very granular to keep it simple but I think in the future we should have an ability to register a custom resource that will integrate it everywhere all at once, something like this:

registerCustomResource(params) {
  registerKindIcon(...);
  registerKindDetailsPage(...);
  registerMapSource(...);
  registerGlobalSearch(...);
  registerSidebarItem(...);
  registerRoute(...);
}

which I think would be extremely useful since a lot of plugins are listing/displaying custom resources.

@sniok sniok force-pushed the map-plugins branch 4 times, most recently from f434b04 to d025312 Compare November 27, 2024 11:32
@sniok sniok changed the title WIP frontend Map: Allow plugins to customize the map frontend Map: Allow plugins to customize the map Nov 27, 2024
@sniok sniok marked this pull request as ready for review November 27, 2024 11:39
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 27, 2024
@sniok sniok requested a review from a team November 27, 2024 11:39
@sniok sniok added resourceMap frontend Issues related to the frontend plugins labels Nov 29, 2024
Copy link
Collaborator

@joaquimrocha joaquimrocha left a comment

Choose a reason for hiding this comment

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

This looks very reasonable. I have 2 questions, however:

  1. Does it makes sense somehow to unify the details page for the map and for other places?Right now we have the notion of a details route, associated with a KubeObject, but a component is registered for this just as a normal route by using registerRoute.
  2. I think the "framework" you are proposing matches a lot the case where we want to display kubernetes resources, but I wonder if it makes sense to abstract it to something that is not Kubernetes specific. Say e.g. we want to display users? Or we want to display clusters?

@sniok
Copy link
Contributor Author

sniok commented Dec 5, 2024

  1. Does it makes sense somehow to unify the details page for the map and for other places?Right now we have the notion of a details route, associated with a KubeObject, but a component is registered for this just as a normal route by using registerRoute.

Absolutely, I think would be perfect for adding details page, especially for custom resources. Even now we could already replace all routes to render KubeObjectDetails component.

  1. I think the "framework" you are proposing matches a lot the case where we want to display kubernetes resources, but I wonder if it makes sense to abstract it to something that is not Kubernetes specific. Say e.g. we want to display users? Or we want to display clusters?

Yes it can support other objects as well, when we register a source it currently only returns nodes with the type "kubeObject" but it can return any type. The only missing piece for now is registering custom node type.

So it is going to look something like this:

// register customUser type
registerNodeType('customUser', { renderNode: (nodeData) => <div>{nodeData.name}</div> } ))

registerMapSource({
   useData() {
      // specify type and pass any data
      return {  nodes: [{ id: 'some-user', type: 'customUser', data: { name: 'user-name' } }] }
   }
})

@sniok
Copy link
Contributor Author

sniok commented Dec 16, 2024

Removed the registerKindDetailsPage method from this PR as it needs some more investigation and thought

@sniok sniok marked this pull request as draft January 8, 2025 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Issues related to the frontend plugins resourceMap size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants