Skip to content

Commit 9ff2483

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

File tree

1 file changed

+20
-15
lines changed
  • workspaces/backend/internal/models/workspaces

1 file changed

+20
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,37 +131,42 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
131131
}
132132

133133
func buildServicesList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []Service {
134-
//nolint:prealloc
135-
var services []Service
136-
137134
if !wskExists(wsk) {
138-
return services
135+
return nil
139136
}
140137

141-
// Get the image configuration from the WorkspaceKind's PodTemplate options.
142138
imageConfig := wsk.Spec.PodTemplate.Options.ImageConfig
139+
basePath := "/workspace"
140+
namespacePath := path.Join(basePath, ws.Namespace, ws.Name)
141+
142+
services := make([]Service, 0, len(imageConfig.Values))
143143

144144
for _, val := range imageConfig.Values {
145-
if len(val.Spec.Ports) == 0 {
146-
continue
147-
}
148-
firstPort := val.Spec.Ports[0]
149-
portStr := fmt.Sprintf("%d", firstPort.Port)
150-
displayName := firstPort.DisplayName
145+
services = append(services, extractServices(&val, namespacePath)...)
146+
}
147+
return services
148+
}
149+
150+
func extractServices(val *kubefloworgv1beta1.ImageConfigValue, namespacePath string) []Service {
151+
if len(val.Spec.Ports) == 0 {
152+
return []Service{}
153+
}
154+
155+
services := make([]Service, 0, len(val.Spec.Ports))
156+
157+
for _, port := range val.Spec.Ports {
158+
displayName := port.DisplayName
151159
if displayName == "" {
152160
displayName = val.Id
153161
}
154-
basePath := "/workspace"
155-
notebookPath := path.Join(basePath, ws.Namespace, ws.Name, portStr)
156162
service := Service{
157163
HttpService: &HttpService{
158164
DisplayName: displayName,
159-
HttpPath: notebookPath,
165+
HttpPath: path.Join(namespacePath, fmt.Sprintf("%d", port.Port)),
160166
},
161167
}
162168
services = append(services, service)
163169
}
164-
165170
return services
166171
}
167172

0 commit comments

Comments
 (0)