@@ -89,6 +89,9 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
89
89
}
90
90
}
91
91
92
+ imageConfigModel , imageConfigValue := buildImageConfig (ws , wsk )
93
+ podConfigModel , _ := buildPodConfig (ws , wsk )
94
+
92
95
workspaceModel := Workspace {
93
96
Name : ws .Name ,
94
97
Namespace : ws .Namespace ,
@@ -113,8 +116,8 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
113
116
Data : dataVolumes ,
114
117
},
115
118
Options : PodTemplateOptions {
116
- ImageConfig : buildImageConfig ( ws , wsk ) ,
117
- PodConfig : buildPodConfig ( ws , wsk ) ,
119
+ ImageConfig : imageConfigModel ,
120
+ PodConfig : podConfigModel ,
118
121
},
119
122
},
120
123
Activity : Activity {
@@ -124,6 +127,7 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
124
127
// https://github.com/kubeflow/notebooks/issues/38
125
128
LastProbe : nil ,
126
129
},
130
+ Services : buildServices (ws , imageConfigValue ),
127
131
}
128
132
return workspaceModel
129
133
}
@@ -151,7 +155,7 @@ func buildHomeVolume(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.W
151
155
}
152
156
}
153
157
154
- func buildImageConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ImageConfig {
158
+ func buildImageConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ( ImageConfig , * kubefloworgv1beta1. ImageConfigValue ) {
155
159
// create a map of image configs from the WorkspaceKind for easy lookup by ID
156
160
// NOTE: we can only build this map if the WorkspaceKind exists, otherwise it will be empty
157
161
imageConfigMap := make (map [string ]kubefloworgv1beta1.ImageConfigValue )
@@ -163,13 +167,15 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
163
167
}
164
168
165
169
// get the current image config
170
+ var currentImageConfigValue * kubefloworgv1beta1.ImageConfigValue
166
171
currentImageConfig := OptionInfo {
167
172
Id : ws .Spec .PodTemplate .Options .ImageConfig ,
168
173
DisplayName : UnknownImageConfig ,
169
174
Description : UnknownImageConfig ,
170
175
Labels : nil ,
171
176
}
172
177
if cfg , ok := imageConfigMap [currentImageConfig .Id ]; ok {
178
+ currentImageConfigValue = & cfg
173
179
currentImageConfig .DisplayName = cfg .Spawner .DisplayName
174
180
currentImageConfig .Description = ptr .Deref (cfg .Spawner .Description , "" )
175
181
currentImageConfig .Labels = buildOptionLabels (cfg .Spawner .Labels )
@@ -218,10 +224,10 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
218
224
Current : currentImageConfig ,
219
225
Desired : desiredImageConfig ,
220
226
RedirectChain : redirectChain ,
221
- }
227
+ }, currentImageConfigValue
222
228
}
223
229
224
- func buildPodConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) PodConfig {
230
+ func buildPodConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ( PodConfig , * kubefloworgv1beta1. PodConfigValue ) {
225
231
// create a map of pod configs from the WorkspaceKind for easy lookup by ID
226
232
// NOTE: we can only build this map if the WorkspaceKind exists, otherwise it will be empty
227
233
podConfigMap := make (map [string ]kubefloworgv1beta1.PodConfigValue )
@@ -233,13 +239,15 @@ func buildPodConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.Wo
233
239
}
234
240
235
241
// get the current pod config
242
+ var currentPodConfigValue * kubefloworgv1beta1.PodConfigValue
236
243
currentPodConfig := OptionInfo {
237
244
Id : ws .Spec .PodTemplate .Options .PodConfig ,
238
245
DisplayName : UnknownPodConfig ,
239
246
Description : UnknownPodConfig ,
240
247
Labels : nil ,
241
248
}
242
249
if cfg , ok := podConfigMap [currentPodConfig .Id ]; ok {
250
+ currentPodConfigValue = & cfg
243
251
currentPodConfig .DisplayName = cfg .Spawner .DisplayName
244
252
currentPodConfig .Description = ptr .Deref (cfg .Spawner .Description , "" )
245
253
currentPodConfig .Labels = buildOptionLabels (cfg .Spawner .Labels )
@@ -288,7 +296,7 @@ func buildPodConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.Wo
288
296
Current : currentPodConfig ,
289
297
Desired : desiredPodConfig ,
290
298
RedirectChain : redirectChain ,
291
- }
299
+ }, currentPodConfigValue
292
300
}
293
301
294
302
func buildOptionLabels (labels []kubefloworgv1beta1.OptionSpawnerLabel ) []OptionLabel {
@@ -322,3 +330,23 @@ func buildRedirectMessage(msg *kubefloworgv1beta1.RedirectMessage) *RedirectMess
322
330
Level : messageLevel ,
323
331
}
324
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