fix: default empty workspace state to Unknown in API responses#1167
fix: default empty workspace state to Unknown in API responses#1167yanmo42 wants to merge 1 commit into
Conversation
The list-workspaces API was copying ws.Status.State verbatim, so a workspace whose controller had not yet reconciled a status was serialised with "state": "" — leaving frontend label cells visually empty (the symptom in kubeflow#1104) and contradicting the generated OpenAPI contract, which declares the field as the non-empty V1Beta1WorkspaceState enum. Default ws.Status.State to WorkspaceStateUnknown when it is the zero value so the API always honours the contract, and remove the need for defensive fallbacks in clients. Also adds a unit test for the helper. Refs kubeflow#1104 Assisted-by: Claude (Anthropic) Signed-off-by: Ian Moog <ianmoog42@gmail.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 |
Snehadas2005
left a comment
There was a problem hiding this comment.
I have a few suggestions regarding the core fix. I think it effectively addresses the root cause in NewWorkspaceListItemFromWorkspace, which helps prevent empty-state values in the primary workspace list views.
To ensure complete coverage and avoid identical symptoms across other parts of the UI, it would be highly beneficial to address one more internal mapper that currently copies ws.Status.State directly. Including it here will maintain strict structural consistency across the repository.
- Synchronise Workspace Status in PVC References: When querying PVC details, the
buildWorkspaceInfoMaphelper directly copies the workspace state. Setting it toWorkspaceStateUnknownhelps avoid duplicate missing tooltips or empty-state UI artefacts in the PVC overlay views. Could you please add some similar adjustments in the fileworkspaces/backend/internal/repositories/pvcs/repo.go?
state := ws.Status.State
if state == "" {
state = kubefloworgv1beta1.WorkspaceStateUnknown
}
wsInfo := models.WorkspaceInfo{
Name: ws.Name,
State: state,
StateMessage: ws.Status.StateMessage,
}
- Accompanying PVC Handler Test Update: Updating the mapper above means the mock workspace setup in the PVC handler test suite will expect the explicit "Unknown" enum alignment instead of a raw empty string. Can you make changes like the ones below in the file
workspaces/backend/api/pvcs_handler_test.go?
Workspaces: []models.WorkspaceInfo{
{
Name: workspaceName1,
State: kubefloworgv1beta1.WorkspaceStateUnknown,
},
},
Once these data boundaries are aligned, this task is fully future-proofed.
Refs #1104. Replaces #1157.
Summary
ws.Status.StatetoWorkspaceStateUnknowninNewWorkspaceListItemFromWorkspaceso the list-workspaces API never returns"state": "".defaultWorkspaceStatehelper plus a unit test.Root cause
workspaces/backend/internal/models/workspaces/funcs.gowas copyingws.Status.Stateverbatim.WorkspaceStateis a string-aliased Go type (zero value""), and the JSON tag isjson:"state"(noomitempty), so a workspace whose controller had not yet reconciled a status was serialised with an emptystatefield. This contradicts the generated OpenAPI/TS contract, which declares the field as the non-emptyV1Beta1WorkspaceStateenum, and is the source of the empty-label "circle icon" symptom in #1104.Fixing it server-side keeps the contract honest and removes the need for defensive fallbacks in every client surface (table cell, PVC tooltip, etc.).
Context
Originally raised as a frontend fallback in #1157; @thaorell correctly flagged the fallback as redundant against the type contract. Tracing the symptom in the backend surfaced the real source.
Validation
go test ./workspaces/backend/internal/models/workspaces/...go vet ./workspaces/backend/internal/models/workspaces/...gofmt -dcleanAI Assistance
Prepared with AI assistance from Claude. The commit includes an
Assisted-bytrailer.