Skip to content

Commit 5d88a27

Browse files
committed
include ports array in podtemplate for httpProxy setting
- moved protocal from imageconfig.spec.ports to podtemplates.ports - included the podtemplates.ports with defaultdisplayname - add validation webhook for podtemplate.ports - update the sample workspacekind with ports reference - referencing same id for portid in imageconfig and podtemplate.ports Signed-off-by: Harshad Reddy Nalla <hnalla@redhat.com>
1 parent 5d91ee0 commit 5d88a27

File tree

13 files changed

+371
-162
lines changed

13 files changed

+371
-162
lines changed

workspaces/backend/api/suite_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,19 @@ func NewExampleWorkspaceKind(name string) *kubefloworgv1beta1.WorkspaceKind {
245245
VolumeMounts: kubefloworgv1beta1.WorkspaceKindVolumeMounts{
246246
Home: "/home/jovyan",
247247
},
248-
HTTPProxy: &kubefloworgv1beta1.HTTPProxy{
249-
RemovePathPrefix: ptr.To(false),
250-
RequestHeaders: &kubefloworgv1beta1.IstioHeaderOperations{
251-
Set: map[string]string{"X-RStudio-Root-Path": "{{ .PathPrefix }}"},
252-
Add: map[string]string{},
253-
Remove: []string{},
248+
Ports: []kubefloworgv1beta1.WorkspaceKindPort{
249+
{
250+
Id: "jupyterlab",
251+
DefaultDisplayName: "JupyterLab",
252+
Protocol: "HTTP",
253+
HTTPProxy: &kubefloworgv1beta1.HTTPProxy{
254+
RemovePathPrefix: ptr.To(false),
255+
RequestHeaders: &kubefloworgv1beta1.IstioHeaderOperations{
256+
Set: map[string]string{},
257+
Add: map[string]string{},
258+
Remove: []string{},
259+
},
260+
},
254261
},
255262
},
256263
ExtraEnv: []v1.EnvVar{
@@ -317,9 +324,8 @@ func NewExampleWorkspaceKind(name string) *kubefloworgv1beta1.WorkspaceKind {
317324
Ports: []kubefloworgv1beta1.ImagePort{
318325
{
319326
Id: "jupyterlab",
320-
DisplayName: "JupyterLab",
327+
DisplayName: ptr.To("JupyterLab"),
321328
Port: 8888,
322-
Protocol: "HTTP",
323329
},
324330
},
325331
},
@@ -342,9 +348,8 @@ func NewExampleWorkspaceKind(name string) *kubefloworgv1beta1.WorkspaceKind {
342348
Ports: []kubefloworgv1beta1.ImagePort{
343349
{
344350
Id: "jupyterlab",
345-
DisplayName: "JupyterLab",
351+
DisplayName: ptr.To("JupyterLab"),
346352
Port: 8888,
347-
Protocol: "HTTP",
348353
},
349354
},
350355
},

workspaces/backend/api/workspacekinds_handler_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ spec:
299299
- id: "jupyterlab"
300300
displayName: "JupyterLab"
301301
port: 8888
302-
protocol: "HTTP"
303302
podConfig:
304303
spawner:
305304
default: "tiny_cpu"

workspaces/backend/internal/models/workspaces/funcs.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
9191

9292
imageConfigModel, imageConfigValue := buildImageConfig(ws, wsk)
9393
podConfigModel, _ := buildPodConfig(ws, wsk)
94+
var wskPodTemplatePorts []kubefloworgv1beta1.WorkspaceKindPort
95+
if wskExists(wsk) {
96+
wskPodTemplatePorts = wsk.Spec.PodTemplate.Ports
97+
}
9498

9599
workspaceModel := Workspace{
96100
Name: ws.Name,
@@ -128,7 +132,7 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
128132
// https://github.com/kubeflow/notebooks/issues/38
129133
LastProbe: nil,
130134
},
131-
Services: buildServices(ws, imageConfigValue),
135+
Services: buildServices(ws, wskPodTemplatePorts, imageConfigValue),
132136
}
133137
return workspaceModel
134138
}
@@ -332,18 +336,20 @@ func buildRedirectMessage(msg *kubefloworgv1beta1.RedirectMessage) *RedirectMess
332336
}
333337
}
334338

