@@ -89,6 +89,9 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
8989 }
9090 }
9191
92+ imageConfigModel , imageConfigValue := buildImageConfig (ws , wsk )
93+ podConfigModel , _ := buildPodConfig (ws , wsk )
94+
9295 workspaceModel := Workspace {
9396 Name : ws .Name ,
9497 Namespace : ws .Namespace ,
@@ -113,8 +116,8 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
113116 Data : dataVolumes ,
114117 },
115118 Options : PodTemplateOptions {
116- ImageConfig : buildImageConfig ( ws , wsk ) ,
117- PodConfig : buildPodConfig ( ws , wsk ) ,
119+ ImageConfig : imageConfigModel ,
120+ PodConfig : podConfigModel ,
118121 },
119122 },
120123 Activity : Activity {
@@ -124,6 +127,7 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
124127 // https://github.com/kubeflow/notebooks/issues/38
125128 LastProbe : nil ,
126129 },
130+ Services : buildServices (ws , imageConfigValue ),
127131 }
128132 return workspaceModel
129133}
@@ -151,7 +155,7 @@ func buildHomeVolume(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.W
151155 }
152156}
153157
154- func buildImageConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ImageConfig {
158+ func buildImageConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ( ImageConfig , * kubefloworgv1beta1. ImageConfigValue ) {
155159 // create a map of image configs from the WorkspaceKind for easy lookup by ID
156160 // NOTE: we can only build this map if the WorkspaceKind exists, otherwise it will be empty
157161 imageConfigMap := make (map [string ]kubefloworgv1beta1.ImageConfigValue )
@@ -163,13 +167,15 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
163167 }
164168
165169 // get the current image config
170+ var currentImageConfigValue * kubefloworgv1beta1.ImageConfigValue
166171 currentImageConfig := OptionInfo {
167172 Id : ws .Spec .PodTemplate .Options .ImageConfig ,
168173 DisplayName : UnknownImageConfig ,
169174 Description : UnknownImageConfig ,
170175 Labels : nil ,
171176 }
172177 if cfg , ok := imageConfigMap [currentImageConfig .Id ]; ok {
178+ currentImageConfigValue = & cfg
173179 currentImageConfig .DisplayName = cfg .Spawner .DisplayName
174180 currentImageConfig .Description = ptr .Deref (cfg .Spawner .Description , "" )
175181 currentImageConfig .Labels = buildOptionLabels (cfg .Spawner .Labels )
@@ -218,10 +224,10 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
218224 Current : currentImageConfig ,
219225 Desired : desiredImageConfig ,
220226 RedirectChain : redirectChain ,
221- }
227+ }, currentImageConfigValue
222228}
223229
224- func buildPodConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) PodConfig {
230+ func buildPodConfig (ws * kubefloworgv1beta1.Workspace , wsk * kubefloworgv1beta1.WorkspaceKind ) ( PodConfig , * kubefloworgv1beta1. PodConfigValue ) {
225231 // create a map of pod configs from the WorkspaceKind for easy lookup by ID
226232 // NOTE: we can only build this map if the WorkspaceKind exists, otherwise it will be empty
227233 podConfigMap := make (map [string ]kubefloworgv1beta1.PodConfigValue )
@@ -233,13 +239,15 @@ func buildPodConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.Wo
233239 }
234240
235241 // get the current pod config
242+ var currentPodConfigValue * kubefloworgv1beta1.PodConfigValue
236243 currentPodConfig := OptionInfo {
237244 Id : ws .Spec .PodTemplate .Options .PodConfig ,
238245 DisplayName : UnknownPodConfig ,
239246 Description : UnknownPodConfig ,
240247 Labels : nil ,
241248 }
242249 if cfg , ok := podConfigMap [currentPodConfig .Id ]; ok {
250+ currentPodConfigValue = & cfg
243251 currentPodConfig .DisplayName = cfg .Spawner .DisplayName
244252 currentPodConfig .Description = ptr .Deref (cfg .Spawner .Description , "" )
245253 currentPodConfig .Labels = buildOptionLabels (cfg .Spawner .Labels )
@@ -288,7 +296,7 @@ func buildPodConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.Wo
288296 Current : currentPodConfig ,
289297 Desired : desiredPodConfig ,
290298 RedirectChain : redirectChain ,
291- }
299+ }, currentPodConfigValue
292300}
293301
294302func buildOptionLabels (labels []kubefloworgv1beta1.OptionSpawnerLabel ) []OptionLabel {
@@ -322,3 +330,23 @@ func buildRedirectMessage(msg *kubefloworgv1beta1.RedirectMessage) *RedirectMess
322330 Level : messageLevel ,
323331 }
324332}
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