Skip to content

fix: default empty workspace state to Unknown in API responses#1167

Open
yanmo42 wants to merge 1 commit into
kubeflow:notebooks-v2from
yanmo42:platypus/kubeflow-1104-backend-default-state
Open

fix: default empty workspace state to Unknown in API responses#1167
yanmo42 wants to merge 1 commit into
kubeflow:notebooks-v2from
yanmo42:platypus/kubeflow-1104-backend-default-state

Conversation

@yanmo42

@yanmo42 yanmo42 commented Jun 7, 2026

Copy link
Copy Markdown

Refs #1104. Replaces #1157.

Summary

  • Default ws.Status.State to WorkspaceStateUnknown in NewWorkspaceListItemFromWorkspace so the list-workspaces API never returns "state": "".
  • Add a defaultWorkspaceState helper plus a unit test.

Root cause

workspaces/backend/internal/models/workspaces/funcs.go was copying ws.Status.State verbatim. WorkspaceState is a string-aliased Go type (zero value ""), and the JSON tag is json:"state" (no omitempty), so a workspace whose controller had not yet reconciled a status was serialised with an empty state field. This contradicts the generated OpenAPI/TS contract, which declares the field as the non-empty V1Beta1WorkspaceState enum, 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 -d clean

AI Assistance

Prepared with AI assistance from Claude. The commit includes an Assisted-by trailer.

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>
@github-project-automation github-project-automation Bot moved this to Needs Triage in Kubeflow Notebooks Jun 7, 2026
@google-oss-prow google-oss-prow Bot added the area/backend area - related to backend components label Jun 7, 2026
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign andyatmiami for approval. For more information see the Kubernetes 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

@Snehadas2005 Snehadas2005 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. Synchronise Workspace Status in PVC References: When querying PVC details, the buildWorkspaceInfoMap helper directly copies the workspace state. Setting it to WorkspaceStateUnknown helps avoid duplicate missing tooltips or empty-state UI artefacts in the PVC overlay views. Could you please add some similar adjustments in the file workspaces/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,
}
  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/backend area - related to backend components area/v2 area - version - kubeflow notebooks v2 size/M

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants