feat: allow resource scoped gadget embedding - #106
Open
alronova wants to merge 1 commit into
Open
Conversation
Signed-off-by: alronova <aditya.divyam001@gmail.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: scope embedded gadgets to specific resource (Pod/Node) only
Description
When a user embedded a gadget from a Pod or Node details page, the record stored in
localStorage['headlamp_embeded_resources']only persisted the resourcekindandcluster, no specific resource identity. Every other resource of the same kind in the cluster would then display the gadget, causing visibility leaks, unintended cross-resource sharing, and destructive cross-impact on deletes.This fix makes the embed system exclusively resource-scoped: every embedded gadget is now bound to the exact Pod or Node it was created from. There is no longer a "kind-wide" global embed mode. A new
embeddedResourcefield (containingkind,name,namespace?, andcluster) is written at creation time and used as the single matching key on the read path. Records withoutembeddedResource(legacy global entries) will not match and are silently not shown.Implementation Details
src/common/embedScoping.tsxA self-contained helper module that is the single source of truth for all embed-scoping logic. No other file duplicates the matching logic.
EmbeddedResourceRef,GadgetInstancederiveResourceRef(jsonData, cluster): builds a normalized{ kind, name, namespace?, cluster }ref fromresource.jsonDatadoesInstanceMatchResource(instance, resourceJson, cluster): requiresembeddedResourceto be present; matches on kind, name, cluster, and namespace (when applicable). Instances withoutembeddedResourcereturnfalse.hasEmbeddedInstancesForResource(instances, resourceJson, cluster): quick existence check used by the section gatesrc/common/gadgetbackgroundinstanceform.tsxWhen
resourceprop is a real object, the new instance now persists:When
resourceis absent (fallback path),isEmbeddedis set tofalseand noembeddedResourceis written, so it never surfaces in any embed view.src/gadgets/gadgetDetails.tsxBoth
handleRun(on-demand → headless) anddeleteHeadlessGadget(headless → on-demand) rebuild a freshlocalStoragerecord. Both now copyembeddedResourcefrom the original so the resource binding survives mode transitions.src/common/helpers.tsxPreserves
embeddedResourceon all transitions whereembedView !== 'None'. Clears it (along withkindandisEmbedded) only when detaching (embedView === 'None').Read paths:
src/index.tsx+src/gadgets/resourcegadgets.tsxindex.tsxgate: replaced kind-only check withhasEmbeddedInstancesForResource; also fixed a pre-existing bug whereclusterwas not checked at the gate levelresourcegadgets.tsxfilter: replaced two-step kind + cluster filter withdoesInstanceMatchResource, gate and renderer now use identical logicsrc/common/GadgetDescription/index.tsxThe Embed Type
<Select>on the standalone gadget details page is disabled wheneverembeddedResourceis present (i.e., always for new records), with a clear tooltip:Testing Done
Before
2026-04-12.11-37-13.mp4
After
2026-04-20.18-26-35.mp4
Now, the gadgets are being embedded and managed specific to each pod.
Checklist