Skip to content

Commit 9532f2f

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 <[email protected]>
1 parent 5d91ee0 commit 9532f2f

File tree

11 files changed

+387
-152
lines changed

11 files changed

+387
-152
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/internal/models/workspaces/funcs.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,9 @@ func buildServices(ws *kubefloworgv1beta1.Workspace, imageConfigValue *kubeflowo
340340
services := make([]Service, len(imageConfigValue.Spec.Ports))
341341
for i := range imageConfigValue.Spec.Ports {
342342
port := imageConfigValue.Spec.Ports[i]
343-
switch port.Protocol { //nolint:gocritic
344-
case kubefloworgv1beta1.ImagePortProtocolHTTP:
345-
services[i].HttpService = &HttpService{
346-
DisplayName: port.DisplayName,
347-
HttpPath: fmt.Sprintf("/workspace/%s/%s/%s/", ws.Namespace, ws.Name, port.Id),
348-
}
343+
services[i].HttpService = &HttpService{
344+
DisplayName: *port.DisplayName,
345+
HttpPath: fmt.Sprintf("/workspace/%s/%s/%s/", ws.Namespace, ws.Name, port.Id),
349346
}
350347
}
351348

workspaces/controller/api/v1beta1/workspacekind_types.go

Lines changed: 35 additions & 12 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)
125+
// ports that the container listens on
119126
// +kubebuilder:validation:Optional
120-
HTTPProxy *HTTPProxy `json:"httpProxy,omitempty"`
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.

workspaces/controller/config/crd/bases/kubeflow.org_workspacekinds.yaml

Lines changed: 80 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,51 +2275,6 @@ spec:
22752275
x-kubernetes-list-map-keys:
22762276
- name
22772277
x-kubernetes-list-type: map
2278-
httpProxy:
2279-
description: http proxy configs (MUTABLE)
2280-
properties:
2281-
removePathPrefix:
2282-
default: false
2283-
description: |-
2284-
if the path prefix is stripped from incoming HTTP requests
2285-
- if true, the '/workspace/{profile_name}/{workspace_name}/' path prefix
2286-
is stripped from incoming requests, the application sees the request
2287-
as if it was made to '/...'
2288-
- this only works if the application serves RELATIVE URLs for its assets
2289-
type: boolean
2290-
requestHeaders:
2291-
description: |-
2292-
header manipulation rules for incoming HTTP requests
2293-
- sets the `spec.http[].headers.request` of the Istio VirtualService
2294-
https://istio.io/latest/docs/reference/config/networking/virtual-service/#Headers-HeaderOperations
2295-
- the following string templates are available:
2296-
- `.PathPrefix`: the path prefix of the Workspace (e.g. '/workspace/{profile_name}/{workspace_name}/')
2297-
properties:
2298-
add:
2299-
additionalProperties:
2300-
type: string
2301-
description: append the given values to the headers specified
2302-
by keys (will create a comma-separated list of values)
2303-
example:
2304-
My-Header: value-to-append
2305-
type: object
2306-
remove:
2307-
description: remove the specified headers
2308-
example:
2309-
- Header-To-Remove
2310-
items:
2311-
type: string
2312-
type: array
2313-
set:
2314-
additionalProperties:
2315-
type: string
2316-
description: overwrite the headers specified by key with
2317-
the given values
2318-
example:
2319-
X-RStudio-Root-Path: '{{ .PathPrefix }}'
2320-
type: object
2321-
type: object
2322-
type: object
23232278
options:
23242279
description: options are the user-selectable fields, they determine
23252280
the PodSpec of the Workspace
@@ -2457,7 +2412,6 @@ spec:
24572412
properties:
24582413
displayName:
24592414
description: the display name of the port
2460-
example: JupyterLab
24612415
maxLength: 64
24622416
minLength: 2
24632417
type: string
@@ -2477,17 +2431,9 @@ spec:
24772431
maximum: 65535
24782432
minimum: 1
24792433
type: integer
2480-
protocol:
2481-
description: the protocol of the port
2482-
enum:
2483-
- HTTP
2484-
example: HTTP
2485-
type: string
24862434
required:
2487-
- displayName
24882435
- id
24892436
- port
2490-
- protocol
24912437
type: object
24922438
minItems: 1
24932439
type: array
@@ -3729,6 +3675,86 @@ spec:
37293675
description: labels to be applied to the Pod resource
37303676
type: object
37313677
type: object
3678+
ports:
3679+
description: ports that the container listens on
3680+
items:
3681+
properties:
3682+
displayName:
3683+
description: the display name of the port
3684+
example: JupyterLab
3685+
maxLength: 64
3686+
minLength: 2
3687+
type: string
3688+
httpProxy:
3689+
description: the http proxy config for the port (MUTABLE)
3690+
properties:
3691+
removePathPrefix:
3692+
default: false
3693+
description: |-
3694+
if the path prefix is stripped from incoming HTTP requests
3695+
- if true, the '/workspace/{profile_name}/{workspace_name}/' path prefix
3696+
is stripped from incoming requests, the application sees the request
3697+
as if it was made to '/...'
3698+
- this only works if the application serves RELATIVE URLs for its assets
3699+
type: boolean
3700+
requestHeaders:
3701+
description: |-
3702+
header manipulation rules for incoming HTTP requests
3703+
- sets the `spec.http[].headers.request` of the Istio VirtualService
3704+
https://istio.io/latest/docs/reference/config/networking/virtual-service/#Headers-HeaderOperations
3705+
- the following string templates are available:
3706+
- `.PathPrefix`: the path prefix of the Workspace (e.g. '/workspace/{profile_name}/{workspace_name}/')
3707+
properties:
3708+
add:
3709+
additionalProperties:
3710+
type: string
3711+
description: append the given values to the headers
3712+
specified by keys (will create a comma-separated
3713+
list of values)
3714+
example:
3715+
My-Header: value-to-append
3716+
type: object
3717+
remove:
3718+
description: remove the specified headers
3719+
example:
3720+
- Header-To-Remove
3721+
items:
3722+
type: string
3723+
type: array
3724+
set:
3725+
additionalProperties:
3726+
type: string
3727+
description: overwrite the headers specified by
3728+
key with the given values
3729+
example:
3730+
X-RStudio-Root-Path: '{{ .PathPrefix }}'
3731+
type: object
3732+
type: object
3733+
type: object
3734+
id:
3735+
description: |-
3736+
the id of the port
3737+
- identifier for the port in `imageconfig` ports.[].id
3738+
example: jupyterlab
3739+
maxLength: 32
3740+
minLength: 1
3741+
pattern: ^[a-z0-9][a-z0-9_-]*[a-z0-9]$
3742+
type: string
3743+
protocol:
3744+
description: the protocol of the port
3745+
enum:
3746+
- HTTP
3747+
example: HTTP
3748+
type: string
3749+
required:
3750+
- displayName
3751+
- id
3752+
- protocol
3753+
type: object
3754+
type: array
3755+
x-kubernetes-list-map-keys:
3756+
- id
3757+
x-kubernetes-list-type: map
37323758
probes:
37333759
description: standard probes to determine Container health (MUTABLE)
37343760
properties:

0 commit comments

Comments
 (0)