Skip to content

Commit 82b435d

Browse files
Yehudit Keridothesuperzapper
authored andcommitted
Add services field to workspace model
Signed-off-by: Yehudit Kerido <yehudit.kerido@nokia.com>
1 parent ddd6ebb commit 82b435d

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

workspaces/backend/internal/models/workspaces/funcs.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package workspaces
1818

1919
import (
2020
"fmt"
21+
"path"
2122

2223
kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
2324
"k8s.io/utils/ptr"
@@ -124,16 +125,17 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
124125
// https://github.com/kubeflow/notebooks/issues/38
125126
LastProbe: nil,
126127
},
128+
Services: buildServicesList(ws, wsk),
127129
}
128130
return workspaceModel
129131
}
130132

131-
func buildPortsList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []ImagePort {
132-
var ports []ImagePort
133+
func buildServicesList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []Service {
134+
//nolint:prealloc
135+
var services []Service
133136

134-
// Return an empty list if wsk is nil.
135137
if !wskExists(wsk) {
136-
return ports
138+
return services
137139
}
138140

139141
// Get the image configuration from the WorkspaceKind's PodTemplate options.
@@ -145,20 +147,22 @@ func buildPortsList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.Wo
145147
}
146148
firstPort := val.Spec.Ports[0]
147149
portStr := fmt.Sprintf("%d", firstPort.Port)
148-
id := firstPort.Id
149150
displayName := firstPort.DisplayName
150151
if displayName == "" {
151152
displayName = val.Id
152153
}
153-
imagePort := ImagePort{
154-
ID: id,
155-
DisplayName: displayName,
156-
Port: portStr,
154+
basePath := "/workspace"
155+
notebookPath := path.Join(basePath, ws.Namespace, ws.Name, portStr)
156+
service := Service{
157+
HttpService: &HttpService{
158+
DisplayName: displayName,
159+
HttpPath: notebookPath,
160+
},
157161
}
158-
ports = append(ports, imagePort)
162+
services = append(services, service)
159163
}
160164

161-
return ports
165+
return services
162166
}
163167

164168
func wskExists(wsk *kubefloworgv1beta1.WorkspaceKind) bool {
@@ -251,7 +255,6 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
251255
Current: currentImageConfig,
252256
Desired: desiredImageConfig,
253257
RedirectChain: redirectChain,
254-
Ports: buildPortsList(ws, wsk),
255258
}
256259
}
257260

workspaces/backend/internal/models/workspaces/types.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Workspace struct {
2929
StateMessage string `json:"stateMessage"`
3030
PodTemplate PodTemplate `json:"podTemplate"`
3131
Activity Activity `json:"activity"`
32+
Services []Service `json:"services,omitempty"`
3233
}
3334

3435
type WorkspaceState string
@@ -84,13 +85,15 @@ type ImageConfig struct {
8485
Current OptionInfo `json:"current"`
8586
Desired *OptionInfo `json:"desired,omitempty"`
8687
RedirectChain []RedirectStep `json:"redirectChain,omitempty"`
87-
Ports []ImagePort `json:"ports,omitempty"`
8888
}
8989

90-
type ImagePort struct {
91-
ID string `json:"id"`
90+
type Service struct {
91+
HttpService *HttpService `json:"httpService,omitempty"`
92+
}
93+
94+
type HttpService struct {
9295
DisplayName string `json:"displayName"`
93-
Port string `json:"port"`
96+
HttpPath string `json:"httpPath"`
9497
}
9598

9699
type PodConfig struct {

0 commit comments

Comments
 (0)