Skip to content

Commit

Permalink
Add services field to workspace model
Browse files Browse the repository at this point in the history
Signed-off-by: Yehudit Kerido <[email protected]>
  • Loading branch information
Yehudit Kerido committed Feb 24, 2025
1 parent 8648291 commit b1fac0d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
27 changes: 15 additions & 12 deletions workspaces/backend/internal/models/workspaces/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package workspaces

import (
"fmt"
"path"

kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -124,16 +125,17 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
// https://github.com/kubeflow/notebooks/issues/38
LastProbe: nil,
},
Services: buildServicesList(ws, wsk),
}
return workspaceModel
}

func buildPortsList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []ImagePort {
var ports []ImagePort
func buildServicesList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []Service {
//nolint:prealloc
var services []Service

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

// Get the image configuration from the WorkspaceKind's PodTemplate options.
Expand All @@ -145,20 +147,22 @@ func buildPortsList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.Wo
}
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,
basePath := "/workspace"
notebookPath := path.Join(basePath, ws.Namespace, ws.Name, portStr)
service := Service{
HttpService: &HttpService{
DisplayName: displayName,
HttpPath: notebookPath,
},
}
ports = append(ports, imagePort)
services = append(services, service)
}

return ports
return services
}

func wskExists(wsk *kubefloworgv1beta1.WorkspaceKind) bool {
Expand Down Expand Up @@ -251,7 +255,6 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
Current: currentImageConfig,
Desired: desiredImageConfig,
RedirectChain: redirectChain,
Ports: buildPortsList(ws, wsk),
}
}

Expand Down
11 changes: 7 additions & 4 deletions workspaces/backend/internal/models/workspaces/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Workspace struct {
StateMessage string `json:"stateMessage"`
PodTemplate PodTemplate `json:"podTemplate"`
Activity Activity `json:"activity"`
Services []Service `json:"services,omitempty"`
}

type WorkspaceState string
Expand Down Expand Up @@ -84,13 +85,15 @@ type ImageConfig struct {
Current OptionInfo `json:"current"`
Desired *OptionInfo `json:"desired,omitempty"`
RedirectChain []RedirectStep `json:"redirectChain,omitempty"`
Ports []ImagePort `json:"ports,omitempty"`
}

type ImagePort struct {
ID string `json:"id"`
type Service struct {
HttpService *HttpService `json:"httpService,omitempty"`
}

type HttpService struct {
DisplayName string `json:"displayName"`
Port string `json:"port"`
HttpPath string `json:"httpPath"`
}

type PodConfig struct {
Expand Down

0 comments on commit b1fac0d

Please sign in to comment.