Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ws): add http service paths to WS get on backend #213

Open
wants to merge 5 commits into
base: notebooks-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions workspaces/backend/internal/models/workspaces/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package workspaces

import (
"fmt"
"path"

kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -124,10 +125,51 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
// https://github.com/kubeflow/notebooks/issues/38
LastProbe: nil,
},
Services: buildServicesList(ws, wsk),
}
return workspaceModel
}

func buildServicesList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []Service {
if !wskExists(wsk) {
return nil
}

imageConfig := wsk.Spec.PodTemplate.Options.ImageConfig
basePath := "/workspace"
namespacePath := path.Join(basePath, ws.Namespace, ws.Name)

services := make([]Service, 0, len(imageConfig.Values))

for _, val := range imageConfig.Values {
services = append(services, extractServices(&val, namespacePath)...)
}
return services
}

func extractServices(val *kubefloworgv1beta1.ImageConfigValue, namespacePath string) []Service {
if len(val.Spec.Ports) == 0 {
return []Service{}
}

services := make([]Service, 0, len(val.Spec.Ports))

for _, port := range val.Spec.Ports {
displayName := port.DisplayName
if displayName == "" {
displayName = val.Id
}
service := Service{
HttpService: &HttpService{
DisplayName: displayName,
HttpPath: path.Join(namespacePath, port.Id),
},
}
services = append(services, service)
}
return services
}

func wskExists(wsk *kubefloworgv1beta1.WorkspaceKind) bool {
return wsk != nil && wsk.UID != ""
}
Expand Down
10 changes: 10 additions & 0 deletions workspaces/backend/internal/models/workspaces/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Workspace struct {
StateMessage string `json:"stateMessage"`
PodTemplate PodTemplate `json:"podTemplate"`
Activity Activity `json:"activity"`
Services []Service `json:"services,omitempty"`
}

type WorkspaceState string
Expand Down Expand Up @@ -86,6 +87,15 @@ type ImageConfig struct {
RedirectChain []RedirectStep `json:"redirectChain,omitempty"`
}

type Service struct {
HttpService *HttpService `json:"httpService,omitempty"`
}

type HttpService struct {
DisplayName string `json:"displayName"`
HttpPath string `json:"httpPath"`
}

type PodConfig struct {
Current OptionInfo `json:"current"`
Desired *OptionInfo `json:"desired,omitempty"`
Expand Down