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 3 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
37 changes: 37 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,46 @@ 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 {
//nolint:prealloc
var services []Service

if !wskExists(wsk) {
return services
}

// Get the image configuration from the WorkspaceKind's PodTemplate options.
imageConfig := wsk.Spec.PodTemplate.Options.ImageConfig

for _, val := range imageConfig.Values {
if len(val.Spec.Ports) == 0 {
continue
}
firstPort := val.Spec.Ports[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// ports that the container listens on
	//   - if multiple ports are defined, the user will see multiple "Connect" buttons
	//     in a dropdown menu on the Workspace overview page
	// +kubebuilder:validation:MinItems:=1
	// +listType:="map"
	// +listMapKey:="id"
	Ports []ImagePort `json:"ports"`	

Shall we support here multiple ports here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we deliberatelly are going to always use the first port here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thesuperzapper maybe you can chime in on this one. ^

I'm good to support just one for now and do a FUP PR on it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ederign I think it's a mistake (mine). Will fix it soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries @yehudit1987 ! Thank you for the PR

portStr := fmt.Sprintf("%d", firstPort.Port)
displayName := firstPort.DisplayName
if displayName == "" {
displayName = val.Id
}
basePath := "/workspace"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of my curiosity, where this /workspace path comes from?

notebookPath := path.Join(basePath, ws.Namespace, ws.Name, portStr)
service := Service{
HttpService: &HttpService{
DisplayName: displayName,
HttpPath: notebookPath,
},
}
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