@@ -18,7 +18,6 @@ package workspaces
18
18
19
19
import (
20
20
"fmt"
21
- "path"
22
21
23
22
kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
24
23
"k8s.io/utils/ptr"
@@ -90,6 +89,9 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
90
89
}
91
90
}
92
91
92
+ imageConfigModel , imageConfigValue := buildImageConfig (ws , wsk )
93
+ podConfigModel , _ := buildPodConfig (ws , wsk )
94
+
93
95
workspaceModel := Workspace {
94
96
Name : ws .Name ,
95
97
Namespace : ws .Namespace ,
@@ -114,8 +116,8 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
114
116
Data : dataVolumes ,
115
117
},
116
118
Options : PodTemplateOptions {
117
- ImageConfig : buildImageConfig ( ws , wsk ) ,
118
- PodConfig : buildPodConfig ( ws , wsk ) ,
119
+ ImageConfig : imageConfigModel ,
120
+ PodConfig : podConfigModel ,
119
121
},
120
122
},
121
123
Activity : Activity {
@@ -125,51 +127,11 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
125
127
// https://github.com/kubeflow/notebooks/issues/38
126
128
LastProbe : nil ,
127
129
},
128
- Services : buildServicesList (ws , wsk ),
130
+ Services : buildServices (ws , imageConfigValue ),
129
131
}
130
132
return workspaceModel
131
133
}
132
134
133
- func buildServicesList (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) []Service {
134
- if ! wskExists (wsk ) {
135
- return nil
136
- }
137
-
138
- 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 ))
143
-
144
- for _ , val := range imageConfig .Values {
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
159
- if displayName == "" {
160
- displayName = val .Id
161
- }
162
- service := Service {
163
- HttpService : & HttpService {
164
- DisplayName : displayName ,
165
- HttpPath : path .Join (namespacePath , port .Id ),
166
- },
167
- }
168
- services = append (services , service )
169
- }
170
- return services
171
- }
172
-
173
135
func wskExists (wsk * kubefloworgv1beta1.WorkspaceKind ) bool {
174
136
return wsk != nil && wsk .UID != ""
175
137
}
@@ -193,7 +155,7 @@ func buildHomeVolume(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.W
193
155
}
194
156
}
195
157
196
- func buildImageConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ImageConfig {
158
+ func buildImageConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ( ImageConfig , * kubefloworgv1beta1. ImageConfigValue ) {
197
159
// create a map of image configs from the WorkspaceKind for easy lookup by ID
198
160
// NOTE: we can only build this map if the WorkspaceKind exists, otherwise it will be empty
199
161
imageConfigMap := make (map [string ]kubefloworgv1beta1.ImageConfigValue )
@@ -205,13 +167,15 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
205
167
}
206
168
207
169
// get the current image config
170
+ var currentImageConfigValue * kubefloworgv1beta1.ImageConfigValue
208
171
currentImageConfig := OptionInfo {
209
172
Id : ws .Spec .PodTemplate .Options .ImageConfig ,
210
173
DisplayName : UnknownImageConfig ,
211
174
Description : UnknownImageConfig ,
212
175
Labels : nil ,
213
176
}
214
177
if cfg , ok := imageConfigMap [currentImageConfig .Id ]; ok {
178
+ currentImageConfigValue = & cfg
215
179
currentImageConfig .DisplayName = cfg .Spawner .DisplayName
216
180
currentImageConfig .Description = ptr .Deref (cfg .Spawner .Description , "" )
217
181
currentImageConfig .Labels = buildOptionLabels (cfg .Spawner .Labels )
@@ -260,10 +224,10 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
260
224
Current : currentImageConfig ,
261
225
Desired : desiredImageConfig ,
262
226
RedirectChain : redirectChain ,
263
- }
227
+ }, currentImageConfigValue
264
228
}
265
229
266
- func buildPodConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) PodConfig {
230
+ func buildPodConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ( PodConfig , * kubefloworgv1beta1. PodConfigValue ) {
267
231
// create a map of pod configs from the WorkspaceKind for easy lookup by ID
268
232
// NOTE: we can only build this map if the WorkspaceKind exists, otherwise it will be empty
269
233
podConfigMap := make (map [string ]kubefloworgv1beta1.PodConfigValue )
@@ -275,13 +239,15 @@ func buildPodConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.Wo
275
239
}
276
240
277
241
// get the current pod config
242
+ var currentPodConfigValue * kubefloworgv1beta1.PodConfigValue
278
243
currentPodConfig := OptionInfo {
279
244
Id : ws .Spec .PodTemplate .Options .PodConfig ,
280
245
DisplayName : UnknownPodConfig ,
281
246
Description : UnknownPodConfig ,
282
247
Labels : nil ,
283
248
}
284
249
if cfg , ok := podConfigMap [currentPodConfig .Id ]; ok {
250
+ currentPodConfigValue = & cfg
285
251
currentPodConfig .DisplayName = cfg .Spawner .DisplayName
286
252
currentPodConfig .Description = ptr .Deref (cfg .Spawner .Description , "" )
287
253
currentPodConfig .Labels = buildOptionLabels (cfg .Spawner .Labels )
@@ -330,7 +296,7 @@ func buildPodConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.Wo
330
296
Current : currentPodConfig ,
331
297
Desired : desiredPodConfig ,
332
298
RedirectChain : redirectChain ,
333
- }
299
+ }, currentPodConfigValue
334
300
}
335
301
336
302
func buildOptionLabels (labels []kubefloworgv1beta1.OptionSpawnerLabel ) []OptionLabel {
@@ -364,3 +330,23 @@ func buildRedirectMessage(msg *kubefloworgv1beta1.RedirectMessage) *RedirectMess
364
330
Level : messageLevel ,
365
331
}
366
332
}
333
+
334
+ func buildServices (ws * kubefloworgv1beta1.Workspace , imageConfigValue * kubefloworgv1beta1.ImageConfigValue ) []Service {
335
+ if imageConfigValue == nil {
336
+ return nil
337
+ }
338
+
339
+ services := make ([]Service , len (imageConfigValue .Spec .Ports ))
340
+ for i := range imageConfigValue .Spec .Ports {
341
+ port := imageConfigValue .Spec .Ports [i ]
342
+ switch port .Protocol { //nolint:gocritic
343
+ case kubefloworgv1beta1 .ImagePortProtocolHTTP :
344
+ services [i ].HttpService = & HttpService {
345
+ DisplayName : port .DisplayName ,
346
+ HttpPath : fmt .Sprintf ("/workspace/%s/%s/%s/" , ws .Namespace , ws .Name , port .Id ),
347
+ }
348
+ }
349
+ }
350
+
351
+ return services
352
+ }
0 commit comments