-
Notifications
You must be signed in to change notification settings - Fork 484
frontend: Map: Refactor source IDs to make them unique #4253
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
Conversation
476369b to
30e8432
Compare
|
This is the PR I was looking for! Thank you! 🙏 |
frontend/src/components/resourceMap/KubeObjectGlance/KubeObjectGlance.tsx
Show resolved
Hide resolved
30e8432 to
4fddb9c
Compare
There was a problem hiding this 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 refactors resource source IDs in the frontend Map feature to ensure uniqueness when handling custom resources. Previously, sources were identified solely by the kind property, which caused collisions when custom resources used the same kind names as built-in resources (e.g., a CRD with kind "Pod" or "Service"). The new approach uses a combination of API group and kind (apiGroup/kind) to create unique identifiers, with a crd- prefix added to custom resources for additional collision prevention.
- Adds
apiGroupNamestatic getter andisClassOftype guard toKubeObjectclass - Introduces
makeKubeSourceIdutility function to generate unique source IDs - Refactors type checking from string-based
kindcomparisons to type-safeisClassOfguards
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/lib/k8s/KubeObject.ts | Adds apiGroupName getter to extract API group from apiVersion and isClassOf type guard method for type-safe instance checking |
| frontend/src/components/resourceMap/sources/definitions/graphDefinitionUtils.tsx | New utility file with makeKubeSourceId function that creates unique IDs in apiGroup/kind format |
| frontend/src/components/resourceMap/sources/definitions/sources.tsx | Updates source creation to use makeKubeSourceId and adds crd- prefix for custom resource sources |
| frontend/src/components/resourceMap/sources/definitions/relations.tsx | Updates relation definitions to use makeKubeSourceId for consistent source ID generation |
| frontend/src/components/resourceMap/nodes/KubeObjectStatus.tsx | Refactors Pod type checking from string comparison to isClassOf type guard |
| frontend/src/components/resourceMap/KubeObjectGlance/KubeObjectGlance.tsx | Refactors all resource type checks to use isClassOf instead of string-based kind comparisons |
| frontend/src/components/resourceMap/KubeObjectGlance/ReplicaSetGlance.tsx | Updates component signature to accept `ReplicaSet |
| frontend/src/components/resourceMap/graph/graphFiltering.test.ts | Updates test to use proper Pod instances instead of mock objects, adds App import to resolve circular dependency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
frontend/src/components/resourceMap/sources/definitions/graphDefinitionUtils.tsx
Outdated
Show resolved
Hide resolved
frontend/src/components/resourceMap/graph/graphFiltering.test.ts
Outdated
Show resolved
Hide resolved
frontend/src/components/resourceMap/KubeObjectGlance/KubeObjectGlance.tsx
Show resolved
Hide resolved
|
@sniok Wanted to check with you first before merging if you think this is ready to go? I'd like this in 0.39.0. |
…o avoid kind clashes
4fddb9c to
7d559fd
Compare
|
This PR is the initial implementation that will now use apiGroup and apiVersion for stricter code evaluation, which was previously solely reliant on 'kind'. This holds significant meaning for Headlamp's plugin system and will serve as a guideline. Thank you for the implementation! |
illume
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 thanks!
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: illume, sniok The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Currently we naively use
kindproperty to differentiate between different resource types.This is problematic since custom resource instances can have same
kindvalues.To make sure we have unique IDs for sources this PR adds API group, so the new format for IDs is now
apiGroup/kind, for example 'apps/Deployment'. This guarantees unique IDs for each resource.Also for custom resources a
crd-prefix was added to avoid collisions with existing resource definitions we have (for example Gateway API). Ideally we wouldn't have to do this, gateway resources should just be displayed once in the Custom Resources list and extended with information instead of defining separate list/details/kubeobject instances. But that is out of scope for this PR and should be handled in #4240Related Issue
Fixes #4245 #4237
How to test
PodorServiceYAMLs I've used to test
CRDs
Instances