-
Notifications
You must be signed in to change notification settings - Fork 63
feat(ws): add spec.podTemplate.ports[] to WorkspaceKind #507
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
base: notebooks-v2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,10 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef | |
|
||
imageConfigModel, imageConfigValue := buildImageConfig(ws, wsk) | ||
podConfigModel, _ := buildPodConfig(ws, wsk) | ||
var wskPodTemplatePorts []kubefloworgv1beta1.WorkspaceKindPort | ||
if wskExists(wsk) { | ||
wskPodTemplatePorts = wsk.Spec.PodTemplate.Ports | ||
} | ||
|
||
workspaceModel := Workspace{ | ||
Name: ws.Name, | ||
|
@@ -128,7 +132,7 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef | |
// https://github.com/kubeflow/notebooks/issues/38 | ||
LastProbe: nil, | ||
}, | ||
Services: buildServices(ws, imageConfigValue), | ||
Services: buildServices(ws, wskPodTemplatePorts, imageConfigValue), | ||
} | ||
return workspaceModel | ||
} | ||
|
@@ -332,18 +336,20 @@ func buildRedirectMessage(msg *kubefloworgv1beta1.RedirectMessage) *RedirectMess | |
} | ||
} | ||
|
||
func buildServices(ws *kubefloworgv1beta1.Workspace, imageConfigValue *kubefloworgv1beta1.ImageConfigValue) []Service { | ||
func buildServices(ws *kubefloworgv1beta1.Workspace, wskPodTemplatePorts []kubefloworgv1beta1.WorkspaceKindPort, imageConfigValue *kubefloworgv1beta1.ImageConfigValue) []Service { | ||
if imageConfigValue == nil { | ||
return nil | ||
} | ||
|
||
services := make([]Service, len(imageConfigValue.Spec.Ports)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to first build a map from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the changes accordingly |
||
for i := range imageConfigValue.Spec.Ports { | ||
port := imageConfigValue.Spec.Ports[i] | ||
switch port.Protocol { //nolint:gocritic | ||
thesuperzapper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
protocol := wskPodTemplatePorts[i].Protocol | ||
// golint complains about the single case in switch statement | ||
switch protocol { //nolint:gocritic | ||
case kubefloworgv1beta1.ImagePortProtocolHTTP: | ||
services[i].HttpService = &HttpService{ | ||
DisplayName: port.DisplayName, | ||
DisplayName: ptr.Deref(port.DisplayName, wskPodTemplatePorts[i].DefaultDisplayName), | ||
HttpPath: fmt.Sprintf("/workspace/%s/%s/%s/", ws.Namespace, ws.Name, port.Id), | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,6 +29,13 @@ import ( | |||||||||||||
=============================================================================== | ||||||||||||||
*/ | ||||||||||||||
|
||||||||||||||
// PortId the id of the port | ||||||||||||||
// | ||||||||||||||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
// +kubebuilder:validation:MinLength:=1 | ||||||||||||||
// +kubebuilder:validation:MaxLength:=32 | ||||||||||||||
// +kubebuilder:validation:Pattern:=^[a-z0-9][a-z0-9_-]*[a-z0-9]$ | ||||||||||||||
type PortId string | ||||||||||||||
|
||||||||||||||
// WorkspaceKindSpec defines the desired state of WorkspaceKind | ||||||||||||||
type WorkspaceKindSpec struct { | ||||||||||||||
|
||||||||||||||
|
@@ -115,9 +122,11 @@ type WorkspaceKindPodTemplate struct { | |||||||||||||
// volume mount paths | ||||||||||||||
VolumeMounts WorkspaceKindVolumeMounts `json:"volumeMounts"` | ||||||||||||||
|
||||||||||||||
// http proxy configs (MUTABLE) | ||||||||||||||
// +kubebuilder:validation:Optional | ||||||||||||||
HTTPProxy *HTTPProxy `json:"httpProxy,omitempty"` | ||||||||||||||
// ports that the container listens on | ||||||||||||||
thesuperzapper marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very important to document for users as it is used in
Suggested change
|
||||||||||||||
// +kubebuilder:validation:MinItems:=1 | ||||||||||||||
// +listType:="map" | ||||||||||||||
// +listMapKey:="id" | ||||||||||||||
Ports []WorkspaceKindPort `json:"ports"` | ||||||||||||||
|
||||||||||||||
// environment variables for Workspace Pods (MUTABLE) | ||||||||||||||
// - the following go template functions are available: | ||||||||||||||
|
@@ -151,6 +160,27 @@ type WorkspaceKindPodTemplate struct { | |||||||||||||
Options WorkspaceKindPodOptions `json:"options"` | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
type WorkspaceKindPort struct { | ||||||||||||||
// the id of the port | ||||||||||||||
// - identifier for the port in `imageconfig` ports.[].id | ||||||||||||||
// +kubebuilder:example="jupyterlab" | ||||||||||||||
Id PortId `json:"id"` | ||||||||||||||
|
||||||||||||||
// the protocol of the port | ||||||||||||||
// +kubebuilder:example:="HTTP" | ||||||||||||||
Protocol ImagePortProtocol `json:"protocol"` | ||||||||||||||
|
||||||||||||||
// the display name of the port | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
// +kubebuilder:validation:MinLength:=2 | ||||||||||||||
// +kubebuilder:validation:MaxLength:=64 | ||||||||||||||
// +kubebuilder:example:="JupyterLab" | ||||||||||||||
DefaultDisplayName string `json:"displayName"` | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's include "default" so it's clear that this is override-able per port:
Suggested change
|
||||||||||||||
|
||||||||||||||
thesuperzapper marked this conversation as resolved.
Show resolved
Hide resolved
thesuperzapper marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
// the http proxy config for the port (MUTABLE) | ||||||||||||||
// +kubebuilder:validation:Optional | ||||||||||||||
HTTPProxy *HTTPProxy `json:"httpProxy,omitempty"` | ||||||||||||||
thesuperzapper marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
type WorkspaceKindPodMetadata struct { | ||||||||||||||
// labels to be applied to the Pod resource | ||||||||||||||
// +kubebuilder:validation:Optional | ||||||||||||||
|
@@ -339,11 +369,8 @@ type ImageConfigSpec struct { | |||||||||||||
type ImagePort struct { | ||||||||||||||
// the id of the port | ||||||||||||||
// - this is NOT used as the Container or Service port name, but as part of the HTTP path | ||||||||||||||
// +kubebuilder:validation:MinLength:=1 | ||||||||||||||
// +kubebuilder:validation:MaxLength:=32 | ||||||||||||||
// +kubebuilder:validation:Pattern:=^[a-z0-9][a-z0-9_-]*[a-z0-9]$ | ||||||||||||||
// +kubebuilder:example="jupyterlab" | ||||||||||||||
Id string `json:"id"` | ||||||||||||||
Id PortId `json:"id"` | ||||||||||||||
|
||||||||||||||
// the port number | ||||||||||||||
// +kubebuilder:validation:Minimum:=1 | ||||||||||||||
|
@@ -354,12 +381,8 @@ type ImagePort struct { | |||||||||||||
// the display name of the port | ||||||||||||||
// +kubebuilder:validation:MinLength:=2 | ||||||||||||||
// +kubebuilder:validation:MaxLength:=64 | ||||||||||||||
// +kubebuilder:example:="JupyterLab" | ||||||||||||||
DisplayName string `json:"displayName"` | ||||||||||||||
|
||||||||||||||
// the protocol of the port | ||||||||||||||
// +kubebuilder:example:="HTTP" | ||||||||||||||
Protocol ImagePortProtocol `json:"protocol"` | ||||||||||||||
// +kubebuilder:validation:Optional | ||||||||||||||
DisplayName *string `json:"displayName,omitempty"` | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// +kubebuilder:validation:Enum:={"HTTP"} | ||||||||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should b a map from
portId
toport config
so we can look it up by that in thebuildServices
section.Same as comment https://github.com/kubeflow/notebooks/pull/507/files#r2342214467 from the last review.