Skip to content

Commit dc2c179

Browse files
author
Yehudit Kerido
committed
feat(ws): Notebooks 2.0 // Frontend // Fetch workspaces
Signed-off-by: Yehudit Kerido <yehudit.kerido@nokia.com>
1 parent 309a134 commit dc2c179

File tree

11 files changed

+108
-186
lines changed

11 files changed

+108
-186
lines changed

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
120120
ImageConfig: imageConfigModel,
121121
PodConfig: podConfigModel,
122122
},
123-
EndPoints: buildEndpointsList(ws, wsk),
124123
},
125124
Activity: Activity{
126125
LastActivity: ws.Status.Activity.LastActivity,
@@ -134,37 +133,6 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
134133
return workspaceModel
135134
}
136135

137-
func buildEndpointsList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []EndPoints {
138-
var endpoints []EndPoints
139-
140-
// Return an empty list if wsk is nil.
141-
if wsk == nil {
142-
return endpoints
143-
}
144-
145-
// Get the image configuration from the WorkspaceKind's PodTemplate options.
146-
imageConfig := wsk.Spec.PodTemplate.Options.ImageConfig
147-
148-
for _, val := range imageConfig.Values {
149-
if len(val.Spec.Ports) == 0 {
150-
continue
151-
}
152-
firstPort := val.Spec.Ports[0]
153-
portStr := fmt.Sprintf("%d", firstPort.Port)
154-
displayName := firstPort.DisplayName
155-
if displayName == "" {
156-
displayName = val.Id
157-
}
158-
ep := EndPoints{
159-
DisplayName: displayName,
160-
Port: portStr,
161-
}
162-
endpoints = append(endpoints, ep)
163-
}
164-
165-
return endpoints
166-
}
167-
168136
func wskExists(wsk *kubefloworgv1beta1.WorkspaceKind) bool {
169137
return wsk != nil && wsk.UID != ""
170138
}

workspaces/backend/internal/models/workspaces/types.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ type PodTemplate struct {
5959
PodMetadata PodMetadata `json:"podMetadata"`
6060
Volumes PodVolumes `json:"volumes"`
6161
Options PodTemplateOptions `json:"options"`
62-
EndPoints []EndPoints `json:"end_points"`
63-
}
64-
65-
type EndPoints struct {
66-
DisplayName string `json:"display_name"`
67-
Port string `json:"port"`
6862
}
6963

7064
type PodMetadata struct {
Binary file not shown.

workspaces/frontend/src/__tests__/cypress/cypress/tests/e2e/Workspaces.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const validateWorkspaceRow = (workspace: Workspace, index: number) => {
1616

1717
cy.findByTestId(`workspace-row-${index}`)
1818
.find('[data-testid="pod-config"]')
19-
.should('have.text', workspace.pod_template.options.pod_config.current.display_name);
19+
.should('have.text', workspace.podTemplate.options.podConfig.current.displayName);
2020
};
2121

2222
// Test suite for workspace-related tests

workspaces/frontend/src/__tests__/cypress/cypress/tests/mocked/workspace.mock.ts

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,40 @@ const generateMockWorkspace = (
1313
): {
1414
name: string;
1515
namespace: string;
16-
workspace_kind: { name: string };
17-
defer_updates: boolean;
16+
workspaceKind: { name: string };
17+
deferUpdates: boolean;
1818
paused: boolean;
19-
paused_time: number;
19+
pausedTime: number;
20+
pendingRestart: boolean;
2021
state: WorkspaceState;
21-
state_message: string;
22-
pod_template: {
23-
pod_metadata: { labels: object; annotations: object };
22+
stateMessage: string;
23+
podTemplate: {
24+
podMetadata: { labels: object; annotations: object };
2425
volumes: {
25-
home: { pvc_name: string; mount_path: string; readOnly: boolean };
26-
data: { pvc_name: string; mount_path: string; readOnly: boolean }[];
26+
home: { pvcName: string; mountPath: string; readOnly: boolean };
27+
data: { pvcName: string; mountPath: string; readOnly: boolean }[];
2728
};
2829
options: {
29-
image_config: {
30+
imageConfig: {
3031
current: {
3132
id: string;
32-
display_name: string;
33+
displayName: string;
3334
description: string;
3435
labels: { key: string; value: string }[];
3536
};
3637
};
37-
pod_config: {
38+
podConfig: {
3839
current: {
3940
id: string;
40-
display_name: string;
41+
displayName: string;
4142
description: string;
4243
labels: ({ key: string; value: string } | { key: string; value: string })[];
4344
};
4445
};
4546
};
46-
image_config: { current: string; desired: string; redirect_chain: never[] };
47-
pod_config: { current: string; desired: string; redirect_chain: never[] };
48-
end_points: { display_name: string; port: string }[];
4947
};
5048
activity: { last_activity: number; last_update: number };
49+
services: { httpService: { displayName: string; httpPath: string } }[];
5150
} => {
5251
const currentTime = Date.now();
5352
const lastActivityTime = currentTime - Math.floor(Math.random() * 1000000);
@@ -56,55 +55,50 @@ const generateMockWorkspace = (
5655
return {
5756
name,
5857
namespace,
59-
workspace_kind: { name: 'jupyterlab' },
60-
defer_updates: paused,
58+
workspaceKind: { name: 'jupyterlab' },
59+
deferUpdates: paused,
6160
paused,
62-
paused_time: paused ? currentTime - Math.floor(Math.random() * 1000000) : 0,
61+
pausedTime: paused ? currentTime - Math.floor(Math.random() * 1000000) : 0,
62+
pendingRestart: false,
6363
state,
64-
state_message:
64+
stateMessage:
6565
state === WorkspaceState.Running
6666
? 'Workspace is running smoothly.'
6767
: state === WorkspaceState.Paused
6868
? 'Workspace is paused.'
6969
: 'Workspace is operational.',
70-
pod_template: {
71-
end_points: [
72-
{
73-
display_name: 'Jupyter-lab',
74-
port: '8888',
75-
},
76-
],
77-
pod_metadata: {
70+
podTemplate: {
71+
podMetadata: {
7872
labels: {},
7973
annotations: {},
8074
},
8175
volumes: {
8276
home: {
83-
pvc_name: `${pvcName}-home`,
84-
mount_path: '/home/jovyan',
77+
pvcName: `${pvcName}-home`,
78+
mountPath: '/home/jovyan',
8579
readOnly: false,
8680
},
8781
data: [
8882
{
89-
pvc_name: pvcName,
90-
mount_path: '/data/my-data',
83+
pvcName,
84+
mountPath: '/data/my-data',
9185
readOnly: paused,
9286
},
9387
],
9488
},
9589
options: {
96-
image_config: {
90+
imageConfig: {
9791
current: {
9892
id: imageConfigId,
99-
display_name: imageConfigDisplayName,
93+
displayName: imageConfigDisplayName,
10094
description: 'JupyterLab environment',
10195
labels: [{ key: 'python_version', value: '3.11' }],
10296
},
10397
},
104-
pod_config: {
98+
podConfig: {
10599
current: {
106100
id: podConfigId,
107-
display_name: podConfigDisplayName,
101+
displayName: podConfigDisplayName,
108102
description: 'Pod configuration with resource limits',
109103
labels: [
110104
{ key: 'cpu', value: '100m' },
@@ -113,21 +107,19 @@ const generateMockWorkspace = (
113107
},
114108
},
115109
},
116-
image_config: {
117-
current: imageConfigId,
118-
desired: '',
119-
redirect_chain: [],
120-
},
121-
pod_config: {
122-
current: podConfigId,
123-
desired: podConfigId,
124-
redirect_chain: [],
125-
},
126110
},
127111
activity: {
128112
last_activity: lastActivityTime,
129113
last_update: lastUpdateTime,
130114
},
115+
services: [
116+
{
117+
httpService: {
118+
displayName: 'Jupyter-lab',
119+
httpPath: `/workspace/${namespace}/${name}/Jupyter-lab/`,
120+
},
121+
},
122+
],
131123
};
132124
};
133125

workspaces/frontend/src/app/actions/WorkspaceKindsActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function buildWorkspaceRedirectStatus(
3636
const workspaceRedirectStatus: WorkspaceRedirectStatus = {};
3737
for (const workspaceKind of workspaceKinds) {
3838
// Loop through the `values` array inside `imageConfig`
39-
const redirect = workspaceKind.pod_template.options.image_config.values.find(
39+
const redirect = workspaceKind.podTemplate.options.imageConfig.values.find(
4040
(value) => value.redirect,
4141
)?.redirect;
4242
// If redirect exists, extract the necessary properties

workspaces/frontend/src/app/pages/Workspaces/Details/WorkspaceDetailsActivity.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type WorkspaceDetailsActivityProps = {
1616
export const WorkspaceDetailsActivity: React.FunctionComponent<WorkspaceDetailsActivityProps> = ({
1717
workspace,
1818
}) => {
19-
const { activity, pauseTime, pendingRestart } = workspace.status;
19+
const { activity, pausedTime: pauseTime, pendingRestart } = workspace;
2020

2121
return (
2222
<DescriptionList isHorizontal>

workspaces/frontend/src/app/pages/Workspaces/Details/WorkspaceDetailsOverview.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,25 @@ export const WorkspaceDetailsOverview: React.FunctionComponent<WorkspaceDetailsO
2323
<Divider />
2424
<DescriptionListGroup>
2525
<DescriptionListTerm>Kind</DescriptionListTerm>
26-
<DescriptionListDescription>{workspace.kind}</DescriptionListDescription>
26+
<DescriptionListDescription>{workspace.workspaceKind.name}</DescriptionListDescription>
2727
</DescriptionListGroup>
2828
<Divider />
2929
<DescriptionListGroup>
3030
<DescriptionListTerm>Labels</DescriptionListTerm>
3131
<DescriptionListDescription>
32-
{workspace.podTemplate.podMetadata.labels.join(', ')}
32+
{workspace.podTemplate.options.podConfig.current.labels.length > 0
33+
? workspace.podTemplate.options.podConfig.current.labels
34+
.map((label) => `${label.key}=${label.value}`)
35+
.join(', ')
36+
: 'No labels available'}
3337
</DescriptionListDescription>
3438
</DescriptionListGroup>
3539
<Divider />
3640
<DescriptionListGroup>
3741
<DescriptionListTerm>Pod config</DescriptionListTerm>
38-
<DescriptionListDescription>{workspace.options.podConfig}</DescriptionListDescription>
42+
<DescriptionListDescription>
43+
{JSON.stringify(workspace.podTemplate.options.podConfig, null, 2)}
44+
</DescriptionListDescription>
3945
</DescriptionListGroup>
4046
<Divider />
4147
</DescriptionList>

workspaces/frontend/src/app/pages/Workspaces/WorkspaceConnectAction.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ export const WorkspaceConnectAction: React.FunctionComponent<WorkspaceConnectAct
3333
};
3434

3535
const onClickConnect = () => {
36-
openEndpoint(workspace.pod_template.end_points[0].port);
36+
window.open(workspace.services[0].httpService.httpPath, '_blank');
3737
};
3838

39-
const openEndpoint = (port: string) => {
40-
window.open(`workspace/${workspace.namespace}/${workspace.name}/${port}`, '_blank');
39+
const openEndpoint = (value: string) => {
40+
window.open(value, '_blank');
4141
};
4242

4343
return (
@@ -67,9 +67,12 @@ export const WorkspaceConnectAction: React.FunctionComponent<WorkspaceConnectAct
6767
shouldFocusToggleOnSelect
6868
>
6969
<DropdownList>
70-
{workspace.pod_template.end_points.map((endpoint) => (
71-
<DropdownItem value={endpoint.port} key={`${workspace.name}-${endpoint.port}`}>
72-
{endpoint.display_name}
70+
{workspace.services.map((service) => (
71+
<DropdownItem
72+
value={service.httpService.httpPath}
73+
key={`${workspace.name}-${service.httpService.displayName}`}
74+
>
75+
{service.httpService.displayName}
7376
</DropdownItem>
7477
))}
7578
</DropdownList>

0 commit comments

Comments
 (0)