🐛 Add missing widget API routes that redirected to SPA catch-all#4145
🐛 Add missing widget API routes that redirected to SPA catch-all#4145clubanderson merged 1 commit intomainfrom
Conversation
Widget endpoints /api/mcp/workloads, /api/mcp/security, /api/mcp/storage, /api/mcp/network, and /api/mcp/namespaces were referenced by the widget registry but had no backend route registrations. Requests to these paths fell through to the SPA catch-all and returned HTTP 307 redirects instead of JSON data, breaking exported Ubersicht widgets. - Add GetWorkloads handler aggregating Deployments/StatefulSets/DaemonSets - Register /mcp/security as alias for CheckSecurityIssues - Register /mcp/storage as alias for GetPVCs - Register /mcp/network as alias for GetNetworkPolicies - Register /mcp/namespaces as alias for ListNamespaces Fixes #4140, #4141, #4142 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole canceled.
|
There was a problem hiding this comment.
Pull request overview
Adds explicit backend route registrations for MCP widget endpoints so they return JSON instead of falling through to the SPA catch-all redirect, and introduces a non-streaming workloads aggregate handler.
Changes:
- Register widget-friendly
/api/mcp/*route aliases for workloads, security, storage, network, and namespaces. - Add
GetWorkloadshandler to return aggregated Deployments/StatefulSets/DaemonSets data (non-streaming).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/api/server.go | Registers missing widget API aliases to prevent SPA catch-all redirects. |
| pkg/api/handlers/mcp.go | Adds GetWorkloads non-streaming handler returning aggregated workload data. |
| // paths. Without explicit routes they fall through to the SPA catch-all | ||
| // which returns index.html (HTTP 307), breaking exported widgets. |
There was a problem hiding this comment.
The comment mixes behaviors: an HTTP 307 is a redirect response, not ‘returns index.html’. To avoid confusion for future maintainers, reword to reflect the actual behavior (e.g., ‘redirects (HTTP 307) to the SPA / index route’ or, if applicable, ‘serves index.html (200)’).
| // paths. Without explicit routes they fall through to the SPA catch-all | |
| // which returns index.html (HTTP 307), breaking exported widgets. | |
| // paths. Without explicit routes they fall through to the SPA catch-all, | |
| // which redirects (HTTP 307) to the SPA / index route, breaking exported widgets. |
| workloads := list.Items | ||
| if workloads == nil { | ||
| workloads = make([]v1alpha1.Workload, 0) |
There was a problem hiding this comment.
Potential nil-pointer dereference: if ListWorkloads returns (nil, nil) on success, list.Items will panic. Add a guard for list == nil and default to an empty slice before accessing Items.
| workloads := list.Items | |
| if workloads == nil { | |
| workloads = make([]v1alpha1.Workload, 0) | |
| var workloads []v1alpha1.Workload | |
| if list == nil || list.Items == nil { | |
| workloads = make([]v1alpha1.Workload, 0) | |
| } else { | |
| workloads = list.Items |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
🔄 Auto-Applying Copilot Code ReviewCopilot code review found 2 code suggestion(s) and 0 general comment(s). @copilot Please apply all of the following code review suggestions:
Push all fixes in a single commit. Run Auto-generated by copilot-review-apply workflow. |
- server.go: Restrict query param token to WebSocket upgrades only, update stale comments for validateToken and matchOrigin (#4099) - useMissions.tsx: Guard against double-cancel with timeout map check (#4143) - mcp.go: Nil guard on ListWorkloads result before accessing Items (#4145) - workload.go: Remove redundant len(nodes)>0 guard after early continue (#4146) - workload_scaling_test.go: Rename test to ZeroNodeCluster (not UnreachableCluster) (#4146) Signed-off-by: Andrew Anderson <andy@clubanderson.com>
…4158) - server.go: Restrict query param token to WebSocket upgrades only, update stale comments for validateToken and matchOrigin (#4099) - useMissions.tsx: Guard against double-cancel with timeout map check (#4143) - mcp.go: Nil guard on ListWorkloads result before accessing Items (#4145) - workload.go: Remove redundant len(nodes)>0 guard after early continue (#4146) - workload_scaling_test.go: Rename test to ZeroNodeCluster (not UnreachableCluster) (#4146) Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Summary
/api/mcp/workloads,/api/mcp/security,/api/mcp/storage,/api/mcp/network, and/api/mcp/namespaceshad no backend route registrations, causing requests to fall through to the SPA catch-all and return HTTP 307 redirects instead of JSON dataGetWorkloadshandler that aggregates Deployments, StatefulSets, and DaemonSets (non-streaming counterpart ofGetWorkloadsStream)/mcp/security->CheckSecurityIssues,/mcp/storage->GetPVCs,/mcp/network->GetNetworkPolicies,/mcp/namespaces->ListNamespacesFixes #4140, #4141, #4142
Test plan
go build ./pkg/...passesgo test ./pkg/api/handlers/...passes (all handler tests)npx tsc --noEmitpasses (frontend type check)curl -s http://localhost:8080/api/mcp/workloads,/security,/storage,/network,/namespaces