Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ws): Notebooks 2.0 // Backend// Add missing field #213

Open
wants to merge 2 commits into
base: notebooks-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions workspaces/backend/internal/models/workspaces/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,39 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
return workspaceModel
}

func buildPortsList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []ImagePort {
var ports []ImagePort

// Return an empty list if wsk is nil.
if !wskExists(wsk) {
return ports
}

// Get the image configuration from the WorkspaceKind's PodTemplate options.
imageConfig := wsk.Spec.PodTemplate.Options.ImageConfig

for _, val := range imageConfig.Values {
if len(val.Spec.Ports) == 0 {
continue
}
firstPort := val.Spec.Ports[0]
portStr := fmt.Sprintf("%d", firstPort.Port)
id := firstPort.Id
displayName := firstPort.DisplayName
if displayName == "" {
displayName = val.Id
}
imagePort := ImagePort{
ID: id,
DisplayName: displayName,
Port: portStr,
}
ports = append(ports, imagePort)
}

return ports
}

func wskExists(wsk *kubefloworgv1beta1.WorkspaceKind) bool {
return wsk != nil && wsk.UID != ""
}
Expand Down Expand Up @@ -218,6 +251,7 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
Current: currentImageConfig,
Desired: desiredImageConfig,
RedirectChain: redirectChain,
Ports: buildPortsList(ws, wsk),
}
}

Expand Down
7 changes: 7 additions & 0 deletions workspaces/backend/internal/models/workspaces/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ type ImageConfig struct {
Current OptionInfo `json:"current"`
Desired *OptionInfo `json:"desired,omitempty"`
RedirectChain []RedirectStep `json:"redirect_chain,omitempty"`
Ports []ImagePort `json:"ports,omitempty"`
}

type ImagePort struct {
Copy link
Member

@thesuperzapper thesuperzapper Feb 20, 2025

Choose a reason for hiding this comment

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

@yehudit1987 it might be more useful for the frontend if we do something more abstract like "services" (which initially only includes "HTTP" type services).

That makes it a bit easier to populate the front-end "connect" box, because rather than constructing the HTTP path in the front end we could just include the httpPath (relative to the UI base, not absolute) rather than constructing it in the front end.

Also, stuff like "port number" don't need to be included because this is hidden from the end user.

For example (written in YAML for clarity, but payload is JSON in app):

...
  services:
    - httpService:
       displayName: "XXXXX"
       httpPath: "/workspace/{namespace}/{workspace_name}/{port_id}/

ID string `json:"id"`
DisplayName string `json:"displayName"`
Port string `json:"port"`
}

type PodConfig struct {
Expand Down
Loading