335-
func buildServices(ws *kubefloworgv1beta1.Workspace, imageConfigValue *kubefloworgv1beta1.ImageConfigValue) []Service {
339+
func buildServices(ws *kubefloworgv1beta1.Workspace, wskPodTemplatePorts []kubefloworgv1beta1.WorkspaceKindPort, imageConfigValue *kubefloworgv1beta1.ImageConfigValue) []Service {
336340
if imageConfigValue == nil {
337341
return nil
338342
}
339343

340344
services := make([]Service, len(imageConfigValue.Spec.Ports))
341345
for i := range imageConfigValue.Spec.Ports {
342346
port := imageConfigValue.Spec.Ports[i]
343-
switch port.Protocol { //nolint:gocritic
347+
portocol := wskPodTemplatePorts[i].Protocol
348+
// golint complains about the single case in switch statement
349+
switch portocol { //nolint:gocritic
344350
case kubefloworgv1beta1.ImagePortProtocolHTTP:
345351
services[i].HttpService = &HttpService{
346-
DisplayName: port.DisplayName,
352+
DisplayName: ptr.Deref(port.DisplayName, wskPodTemplatePorts[i].DefaultDisplayName),
347353
HttpPath: fmt.Sprintf("/workspace/%s/%s/%s/", ws.Namespace, ws.Name, port.Id),
348354
}
349355
}

workspaces/controller/api/v1beta1/workspacekind_types.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ import (
2929
===============================================================================
3030
*/
3131

32+
// PortId the id of the port
33+
//
34+
// +kubebuilder:validation:MinLength:=1
35+
// +kubebuilder:validation:MaxLength:=32
36+
// +kubebuilder:validation:Pattern:=^[a-z0-9][a-z0-9_-]*[a-z0-9]$
37+
type PortId string
38+
3239
// WorkspaceKindSpec defines the desired state of WorkspaceKind
3340
type WorkspaceKindSpec struct {
3441

@@ -115,9 +122,11 @@ type WorkspaceKindPodTemplate struct {
115122
// volume mount paths
116123
VolumeMounts WorkspaceKindVolumeMounts `json:"volumeMounts"`
117124

118-
// http proxy configs (MUTABLE)
119-
// +kubebuilder:validation:Optional
120-
HTTPProxy *HTTPProxy `json:"httpProxy,omitempty"`
125+
// ports that the container listens on
126+
// +kubebuilder:validation:MinItems:=1
127+
// +listType:="map"
128+
// +listMapKey:="id"
129+
Ports []WorkspaceKindPort `json:"ports,omitempty"`
121130

122131
// environment variables for Workspace Pods (MUTABLE)
123132
// - the following go template functions are available:
@@ -151,6 +160,27 @@ type WorkspaceKindPodTemplate struct {
151160
Options WorkspaceKindPodOptions `json:"options"`
152161
}
153162

163+
type WorkspaceKindPort struct {
164+
// the id of the port
165+
// - identifier for the port in `imageconfig` ports.[].id
166+
// +kubebuilder:example="jupyterlab"
167+
Id PortId `json:"id"`
168+
169+
// the protocol of the port
170+
// +kubebuilder:example:="HTTP"
171+
Protocol ImagePortProtocol `json:"protocol"`
172+
173+
// the display name of the port
174+
// +kubebuilder:validation:MinLength:=2
175+
// +kubebuilder:validation:MaxLength:=64
176+
// +kubebuilder:example:="JupyterLab"
177+
DefaultDisplayName string `json:"displayName"`
178+
179+
// the http proxy config for the port (MUTABLE)
180+
// +kubebuilder:validation:Optional
181+
HTTPProxy *HTTPProxy `json:"httpProxy,omitempty"`
182+
}
183+
154184
type WorkspaceKindPodMetadata struct {
155185
// labels to be applied to the Pod resource
156186
// +kubebuilder:validation:Optional
@@ -339,11 +369,8 @@ type ImageConfigSpec struct {
339369
type ImagePort struct {
340370
// the id of the port
341371
// - this is NOT used as the Container or Service port name, but as part of the HTTP path
342-
// +kubebuilder:validation:MinLength:=1
343-
// +kubebuilder:validation:MaxLength:=32
344-
// +kubebuilder:validation:Pattern:=^[a-z0-9][a-z0-9_-]*[a-z0-9]$
345372
// +kubebuilder:example="jupyterlab"
346-
Id string `json:"id"`
373+
Id PortId `json:"id"`
347374

348375
// the port number
349376
// +kubebuilder:validation:Minimum:=1
@@ -354,12 +381,8 @@ type ImagePort struct {
354381
// the display name of the port
355382
// +kubebuilder:validation:MinLength:=2
356383
// +kubebuilder:validation:MaxLength:=64
357-
// +kubebuilder:example:="JupyterLab"
358-
DisplayName string `json:"displayName"`
359-
360-
// the protocol of the port
361-
// +kubebuilder:example:="HTTP"
362-
Protocol ImagePortProtocol `json:"protocol"`
384+
// +kubebuilder:validation:Optional
385+
DisplayName *string `json:"displayName,omitempty"`
363386
}
364387

365388
// +kubebuilder:validation:Enum:={"HTTP"}

workspaces/controller/api/v1beta1/zz_generated.deepcopy.go

Lines changed: 34 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)