Skip to content

feat: add deep-link support for pod exec/terminal via ?view=exec#4941

Open
justinas-wix wants to merge 2 commits intokubernetes-sigs:mainfrom
justinas-wix:feat/exec-deep-link
Open

feat: add deep-link support for pod exec/terminal via ?view=exec#4941
justinas-wix wants to merge 2 commits intokubernetes-sigs:mainfrom
justinas-wix:feat/exec-deep-link

Conversation

@justinas-wix
Copy link
Copy Markdown
Contributor

@justinas-wix justinas-wix commented Mar 23, 2026

Summary

Add support for the ?view=exec query parameter on pod detail pages to auto-launch the terminal/exec Activity panel, mirroring the existing ?view=logs deep-link support.

This enables users to share and bookmark direct links to exec into a specific pod:

/c/<cluster>/pods/<namespace>/<pod-name>?view=exec

Motivation

Headlamp already supports ?view=logs for deep-linking to pod logs. This is useful for sharing links from alerting systems, CI/CD pipelines, runbooks, and incident management tools. The same capability for exec/terminal is a natural complement — teams often need to quickly exec into a pod to debug an issue flagged by monitoring.

Changes

frontend/src/components/pod/Details.tsx:

  • Added a launchTerminal callback (via useCallback), mirroring the existing launchLogs pattern. It calls Activity.launch() with the Terminal component and dispatches the TERMINAL event with OPENED status.
  • Added a useEffect that watches for ?view=exec in the URL query parameters and auto-launches the terminal once the pod data is loaded, using a ref (lastAutoLaunchedPodExec) to prevent duplicate launches — the same pattern used for ?view=logs.
  • Refactored the existing inline terminal launch in the POD_TERMINAL header action button to reuse the new launchTerminal callback instead of inlining the Activity.launch() call, keeping the code DRY and consistent with how launchLogs is already used for the logs button.

frontend/src/components/pod/Details.test.tsx (new):

  • Added unit tests for both ?view=exec (new) and ?view=logs (existing) auto-launch behavior
  • Tests verify Activity.launch is called correctly, not called when param is absent, and not re-triggered on re-renders

Usage

Deep link Behavior
/c/main/pods/default/my-app?view=logs Opens log viewer (existing)
/c/main/pods/default/my-app?view=exec Opens terminal/exec (new)

Test Plan

  • Navigate to /c/<cluster>/pods/<namespace>/<pod>?view=exec — terminal Activity panel should auto-open
  • Navigate to /c/<cluster>/pods/<namespace>/<pod>?view=logs — log viewer should still auto-open (no regression)
  • Navigate to /c/<cluster>/pods/<namespace>/<pod> (no query param) — neither should auto-open
  • Click the "Terminal / Exec" header action button on a pod detail page — terminal should open as before
  • Verify the terminal connects and allows command execution
  • Unit tests pass (npx vitest run src/components/pod/Details.test.tsx)

Add support for the `?view=exec` query parameter on pod detail pages to
auto-launch the terminal/exec Activity panel, mirroring the existing
`?view=logs` deep-link support.

This enables users to share and bookmark direct links to exec into a
specific pod, e.g.:
  /c/main/pods/default/my-app?view=exec

Also refactors the terminal launch logic into a reusable `launchTerminal`
callback (consistent with the existing `launchLogs` pattern), which the
header action button now reuses instead of inlining.

Signed-off-by: justinas-wix <justinask@wix.com>
Made-with: Cursor
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: justinas-wix
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 added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 23, 2026
@justinas-wix justinas-wix force-pushed the feat/exec-deep-link branch 2 times, most recently from d90fcd6 to c3183e6 Compare March 23, 2026 10:45
Add tests for the PodDetails component to verify the auto-launch
behavior for both ?view=exec (new) and ?view=logs (existing):

- Terminal Activity is launched when ?view=exec is in the URL
- Logs Activity is launched when ?view=logs is in the URL
- Nothing is launched when no view param is present
- Nothing is launched for unrecognized view param values
- Terminal is not re-launched on subsequent renders for the same pod
- TERMINAL event is dispatched with OPENED status for exec deep-link

Signed-off-by: justinas-wix <justinask@wix.com>
Made-with: Cursor
@justinas-wix
Copy link
Copy Markdown
Contributor Author

Sorry I have messed up previous PR with squashing to much and then force pushing on top...

  • Opened new one instead to make history clean.
  • Added tests please review when you have time.

Appreciated!!!

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants