Skip to content

Commit e89096b

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 88f9a64 commit e89096b

File tree

6 files changed

+238
-158
lines changed

6 files changed

+238
-158
lines changed
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.pod_config.current);
19+
.should('have.text', workspace.pod_template.options.pod_config.current.display_name);
2020
};
2121

2222
// Test suite for workspace-related tests

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

Lines changed: 90 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,57 @@ const generateMockWorkspace = (
66
namespace: string,
77
state: WorkspaceState,
88
paused: boolean,
9-
imageConfig: string,
10-
podConfig: string,
9+
imageConfigId: string,
10+
imageConfigDisplayName: string,
11+
podConfigId: string,
12+
podConfigDisplayName: string,
1113
pvcName: string,
12-
): Workspace => {
14+
): {
15+
name: string;
16+
namespace: string;
17+
workspace_kind: { name: string };
18+
defer_updates: boolean;
19+
paused: boolean;
20+
paused_time: number;
21+
state: WorkspaceState;
22+
state_message: string;
23+
pod_template: {
24+
pod_metadata: { labels: {}; annotations: {} };
25+
volumes: {
26+
home: { pvc_name: string; mount_path: string; readOnly: boolean };
27+
data: { pvc_name: string; mount_path: string; readOnly: boolean }[];
28+
};
29+
options: {
30+
image_config: {
31+
current: {
32+
id: string;
33+
display_name: string;
34+
description: string;
35+
labels: { key: string; value: string }[];
36+
};
37+
};
38+
pod_config: {
39+
current: {
40+
id: string;
41+
display_name: string;
42+
description: string;
43+
labels: ({ key: string; value: string } | { key: string; value: string })[];
44+
};
45+
};
46+
};
47+
image_config: { current: string; desired: string; redirect_chain: any[] };
48+
pod_config: { current: string; desired: string; redirect_chain: any[] };
49+
};
50+
activity: { last_activity: number; last_update: number };
51+
} => {
1352
const currentTime = Date.now();
14-
const lastActivityTime = currentTime - Math.floor(Math.random() * 1000000); // Random last activity time
15-
const lastUpdateTime = currentTime - Math.floor(Math.random() * 100000); // Random last update time
53+
const lastActivityTime = currentTime - Math.floor(Math.random() * 1000000);
54+
const lastUpdateTime = currentTime - Math.floor(Math.random() * 100000);
1655

1756
return {
1857
name,
1958
namespace,
20-
workspace_kind: {
21-
name: 'jupyterlab',
22-
},
59+
workspace_kind: { name: 'jupyterlab' },
2360
defer_updates: paused,
2461
paused,
2562
paused_time: paused ? currentTime - Math.floor(Math.random() * 1000000) : 0,
@@ -45,41 +82,60 @@ const generateMockWorkspace = (
4582
{
4683
pvc_name: pvcName,
4784
mount_path: '/data/my-data',
48-
readOnly: paused, // Set based on the paused state
85+
readOnly: paused,
4986
},
5087
],
5188
},
89+
options: {
90+
image_config: {
91+
current: {
92+
id: imageConfigId,
93+
display_name: imageConfigDisplayName,
94+
description: 'JupyterLab environment',
95+
labels: [{ key: 'python_version', value: '3.11' }],
96+
},
97+
},
98+
pod_config: {
99+
current: {
100+
id: podConfigId,
101+
display_name: podConfigDisplayName,
102+
description: 'Pod configuration with resource limits',
103+
labels: [
104+
{ key: 'cpu', value: '100m' },
105+
{ key: 'memory', value: '128Mi' },
106+
],
107+
},
108+
},
109+
},
52110
image_config: {
53-
current: imageConfig,
111+
current: imageConfigId,
54112
desired: '',
55113
redirect_chain: [],
56114
},
57115
pod_config: {
58-
current: podConfig,
59-
desired: podConfig,
116+
current: podConfigId,
117+
desired: podConfigId,
60118
redirect_chain: [],
61119
},
62120
},
63121
activity: {
64122
last_activity: lastActivityTime,
65123
last_update: lastUpdateTime,
66-
last_probe: {
67-
start_time_ms: lastUpdateTime - 1000, // Simulated probe timing
68-
end_time_ms: lastUpdateTime,
69-
result: 'default_result',
70-
message: 'default_message',
71-
},
72124
},
73125
};
74126
};
75127

76128
const generateMockWorkspaces = (numWorkspaces: number, byNamespace = false) => {
77129
const mockWorkspaces = [];
78-
const podConfigs = ['Small CPU', 'Medium CPU', 'Large CPU'];
130+
const podConfigs = [
131+
{ id: 'small-cpu', display_name: 'Small CPU' },
132+
{ id: 'medium-cpu', display_name: 'Medium CPU' },
133+
{ id: 'large-cpu', display_name: 'Large CPU' },
134+
];
79135
const imageConfigs = [
80-
'jupyterlab_scipy_180',
81-
'jupyterlab_tensorflow_230',
82-
'jupyterlab_pytorch_120',
136+
{ id: 'jupyterlab_scipy_180', display_name: 'JupyterLab SciPy 1.8.0' },
137+
{ id: 'jupyterlab_tensorflow_230', display_name: 'JupyterLab TensorFlow 2.3.0' },
138+
{ id: 'jupyterlab_pytorch_120', display_name: 'JupyterLab PyTorch 1.2.0' },
83139
];
84140
const namespaces = byNamespace ? ['kubeflow'] : ['kubeflow', 'system', 'user-example', 'default'];
85141

@@ -94,11 +150,22 @@ const generateMockWorkspaces = (numWorkspaces: number, byNamespace = false) => {
94150
const name = `workspace-${i}`;
95151
const namespace = namespaces[i % namespaces.length];
96152
const pvcName = `data-pvc-${i}`;
153+
97154
const imageConfig = imageConfigs[i % imageConfigs.length];
98155
const podConfig = podConfigs[i % podConfigs.length];
99156

100157
mockWorkspaces.push(
101-
generateMockWorkspace(name, namespace, state, paused, imageConfig, podConfig, pvcName),
158+
generateMockWorkspace(
159+
name,
160+
namespace,
161+
state,
162+
paused,
163+
imageConfig.id,
164+
imageConfig.display_name,
165+
podConfig.id,
166+
podConfig.display_name,
167+
pvcName,
168+
),
102169
);
103170
}
104171

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
ActionsColumn,
2727
IActions,
2828
} from '@patternfly/react-table';
29-
import { useState } from 'react';
3029
import { CodeIcon } from '@patternfly/react-icons';
3130
import { Workspace, WorkspacesColumnNames, WorkspaceState } from '~/shared/types';
3231
import { WorkspaceDetails } from '~/app/pages/Workspaces/Details/WorkspaceDetails';
@@ -41,7 +40,7 @@ import { WorkspaceStartActionModal } from '~/app/pages/Workspaces/workspaceActio
4140
import { WorkspaceRestartActionModal } from '~/app/pages/Workspaces/workspaceActions/WorkspaceRestartActionModal';
4241
import { WorkspaceStopActionModal } from '~/app/pages/Workspaces/workspaceActions/WorkspaceStopActionModal';
4342
import Filter, { FilteredColumn } from 'shared/components/Filter';
44-
import { formatRam } from 'shared/utilities/WorkspaceResources';
43+
import { formatRam, formatCPU } from 'shared/utilities/WorkspaceResources';
4544

4645
export enum ActionType {
4746
ViewDetails,
@@ -141,9 +140,17 @@ export const Workspaces: React.FunctionComponent = () => {
141140
case columnNames.kind:
142141
return workspace.workspace_kind.name.search(searchValueInput) >= 0;
143142
case columnNames.image:
144-
return workspace.pod_template.image_config.current.search(searchValueInput) >= 0;
143+
return (
144+
workspace.pod_template.options.image_config.current.display_name.search(
145+
searchValueInput,
146+
) >= 0
147+
);
145148
case columnNames.podConfig:
146-
return workspace.pod_template.pod_config.current.search(searchValueInput) >= 0;
149+
return (
150+
workspace.pod_template.options.pod_config.current.display_name.search(
151+
searchValueInput,
152+
) >= 0
153+
);
147154
case columnNames.state:
148155
return WorkspaceState[workspace.state].search(searchValueInput) >= 0;
149156
case columnNames.homeVol:
@@ -165,12 +172,12 @@ export const Workspaces: React.FunctionComponent = () => {
165172
const { name, kind, image, podConfig, state, homeVol, cpu, ram, lastActivity } = {
166173
name: workspace.name,
167174
kind: workspace.workspace_kind.name,
168-
image: workspace.pod_template.image_config.current,
175+
image: workspace.pod_template.options.image_config.current.display_name,
169176
podConfig: workspace.pod_template.pod_config.current,
170177
state: workspace.state,
171178
homeVol: workspace.pod_template.volumes.home.pvc_name,
172-
cpu: workspace.cpu,
173-
ram: workspace.ram,
179+
cpu: getCpuValue(workspace),
180+
ram: getRamValue(workspace),
174181
lastActivity: workspace.activity.last_activity,
175182
};
176183
return [name, kind, image, podConfig, state, homeVol, cpu, ram, lastActivity];
@@ -366,6 +373,14 @@ export const Workspaces: React.FunctionComponent = () => {
366373
</>
367374
);
368375

376+
const getCpuValue = (workspace: Workspace): string =>
377+
workspace.pod_template.options.pod_config.current.labels.find((label) => label.key === 'cpu')
378+
?.value || 'N/A';
379+
380+
const getRamValue = (workspace: Workspace): string =>
381+
workspace.pod_template.options.pod_config.current.labels.find((label) => label.key === 'memory')
382+
?.value || 'N/A';
383+
369384
return (
370385
<Drawer
371386
isInline

0 commit comments

Comments
 (0)